Yttrium
Yttrium

Reputation: 2137

What is the best way to pass information from a C# app to a C++ app while both are running?

What would be the best way to pass information from a windows forms C# app to a MFC C++ app while they are running? I don't need to send much, just a small string.

Thanks, Jeff

Upvotes: 2

Views: 569

Answers (4)

Hans Passant
Hans Passant

Reputation: 941347

Going down the list of IPC options:

  • Memory mapped files. Easy in C++, tough in C# without pointers, awkward handshaking
  • WM_COPYDATA. Easy in both, tricky to find the window handle you'll need
  • Clipboard. Easy in both, very awkward handshaking
  • COM. Out-of-proc is a beast, forget about it
  • Mailslots. Not suitable for one-to-one communication
  • Pipes. Easy in .NET 3.5, do-able in C++ but a bit tricky to get right
  • Sockets. Easy in both, hard to pass up.

Upvotes: 4

ShuggyCoUk
ShuggyCoUk

Reputation: 36438

MailSlot api is small and simple but requires P/Invoke to use from c# and can go outside your local machine so needs care. see my answer here

Named pipes may well be more robust but this is an alternate.

Upvotes: 0

James
James

Reputation: 12796

Use named pipes, see this posting.

Upvotes: 3

TheSmurf
TheSmurf

Reputation: 15568

If the C++ app has a main window, take a look at using the SendMessage function (via P/Invoke) in the C# app to send a WM_COPYDATA message to the C++ app.

http://msdn.microsoft.com/en-us/library/ms649011%28VS.85%29.aspx

Upvotes: 0

Related Questions