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

2019-02-27 16:47发布

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条回答
男人必须洒脱
2楼-- · 2019-02-27 17:32
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate void AnotherMethodDelegate(string s, IntPtr anyParameter);

[DllImport("dllname",
           CallingConvention = CallingConvention.Cdecl,
           CharSet = CharSet.Ansi)]
uint aMethod(IntPtr anyParameter, AnotherMethodDelegate anotherMethod);
查看更多
登录 后发表回答