简体   繁体   中英

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

我有两个Windows服务,第一个用C#编写,第二个用非托管C ++编写,我想知道如何进行双向进程间通信。

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.

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).

套接字和命名管道是托管和非托管环境中都支持的两个选项。

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

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

我会说redis将是任何类型的进程间通信的最佳解决方案

使用DCOM / RPC或命名管道 - 其他任何东西都是不安全,hacky或两者兼而有之。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM