Trigger event in C # from C ++ DLL

I have a umanaged C ++ DLL that interacts with Cisco Server (UCCX).

It sends and receives messages to and from this server via TCP / IP. Now there are several types of messages that he receives that contain some parameters that he needs to send in the C # GUI, which displays these parameters on the screen.

Please tell me an efficient method to fire events in C # from this DLL.

+5
source share
2 answers

http://blogs.msdn.com/b/davidnotario/archive/2006/01/13/512436.aspx seems to answer your question. You are using 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");
    }
   );
}
+6
source

, ++

typedef void (__stdcall *PFN_MYCALLBACK)();
extern "C" __declspec(dllexport) void __stdcall MyUnmanagedApi(PFN_ MYCALLBACK callback);

- __stdcall ++

typedef void (*PFN_MYCALLBACK)();
extern "C" __declspec(dllexport) void MyUnmanagedApi(PFN_ MYCALLBACK callback);

#:

public delegate void MyCallback();
[DllImport("MYDLL.DLL", CallingConvention = CallingConvention.Cdecl))] 
public static extern void MyUnmanagedApi(MyCallback callback);

as above ...
0

All Articles