如何发送字节数组到C ++中的另一个进程 [英] How to send a byte array to another process in C++

查看:135
本文介绍了如何发送字节数组到C ++中的另一个进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在网站上检查一种方法,以将数据从一个过程转移到另一个在C ++。我发现了方法SendMessage(),但它似乎不能采取一个字节数组。

I have been checking on the site for a way to transfer data from a process to another one in C++. I found the method SendMessage() but it does not seem to be able to take a byte array.

为了解释这里的上下文,我有一个应用程序将数据发送到另一个应用程序。我们有几个具有不同ID的对象。接收的应用程序为每个不同的对象创建一个选项卡。如果接收数据的应用程序关闭,我们将启动一个新进程并向用户显示数据。如果我们第二次发送,我们需要检查ID,看看我们是否已经有一个对象,如果是替换它。否则为新对象添加新选项卡。

To explain a little bit the context here, I have an application that send data to another one. We have several objects with different IDs. The app that receives creates a tab for every different objects. If the app that is receiving the data is closed, we start a new process and show the data to the user. If we send a second time, we need to check with IDs to see if we already have one of the objects, if yes replace it. Otherwise add new tabs for the new objects.

我们使用来自google的协议缓冲区,他们使用字节数组进行传输和序列化,所以这就是为什么我需要找到一种方法来从一个进程发送一个字节数组另一个。

We use protocol buffers from google and they work with byte arrays for transportation and serialization, so that's why I need to find a way to send a byte array from a process to another.

我能够得到进程的HWND,但我不知道从现在开始。

I was able to get the HWND of the process but I don't know where to go from now.

推荐答案

进程间通信是一种特定于平台的事情。在Windows中,有很多方法可以做到这一点。这篇MSDN文章介绍了几种方法及其优点,缺点和用例:

Interprocess communication is a plattform-specific thing. In Windows, there are many ways to do that. This MSDN article describes several methods and their pros, cons and use-cases:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365574(v = vs.85 ).aspx

当您控制这两个应用程序,并且对第三方应用程序的支持不在乎时,请发送 WM_COPYDATA 消息通过SendMessage()传递给其他进程可能是一个好办法。

When you control both applications, and support for 3rd party applications is no concern for you, then sending the WM_COPYDATA message through SendMessage() to the other process might be a good approach.

这篇关于如何发送字节数组到C ++中的另一个进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆