tags:

views:

82

answers:

4

I have a very simple interface which needs to communicate between processes. It's currently implemented in a very simple manner (all single proc):

bool GetFoo(struct Foo *outFoo);
bool GetBar(struct Bar *getBar);

Such as:

Foo foo;
if (!GetFoo(&foo))
{
    ReportError();
}

GetFoo fills out the "Foo" data structure with pure data (that is, no pointers - it's purely blitable data).

I need to convert this in-process function call to be between two processes on the same machine (in this case it's always the same machine). Is there a commonly followed idiom for cross-process calls in C++ on Windows? Is there some kind of intra-process communication supported by Windows? Should I be using shared memory instead?

One note: I don't want to take a dependency on anything other than the Windows APIs if at all possible.

A: 

I'm not sure what the most common is -- to truly answer that we'd have to have some kind of polling. That said, the most flexible way would probably be to expose the methods via DCOM.

Billy ONeal
+2  A: 

You have many choices, but in my personal experience the most popular/easy to use ones are: sockets & pipes.

See here for all IPC options available for Windows.

Eugen Constantin Dinca
That is not a cross process call. The OP is specifically asking for remote procedure calls, not general cross process information sharing.
Billy ONeal
The `Is there some kind of intra-process communication supported by Windows?` and the mentioning of `shared memory` must of threw me off then...
Eugen Constantin Dinca
Sockets and pipes can absolutely be used to implement RPC. HTTP POST requests are in every respect remote procedure calls -- they accept input arguments, perform processing, and return results. In a simple system the mere establishment of a connection could be the request. For more complex situations, `TransactNamedPipe` is probably perfect. What more are you looking for?
Ben Voigt
Remember that pipes on Windows are _named_ pipes. A procedure is essentially no more than a named function with input and output parameters. So a named pipe "GetFoo" that returns a serialized Foo object makes perfect sense in this context.
MSalters
Billy: Actually general cross process information sharing would be acceptable for my purposes (so would remote procedure calls). This is why I mentioned shared memory. Eugen's answer was what I was looking for.
LCC
A: 

A common method would be RPC, it can be implemented in various ways for instance as Billy mentioned using COM` (or DCOM if the processes are residing on different machines).

Although you may want to think about not doing direct RPC calls and instead have a named pipe between your processes which is used for the communication.

BuggerMe
A: 

There are a number of ways to communicate between processes on the same computer in Windows. Which one works best depends on the relationship between the two processes. Is one process expected to start the other? In that case an out-of-process COM server would probably work best, since you can restart the other process if it is not already running.

If performance is critical, then shared memory will give you the most control the speed of passing the data between your processes.

One thing to think about is the failure semantics of running multiple processes. What does the calling process do if the callee is not there?