How to move/copy data from MFC to C++/CLI using events/delegates/callback

岁酱吖の 提交于 2019-12-12 03:49:58

问题


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.

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

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

Edit ::

As mentioned by Hans below added request for callback solutions.


回答1:


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

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



来源:https://stackoverflow.com/questions/38521509/how-to-move-copy-data-from-mfc-to-c-cli-using-events-delegates-callback

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!