PInvoke C#: Function takes pointer to function as argument

前端 未结 2 1674
一生所求
一生所求 2020-12-01 14:56

I\'d like to access this function in my c# code, is this possible? so in the end the c++ code would call my function and also apply the struct called \"sFrameofData\".

2条回答
  •  悲哀的现实
    2020-12-01 15:24

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

提交回复
热议问题