Calling C++ method from C# with pointer parameter (WCT)

前端 未结 1 1976
独厮守ぢ
独厮守ぢ 2021-01-23 08:44

I am new to this concept of calling C++ methods from C#.

Assuming that I want to call a C++ function GetThreadWaitChain from C#:

https://msdn.micr

相关标签:
1条回答
  • 2021-01-23 09:45

    The GetThreadWaitChain function prototype is incorrect. It should be:

    [DllImport("advapi32.dll", SetLastError = true)]
    public static extern bool GetThreadWaitChain(
        IntPtr  WctHandle,
        IntPtr Context,
        UInt32 Flags,
        int ThreadId,
        ref int NodeCount,    
        [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] 
        [In, Out] 
        WAITCHAIN_NODE_INFO[] NodeInfoArray,  
        out int IsCycle
    );
    

    When calling first allocate the WAITCHAIN_NODE_INFO array.

    WAITCHAIN_NODE_INFO[] data = new WAITCHAIN_NODE_INFO[16];
    
    0 讨论(0)
提交回复
热议问题