Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing data between C++ (MFC) app and C#

Tags:

c++

c#

ipc

We have a monolithic MFC GUI app that is nearing the end of it's life in C++. We are planning to build new functionality in C# and pass data between each app.

Question is: What is the best approach for passing data between C++ and C#?

Notes:
Both ends will have a GUI front end and will probably only need to pass simple data like Id's and possibly have a mechanism where it indicates to the other app what process/functionality to use.
Eg One of the applications will be a CRM system in C# that when a row in a grid is double clicked would pass say the customerId and a message to open that customer in the Customer Form of the MFC app.

I have done a little bit of research, the options seem to be Windows Messaging, Memory Mapping, Named Pipes or something like Windows Sockets. At this stage we are leaning towards Named Pipes, but would really appreciate other advice or tips or other peoples experiences.

like image 258
JamesSugrue Avatar asked Oct 08 '08 20:10

JamesSugrue


2 Answers

Personally I'd be thinking of using something like named pipes as they are easy to use from the C++ side and the System.IO.Pipes on the .NET side also.

It would also be the path of probably least resistance if you're planning to replace the other non .NET bits of the app over time.

like image 91
Shaun Austin Avatar answered Sep 26 '22 14:09

Shaun Austin


Take your pick:

  • files
  • named pipes <-- My recommendation
  • shared memory
  • sockets
  • COM
  • Windows messages

Why named pipes?

  • Gives you a FIFO way of working for free (like sockets, but not like shared memory)
  • Can easily communicate both ways
  • Well supported on all platforms
  • Easy to use
  • Reliable data passing and delivery
  • Can be blocking and non blocking
  • Can read data without removing (unlike sockets)
  • Can be expanded to include a third app easily.

In .Net just use System.IO.Pipes.

In C++ use CreateNamedPipe and CreateFile.

like image 31
Brian R. Bondy Avatar answered Sep 26 '22 14:09

Brian R. Bondy