简体   繁体   English

在两个C ++程序之间交换消息

[英]Exchanging messages between two C++ programs

I am new to creating Windows applications in C++. 我是用C ++创建Windows应用程序的新手。 My task is to write two cpp files, one of which will send a number (x) to the other one, the other one will evaluate f(x) and send it back to the first one. 我的任务是编写两个cpp文件,其中一个将向另一个发送一个数字(x),另一个将评估f(x)并将其发送回第一个。 I should implement it using Messages. 我应该使用Messages实现它。 Couldn't get anything specific online, Could someone pls give me a clue, where to start? 无法在网上得到任何具体信息,有人可以给我一个线索,从哪里开始? Great thanx! 太棒了!

Are you talking about window messages? 你在谈论窗口消息吗? If so, the sending app could use SendMessage , which would cause the receiving app to get its window procedure executed. 如果是这样,发送应用程序可以使用SendMessage ,这将导致接收应用程序执行其窗口过程。 Of course, this means that the receiving app needs to create a window whose window handle is somehow made available to the sending app. 当然,这意味着接收应用程序需要创建一个窗口,其窗口句柄以某种方式可供发送应用程序使用。

You can do it in several ways. 你可以用几种方式做到这一点。

Look at ZeroMQ (http://zeromq.org ; cross-platform, LGPL). 看看ZeroMQ(http://zeromq.org;跨平台,LGPL)。 It is a very simple, lightweight and powerfull library. 它是一个非常简单,轻量级和强大的库。 From the very basic level you can use it to exchange UDP-style datagrams, but through reliable transport (TCP or some variants). 从最基本的层面,您可以使用它来交换UDP样式的数据报,但通过可靠的传输(TCP或某些变体)。 Also you have cancelling support, time-based polling and advanced network schemes (which are non-needed in your case). 您还取消了支持,基于时间的轮询和高级网络方案(在您的情况下不需要)。 I've selected it for a similar task, and it performs very well. 我选择了它来完成类似的任务,并且表现非常出色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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