从C ++ DLL触发C#中的事件 [英] Triggering event in C# from C++ DLL
问题描述
它通过TCP / IP向本服务器发送和接收消息。现在有一些类型的消息,它包含一些需要发送到C#GUI的参数,这些参数将在屏幕上显示这些参数。
请告诉我一个有效的从这个DLL触发C#中的事件的方法。
http://blogs.msdn.com/b/davidnotario/archive/2006/01/13/512436.aspx 似乎回答你的问题。您在C#方面使用一个代理,并在C ++方面使用标准回调。
C ++边:
typedef void(__stdcall * PFN_MYCALLBACK)();
int __stdcall MyUnmanagedApi(PFN_ MYCALLBACK callback);
C#边
code> public delegate void MyCallback();
[DllImport(MYDLL.DLL)] public static extern void MyUnmanagedApi(MyCallback callback);
public static void Main()
{
MyUnmanagedApi(
delegate()
{
Console.WriteLine(被非托管调用侧);
}
);
}
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 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.
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++ 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");
}
);
}
这篇关于从C ++ DLL触发C#中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!