PInvoke C#: Function takes pointer to function as argument

半世苍凉 提交于 2019-11-27 08:56:55
ahawker

You want to use a delegate that matches the method signature of your "MyFunction" C++ method.

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void MyFunctionDelegate(IntPtr frame);

[DllImport("Cortex_SDK.dll")]
public extern static int Cortex_SetDataHandlerFunc(
[MarshalAs(UnmanagedType.FunctionPtr)]MyFunctionDelegate functionCallback);
Davide Piras

I am not sure what is the proper way but I don't think is enough to use ref IntPtr for functions and structures...

see here for some help: C# P/Invoke: Marshalling structures containing function pointers

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