Triggering event in C# from C++ DLL

后端 未结 2 453
迷失自我
迷失自我 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:41

    http://blogs.msdn.com/b/davidnotario/archive/2006/01/13/512436.aspx seems to answer your question. You use a delegate on the C# side and a standard callback on the C++ side.

    C++ side:

    typedef void (__stdcall *PFN_MYCALLBACK)();
    int __stdcall MyUnmanagedApi(PFN_ MYCALLBACK callback);
    

    C# side

    public delegate void MyCallback();
    [DllImport("MYDLL.DLL")] public static extern void MyUnmanagedApi(MyCallback callback);
    
    public static void Main()
    {
      MyUnmanagedApi(
        delegate()
        {
          Console.WriteLine("Called back by unmanaged side");
        }
       );
    }
    

提交回复
热议问题