0

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.

bhardwajhp
  • 43
  • 1
  • 8
  • Have you looked into any of the [IPC](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v=vs.85).aspx) constructs? – rrirower Jul 22 '16 at 15:52
  • Thanks @rrirower this link looks promising https://msdn.microsoft.com/en-us/library/windows/desktop/ms649009(v=vs.85).aspx, but they have not implemented the destination class which will read the data. can you please direct me to a good example with destination class implementation. – bhardwajhp Jul 26 '16 at 07:43
  • Usually done with gcroot<> to have your MFC code keep a reference to a managed object. If that's an obstacle then a callback is a logical shortcut here, you can hand your MFC code a function pointer with Marhal::GetFunctionPointerForDelegate(). – Hans Passant Jul 26 '16 at 12:12
  • @Hans i have seen your examples of getFPFD in all the examples you are invoking delegate to run native function, what i need is opposite meaning invoking some function in C++ which invokes some delegate in CLI and eventually notify C# code to update some data ? i new to c++/cli apologies for stupid queries. please share some good example links thanks – bhardwajhp Aug 01 '16 at 06:53
  • 1
    @Funky were you able to implement passing string from c++ yo C# for "http://stackoverflow.com/questions/5030936/c-callback-to-send-text-back-to-c-sharp?answertab=active#tab-top" – bhardwajhp Aug 01 '16 at 06:58

1 Answers1

0

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.

bhardwajhp
  • 43
  • 1
  • 8