Artyom
Artyom

Reputation: 145

Marshal void** c#

I try to use C dll in C#

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);

In C# I have

[DllImport("Y:\\libs\\Min.x86.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern M_STATUS M_Create(IntPtr pTarget, IntPtr pDetour, ref IntPtr ppOriginal);

But I always get PinvokeStackImbalance Exception

Where is mistake?

Upvotes: 1

Views: 685

Answers (1)

siride
siride

Reputation: 209475

Adding as an actual answer so it won't get lost.

The C function is declared as WINAPI, but the calling convention specified in the DllImport attribute is Cdecl. The conventions must match, so change it to either StdCall or Winapi.

Upvotes: 3

Related Questions