tags:

views:

296

answers:

5

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

A: 

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

DannySmurf
+3  A: 

Use named pipes, see this posting.

James
Named pipes are INSANELY fast on the local system. Specificially designed for IPC.
Spence
A: 

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.

ShuggyCoUk
+3  A: 

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.
Hans Passant
+1  A: 

This tutorial help you :
.NET 3.5 Adds Named Pipes Support
Interprocess Communication using Named Pipes in C#

lsalamon