虚空元帅 c#

Marshal void** c#

我尝试在 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 异常

错在哪里?

添加为实际答案,以免丢失。

C 函数声明为WINAPI,但DllImport 属性中指定的调用约定为Cdecl。约定必须匹配,因此将其更改为 StdCallWinapi.