Pass Managed Function Pointer As Unmanaged Callback

后端 未结 2 918
我寻月下人不归
我寻月下人不归 2021-01-13 13:24

I am attempting to pass a managed function pointer void (*)(void *) to my unmanaged library. My unmanaged library calls this callback with a pointer to a frame

2条回答
  •  隐瞒了意图╮
    2021-01-13 13:54

    EDIT: not a problem with cross-thread calls. If the unmanaged caller expects to call a __cdecl function, then you have to decorate the delegate type with an UnmanagedFunctionPointerAttribute attribute.

    using namespace System::Runtime::InteropServices;
    
    [UnmanagedFunctionPointerAttribute(CallingConvention::Cdecl)] 
    delegate void myCallbackDelegate(void * usr_data); 
    

提交回复
热议问题