我尝试在C#中使用C dll
typedef enum M_STATUS
{
// Unknown error. Should not be returned.
M_UNKNOWN = -1,
// Successful.
M_OK = 0
} M_STATUS;
M_STATUS WINAPI M_Create(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal);
在C#中我有
[DllImport("Y:\\libs\\Min.x86.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern M_STATUS M_Create(IntPtr pTarget, IntPtr pDetour, ref IntPtr ppOriginal);
但我总是得到PinvokeStackImbalance Exception
哪里出错?
答案 0 :(得分:3)
添加为实际答案,以免迷路。
C函数声明为WINAPI
,但DllImport
属性中指定的调用约定为Cdecl
。约定必须匹配,因此请将其更改为StdCall
或Winapi
。