Drake
Drake

Reputation: 3891

C++ communicate across processes

I have a dll that is loaded into multiple processes. What would be a clean way to have communication across those processes/dlls. Sending simple strings is the goal. I would prefer to avoid sendmessage, file io, and sending the address of the string command.

Upvotes: 1

Views: 4364

Answers (4)

paulmk
paulmk

Reputation: 3

Microsoft has a pretty comprehensive overview over the different methods for inter-process communication.

The article explains the pros and cons of the most common methods. Among them are

  • Data Copy (Message Passing)
  • File Mapping (Named Shared Memory)
  • Pipes
  • Remote Procedure Call and more.

Each section of the article gives links to further documentation including some very useful code-examples.

Upvotes: 0

Carey Gregory
Carey Gregory

Reputation: 6846

I assume you're coding for Windows.

Named pipes are probably the best solution if your communications are point-to-point between processes. You can easily design client/server-style protocols such as this:

Client: Here is data to process

Server: Here are the results of processing your request

Named pipes will also port easily to other point-to-point mechanisms such as sockets or anonymous pipes.

If your communications aren't point-to-point and you need to maintain common shared data among multiple processes, then memory mapped files as suggested by Andre' are a better choice, but will definitely need mutex protection to be reliable.

Upvotes: 2

Tod
Tod

Reputation: 8242

Since everyone else assumed Windows can I assume UcOs/II? Use a Message Mailbox. OK I figure if you are on windows there has to be something similar a quick google turned up Mailslots.

Upvotes: 0

André Caron
André Caron

Reputation: 45224

I would look into shared memory. There's a nice example on MSDN.

Keep in mind that just like when using threads in the same process, access to shared memory is not serialized. You'll need some form of synchronization (e.g. a named mutex) to serialize access to the memory block.

Upvotes: 5

Related Questions