cnd
cnd

Reputation: 33724

C++ to C# event handling

So I've got my C# WinForm Application, from it I call my C++ CLI MFC dll library.

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

so when this native function is called from client side :

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

I need to bring the Data from C# so I need to register this as event somehow.

Upvotes: 3

Views: 3318

Answers (2)

Matěj Zábský
Matěj Zábský

Reputation: 17272

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

Why can't you just register a native handler to the native event/callback, which then just invokes a .NET event, which can be the consumed from C#.

Upvotes: 4

Mahmoud Al-Qudsi
Mahmoud Al-Qudsi

Reputation: 29519

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

Upvotes: 0

Related Questions