PInvoke C#: Function takes pointer to function as argument

Solution 1:

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

Solution 2:

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