views:

346

answers:

8

I need to pass some data (integers) from one (C++) program to another (C#). What is the fastest way to do this?

P.S.: OS: Windows XP

+6  A: 

My personal preference for this, given that you're using C++ and C# both, and it's on the same system, would be to use Pipes.

They work very well from native code (C++) as well as from C# via NamedPipeClientStream and NamedPipeServerStream.

However, there are other options for Interprocess Communication, any of which would work.

Reed Copsey
I think you mean named pipes, not pipes. Pipes and named pipes are different IPC mechanisms.
Ken
Pipes include both Named Pipes and Anonymous pipes. You could, technically, use anonymous pipes if one process is launching the other, but otherwise, you'd want named pipes. Both are, technically, "Pipes", though. From MS: "There are two types of Pipes...", see: http://msdn.microsoft.com/en-us/library/aa365137(VS.85).aspx
Reed Copsey
+2  A: 

Shared memory would be the fastest but named pipes are pretty fast too and much easier to use.

Jonas Elfström
+1  A: 

Check out this article for a run-down of the available options. Your best bet is probably a pipe.

moonshadow
Please replace the "tinyurl" address with the actual address.
cic
I'll just leave it alone instead of fighting with you... lol sorry
Matthew Whited
@cic: so done. Sorry - it contained brackets, messing up the formatting, and I haven't memorised the escape codes yet.
moonshadow
+1  A: 

Using files would be the simplest way. If you need the speed, then network sockets may be a good option.

Dima
A mailslot is basically a file, but can only be used for one-way communication.
cchampion
A: 

Just in case it's helpful, if it's not critical that this be interprocess communication (if the functionality you require out of one can be shaped into a DLL which both use or similar) you can use the Common Language Runtime for interoperability.

antik
A: 

My recommendation would be Sockets or RPC. I'm not familiar with pipes, but it seems to be a popular option too.

Marcin
+1  A: 

mailslots can be used if you're communication is one-way and your messages are small. Otherwise I'd recommend using named pipes (as others have recommended).

here's something on mailslots

All IPC mechanisms

cchampion
A: 

There are many examples of IPC using many methods in C++ and C#, look at CodFX

lsalamon