2

I see there are some other posts related to this issue. However, I want to ask if there is new elegant way to just exchange some messages between a C#.net application and a C++ application?

They are running on the same machine.

Thanks in advance.

famousgarkin
  • 13,687
  • 5
  • 58
  • 74
olidev
  • 20,058
  • 51
  • 133
  • 197
  • Assuming your looking to do interprocess communication, check out this article on using NamedPipes: http://www.codeproject.com/KB/threads/dotnetnamedpipespart1.aspx – sbeskur Dec 09 '11 at 23:10
  • this one is for two .net applications, right? I am looking for a solution between a C++ app and a .net app – olidev Dec 09 '11 at 23:12
  • Named pipes are built into the OS and can be used to communicate between processes regardless of the language they are built with. http://msdn.microsoft.com/en-us/library/windows/desktop/aa365590(v=vs.85).aspx – dkackman Dec 09 '11 at 23:23
  • named pipes deserve more love. They are ubiquitous in the Unix world, but windows programmers prefer, say, DCOM or whatever. Named pipes take a couple of LOC to get working – Alexandre C. Dec 09 '11 at 23:39

3 Answers3

3

What you want is inter-process communication (IPC), which is language-agnostic by definition.

Typical solutions include:

  • Named pipes (also called FIFOs)
  • Mail slots
  • File mapping
  • Sockets
  • RPC
  • etc.

You use different ones depending on your needs.

Here is information on windows-supported IPC methods: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365574%28v=vs.85%29.aspx

Most of this functionality is exposed in C# through WCF, which is windows-specific of course. If you're using Mono, you're out of luck.

C++ doesn't define any IPC constructs in the language itself, so you will have to use platform-specific libraries regardless.

Search around for IPC examples in C# and C++ and you will get plenty of hits.

Here's a SO post to get you started: IPC Mechanisms in C# - Usage and Best Practices

Community
  • 1
  • 1
jwd
  • 10,837
  • 3
  • 43
  • 67
1

I have always used sockets, that is the simplest way I can think of (not the most elegant though)

GETah
  • 20,922
  • 7
  • 61
  • 103
0

There are many mechanisms you can use to do this.

This article enumerates the common ways to accomplish interprocess communication on the windows platform. Most if not all are possible form both C# and C++ (though I would hate to see you use DDE from C#, though it has apparently been done).

dkackman
  • 15,179
  • 13
  • 69
  • 123
  • in addition, I found this post helpful as well http://stackoverflow.com/questions/56121/ipc-mechanisms-in-c-sharp-usage-and-best-practices – olidev Dec 10 '11 at 01:24