Event handling from C ++ to C #

So, I have my C # WinForm application from which I call my C ++ CLI MFC dll library.

But there are several events in my C ++ library, even this happens in the native (non-CLI) part of this library. And I need to call the code from my C # application and get some data, maybe right there at this event.

therefore, when this native function is called from the client side:

bool __stdcall ClassName::WorkQuery() { ...... switch(pp->code) { case READCOMPLEX: .......... 

I need to bring data from C # , so I need to somehow register this as an event.

+4
source share
2 answers

So the problem is that you need to run C # code in response to an MFC event (or C ++ callback), right?

Why can't you just register your own handler for your own event / callback, which then just raises a .NET event that can be used in C #.

+5
source

You can create a .NET event from a C ++ / CLI event descriptor, and then use it natively. Just use EventWaitHandle or derived AutoResetEvent and ManualResetEvent objects.

+1
source

All Articles