How can I write a signature on C# for a wrapped C+

2019-02-27 17:35发布

问题:

I'm writing a wrapper for a dll. The dll has a method whose signature resembles the following:

unsigned long aMethod(void *anyParameter, 
void (*anotherMethod)(const char *,  void *))

I've searching at google for a tutorial to give me insight on how to write the signature on C# so the framework can do the marshalling process.

How can it be written? Do you know about any tutorial, book or documentation on this subject?

回答1:

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void AnotherMethodDelegate(string s, IntPtr anyParameter);

[DllImport("dllname",
           CallingConvention = CallingConvention.Cdecl,
           CharSet = CharSet.Ansi)]
uint aMethod(IntPtr anyParameter, AnotherMethodDelegate anotherMethod);