从C在C#中触发事件++ DLL [英] Triggering event in C# from C++ DLL
问题描述
我有与思科服务器(UCCX)通信的umanaged C ++ DLL。
I have an umanaged C++ DLL which is communicating with a Cisco Server (UCCX).
它发送和接收信息,并从其通过TCP / IP此服务器。现在也有一些类型的接收到的消息,其中包含它需要发送到C#GUI,这将在屏幕上显示这些参数的一些参数。
It sends and receives messages to and from this server via TCP/IP. Now there are some types of messages it receives which contains some parameters which it needs to send to a C# GUI which will display these parameters on screen.
请告诉我一个高效方法来触发此DLL C#的事件。
Please tell me an efficient method to trigger an event in C# from this DLL.
推荐答案
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 ++端:
typedef void (__stdcall *PFN_MYCALLBACK)();
int __stdcall MyUnmanagedApi(PFN_ MYCALLBACK callback);
C#侧
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");
}
);
}
这篇关于从C在C#中触发事件++ DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!