Achal Gupta Achal Gupta - 3 years ago 397
C# Question

Triggering event in C# from C++ DLL

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.

Answer Source 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()
      Console.WriteLine("Called back by unmanaged side");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download