2009/07/30

C# - Passing Pointer / Pointer-to-Pointer as Input Parameter to DLL Methods

C Method Declaration

int TestMethod1(Struct1** handle);

int TestMethod2(Struct2* handle);




C# Dll Import

[DllImport("TestMethods.dll")]

private static extern int TestMethod1(ref IntPtr ptrHandle);

[DllImport("TestMethods.dll")]

private static extern int TestMethod2(IntPtr ptrHandle);




C# Calling Dll Methods

IntPtr ptrHandle = IntPtr.Zero;

ptrHandle = Marshal.AllocHGlobal(IntPtr.Size);

TestMethod1(ref ptrHandle);

TestMethod2(ptrHandle);

Marshal.FreeHGlobal(ptrHandle);

No comments:

Post a Comment

Google Analytics

Blog Archive

Followers