开发者

C++ to C# event handling

开发者 https://www.devze.com 2023-04-10 05:56 出处:网络
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

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 sid开发者_开发百科e :

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.


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#.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消