Triggering event in C# from C++ DLL

后端 未结 2 446
迷失自我
迷失自我 2020-12-31 20:55

I have an umanaged C++ DLL which is communicating with a Cisco Server (UCCX).

It sends and receives messages to and from this server via TCP/IP. Now there are some

2条回答
  •  渐次进展
    2020-12-31 21:44

    Note the C++ side should be

    typedef void (__stdcall *PFN_MYCALLBACK)();
    extern "C" __declspec(dllexport) void __stdcall MyUnmanagedApi(PFN_ MYCALLBACK callback);
    

    An alternate option is to drop the __stdcall on the C++ side

    typedef void (*PFN_MYCALLBACK)();
    extern "C" __declspec(dllexport) void MyUnmanagedApi(PFN_ MYCALLBACK callback);
    

    And on the C# side:

    public delegate void MyCallback();
    [DllImport("MYDLL.DLL", CallingConvention = CallingConvention.Cdecl))] 
    public static extern void MyUnmanagedApi(MyCallback callback);
    
    as above ...
    

提交回复
热议问题