1

The following is a PInvoke block in C++ that I'm trying to convert to C#:

typedef  PVOID   JHANDLE ;
typedef  UINT32  JRET ;

#define JEXPORT __declspec(dllimport) JRET

JEXPORT
JInitialize (
   OUT JHANDLE* ppHandle,
   IN  PVOID       context,  
   IN  UINT32      flags
) ;

I tried the following call, but it threw a PInvokeStackImbalance exception saying that the signatures don't match:

[DllImport("jhi.dll")]
public static extern UInt32 JHI_Initialize(out IntPtr ppHandle, IntPtr context, UInt32 flags);

Obviously a pointer of a pointer is handled different, but I'm not exactly sure how it translates.

1 Answer 1

2

You are missing the CallingConvention in your [DllImport] declaration, it is Cdecl.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I always forget about CallingConvention
I know this is ancient and the OP's problem doesn't really match mine, but this answer just saved me after many hours of pInvoke hell. You get a vote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.