How can I write a signature on C# for a wrapped C++ method having a pointer to a function it its arguments?

送分小仙女□ 提交于 2019-12-02 12:56:27

问题


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


来源:https://stackoverflow.com/questions/7410382/how-can-i-write-a-signature-on-c-sharp-for-a-wrapped-c-method-having-a-pointer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!