# C or C++ library for inter-process communication in Windows

**URL:** <https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904>\
**Category:** In My Humble Opinion\
**Created:** [January 27, 2014, 11:27pm UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904 "2014-01-27T23:27:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [January 27, 2014, 11:27pm UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/1 "2014-01-27T23:27:22Z")

</div>

So I’m doing development work on Windows, and I’d like to do some communication between two processes running on the same machine (but not in the same user session, potentially). Seems to me there are about 4 different ways I can do that:  
-shared memory  
-a named pipe  
-TCP/IP  
-memory-mapped files

What I really want is a client-server model, where one running program can say “OK, I’m listening here on a named-or-numbered channel of some sort” and other programs can connect and disconnect, and while they’re connected, they can pass streams of bytes back and forth".

None of those methods seem dauntingly difficult, but I feel like setting up a nice robust module is going to involve a bunch of work to get all the corner cases and synchronization and so forth working properly, and this seems like a problem that someone else must have already solved.

So… is the a library or package I can find somewhere that does all the dirty work and presents a nice clean usable API?  
thanks!

---

<div class="post-metadata">

**Author:** ![RaftPeople](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@RaftPeople](https://boards.straightdope.com/u/RaftPeople)\
**Post date:** [January 27, 2014, 11:46pm UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/2 "2014-01-27T23:46:33Z")

</div>

You could use sockets, here’s a link to a C tutorial:

> **[Networking and Socket Programming Tutorial in C](https://www.codeproject.com/Articles/586000/Networking-and-Socket-programming-tutorial-in-C)**
>
> Networking and Socket programming tutorial in C.

I’ve done exactly what you are looking to do but in Java, worked well.

---

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [January 28, 2014, 12:12am UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/3 "2014-01-28T00:12:18Z")

</div>

> [@RaftPeople](#):
>
> You could use sockets, here’s a link to a C tutorial:  
> [http://www.codeproject.com/Articles/586000/Networking-and-Socket-programming-tutorial-in-C](http://www.codeproject.com/Articles/586000/Networking-and-Socket-programming-tutorial-in-C)
> 
> I’ve done exactly what you are looking to do but in Java, worked well.

We already have a very robust socket library which we use for TCP/IP communication between programs running on different machines. What we do not have (and what I suspect must be possible) is a similar system which takes advantage of knowing that the communicating processes are running on the machine and can thus avoid a bunch of overhead and run much faster.

---

<div class="post-metadata">

**Author:** ![Senegoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/senegoid/32/6606_2.png) [@Senegoid](https://boards.straightdope.com/u/Senegoid)\
**Post date:** [January 28, 2014, 12:13am UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/4 "2014-01-28T00:13:13Z")

</div>

> [@RaftPeople](#):
>
> You could use sockets, here’s a link to a C tutorial:  
> [Networking and Socket Programming Tutorial in C- CodeProject](http://www.codeproject.com/Articles/586000/Networking-and-Socket-programming-tutorial-in-C)

Just took a look there. That tutorial says explicitly that it’s for Linux ONLY, and not for Winders. But, depending on what level of beginnerness the OP is looking for, it could be a good conceptual lesson in any case.

---

<div class="post-metadata">

**Author:** ![arseNal](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@arseNal](https://boards.straightdope.com/u/arseNal)\
**Post date:** [January 28, 2014, 12:18am UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/5 "2014-01-28T00:18:51Z")

</div>

Are you talking strictly synchronous communication? If not, what about using an open source messaging system like ActiveMQ?

[http://activemq.apache.org/](http://activemq.apache.org/)

Write to a queue from one process, read from it from another, all the robustness is built-in for you. Only problem is it might be a bit heavyweight for your purposes. Or, it could provide a lot of functionality you might find useful (store and forward, etc.)

Actually, you can do synchronous with it too, I think it just takes a bit more work.

ETA: I know you said C/C++ but I’m sure there’s a a C/C++ client for it.

---

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [January 28, 2014, 12:21am UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/6 "2014-01-28T00:21:48Z")

</div>

> [@arseNal](#):
>
> Are you talking strictly synchronous communication? If not, what about using an open source messaging system like ActiveMQ?
> 
> [http://activemq.apache.org/](http://activemq.apache.org/)
> 
> Write to a queue from one process, read from it from another, all the robustness is built-in for you. Only problem is it might be a bit heavyweight for your purposes.

Yeah… flexibility is unimportant here, this is all programs written in C/C++ with the same libraries linked in all running on a single Windows machine. What’s important is performance, so that a program that runs for only a fraction of a second can connect, send some data, and disconnect, without tons of overhead.

---

<div class="post-metadata">

**Author:** ![arseNal](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@arseNal](https://boards.straightdope.com/u/arseNal)\
**Post date:** [January 28, 2014, 12:31am UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/7 "2014-01-28T00:31:46Z")

</div>

Ok, then what about these guys? Never used it before, but sounds promising:

[http://www.boost.org/doc/libs/1\_47\_0/doc/html/interprocess.html](http://www.boost.org/doc/libs/1_47_0/doc/html/interprocess.html)

---

<div class="post-metadata">

**Author:** ![arseNal](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@arseNal](https://boards.straightdope.com/u/arseNal)\
**Post date:** [January 28, 2014, 12:37am UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/8 "2014-01-28T00:37:44Z")

</div>

Missed edit window.

Better link with sample code: [Sharing memory between processes - 1.55.0](http://www.boost.org/doc/libs/1_55_0/doc/html/interprocess/sharedmemorybetweenprocesses.html)

---

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [January 28, 2014, 12:43am UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/9 "2014-01-28T00:43:48Z")

</div>

> [@arseNal](#):
>
> Missed edit window.
> 
> Better link with sample code: [Sharing memory between processes - 1.55.0](http://www.boost.org/doc/libs/1_55_0/doc/html/interprocess/sharedmemorybetweenprocesses.html)

Yeah, shared memory definitely seems like the right approach, but there’s a LOT of extra work involved in getting all the details right. [This](http://www.codeproject.com/Articles/14740/Fast-IPC-Communication-Using-Shared-Memory-and-Int) seems to be a learned discussion of the topic.

But so far I haven’t actually found a library that does what I need.

---

<div class="post-metadata">

**Author:** ![Isilder](https://avatars.discourse-cdn.com/v4/letter/i/cc9497/32.png) [@Isilder](https://boards.straightdope.com/u/Isilder)\
**Post date:** [January 28, 2014, 1:21pm UTC](https://boards.straightdope.com/t/c-or-c-library-for-inter-process-communication-in-windows/679904/10 "2014-01-28T13:21:17Z")

</div>

> [@MaxTheVool](#):
>
> -shared memory  
> -a named pipe  
> -TCP/IP  
> -memory-mapped files

Add DDE

> **[About Dynamic Data Exchange - Win32 apps](https://learn.microsoft.com/en-us/windows/win32/dataxchg/about-dynamic-data-exchange?redirectedfrom=MSDN)**
>
> This topic discusses transferring data between applications.

Well it might be based on one of the earlier 4 but being somewhat inbuilt (not a third party library), and being easier to use,… well it might be what the OP wanted.
