从C在C#中触发事件++ DLL [英] Triggering event in C# from C++ DLL

查看:214
本文介绍了从C在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 似乎回答你的问题。你使用C#的一面,并在C ++侧一个标准的回调委托

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆