LCC
LCC

Reputation: 1189

Most common idiom for intra-process communciation on Windows?

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.

Upvotes: 3

Views: 708

Answers (4)

jnoss
jnoss

Reputation: 2049

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?

Upvotes: 0

Eugen Constantin Dinca
Eugen Constantin Dinca

Reputation: 9150

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.

Upvotes: 2

BuggerMe
BuggerMe

Reputation: 77

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.

Upvotes: 0

Billy ONeal
Billy ONeal

Reputation: 106609

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.

Upvotes: 0

Related Questions