如何使用事件/代理/回调将数据从MFC移动/复制到C ++ / CLI [英] How to move/copy data from MFC to C++/CLI using events/delegates/callback

查看:267
本文介绍了如何使用事件/代理/回调将数据从MFC移动/复制到C ++ / CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个MFC应用程序设置,只要有新数据可用,客户端就会从服务器接收数据。客户端正在用C#重写,但与服务器部分的通信是在MFC中。我们已经为与MFC相关的类编写了C ++ / CLI包装器,并且能够在应用程序初始化时接收数据。通信引擎仍在MFC中,并且我们仅为数据项创建了包装器类。初始化CLI包装器时,我们将数据从MFC阵列复制到CLI阵列。但不确定5秒钟后如何获取接收到的数据。它如何通知C ++ / CLI包装器后台运行的MFC代码已接收到新数据。如果您需要澄清,请告诉我。

We have a MFC application setup where a client receives data from server whenever new data is available. Client is being rewritten in C# but communication with server part is in MFC. We have written a C++/CLI wrapper to classes associated with MFC and are able to receive data on application initialization. Communication engine is still in MFC and we have created wrapper classes only for data items. When we initialize the CLI wrapper we copy the data from MFC arrays to CLI arrays. But am not sure how to get the data which is received lets say after 5 seconds. How can it notify C++/CLI wrapper that new data has been received by MFC code running in the background. Please let me know if you need clarifications. Thanks.


是否可以从C ++代码调用C ++ / CLI方法?

or Is there a way to invoke a C++/CLI method from C++ code ?

注意:
是具有vc ++和C ++ / CLI代码的混合模式编译。

NOTE: its a mixed mode compilation which has vc++ and C++/CLI code.

:

正如汉斯在下面提到的那样,增加了对回调解决方案的要求。

As mentioned by Hans below added request for callback solutions.

推荐答案

通过将CPP事件转换为CLI委托,被.NET识别为.NET委托。

Resolved this issue by converting, CPP events to CLI delegates, which are recognized by .NET as .NET delegates.

这样,我们可以从CPP控制C#末尾的动作。如果有人有更好的解决方案,请分享。

this way we can control actions at C# end from CPP. If anybody has a better solution please share.

这篇关于如何使用事件/代理/回调将数据从MFC移动/复制到C ++ / CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆