netseng
netseng

Reputation: 2286

Interprocess Communication Between C# application and unmanaged C++ application

I have two Windows services, the first one written in C# and the second written in unmanaged C++, I want to know how can I do two-way interprocess communication.

Upvotes: 6

Views: 9011

Answers (8)

ren
ren

Reputation: 3993

I would say redis would be the best solution for any kind of interprocess communication

Upvotes: 0

Matt Davis
Matt Davis

Reputation: 46052

If the interprocess communication is always going to be done on the same machine, named pipes is the way to go because they are faster than other options.

However, if there is even the slightest chance that this communication might occur across machine boundaries at some point, go with the socket approach. For C++, you'll need the winsock2.h header file. In C#, use the System.Net.Sockets namespace.

It's been a while since I've done unmanaged C++, but my recollection is that you'll have to write less C++ code if you create the server on the C++ side and then use the TcpClient class on the C# side.

Upvotes: 8

Vinay
Vinay

Reputation: 4793

Create a Singleton COM object. Maintain data in this COM object, which can be read by both C++ and C# applications.

Upvotes: 0

Edwin Jarvis
Edwin Jarvis

Reputation: 6140

I would say sockets and a messaging system. Check our for Google Protocol Buffers.

Upvotes: 1

casperOne
casperOne

Reputation: 74560

There are a number of ways to do this, but I think that the best way would be to use WCF and COM+. If you host a service in COM+, you can access it through WCF in your .NET service, and through COM interfaces in your unmanaged code.

You might want to check out the following sections of the MSDN documentation to get started:

Integrating WCF Services with COM+: http://msdn.microsoft.com/en-us/library/bb735856.aspx

Integrating with COM+ Applications Overview: http://msdn.microsoft.com/en-us/library/ms734723.aspx

Upvotes: 1

dicroce
dicroce

Reputation: 46820

Sockets are probably your best bet.

With sockets your not necessarily tied to both programs being on the same machine.

Also, it's likely to be the most portable option (heck, Windows even has select() for sockets).

Upvotes: 2

denis phillips
denis phillips

Reputation: 12780

Sockets and Named Pipes are two options well supported in the managed and unmanaged environments.

Upvotes: 1

Ana Betts
Ana Betts

Reputation: 74692

Use either DCOM/RPC or named pipes - anything else is either insecure, hacky, or both.

Upvotes: 0

Related Questions