C ++到C#事件处理 [英] C++ to C# event handling
问题描述
所以,我已经得到了它在我的 C# WinForm应用程序,我把我的 C ++ CLI MFC DLL 库。
So I've got my C# WinForm Application, from it I call my C++ CLI MFC dll library.
但也有一些的活动在我的C ++库,即使这样的事件发生在该库的原生(非CLI)的一部分。而我需要从我的C#应用程序调用一些代码,并得到了一些数据,也许就在那里对本次活动
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:
..........
我需要从C#把数据的所以我需要以某种方式注册此作为事件。
I need to bring the Data from C# so I need to register this as event somehow.
推荐答案
所以,问题是你需要在响应MFC事件(或C ++回调)上运行的C#代码,对吧?
So the problem is you need to run C# code in response to MFC event (or C++ callback), right?
为什么你不能只是注册一个原生处理器原生事件/回调,然后只调用.NET的事件,可以从C#来消耗。
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#.
这篇关于C ++到C#事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!