使用WM_COPYDATA在进程之间发送数据 [英] Use WM_COPYDATA to send data between processes

查看:174
本文介绍了使用WM_COPYDATA在进程之间发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在进程之间发送文本。我发现了很多这样的例子,但没有一个,我可以得到工作。这是我到目前为止:

I wish to send text between processes. I have found lots of examples of this but none that I can get working. Here is what I have so far:

为发送部分:

COPYDATASTRUCT CDS;
CDS.dwData = 1;
CDS.cbData = 8;
CDS.lpData = NULL;
SendMessage(hwnd, WM_COPYDATA , (WPARAM)hwnd, (LPARAM) (LPVOID) &CDS);

接收部分:

case WM_COPYDATA:
COPYDATASTRUCT* cds = (COPYDATASTRUCT*) lParam;

我不知道如何构造COPYDATASTRUCT,我刚刚把东西放在似乎工作。当调试WM_COPYDATA情况下执行,但我不知道该怎么做COPYDATASTRUCT。

I dont know how to construct the COPYDATASTRUCT, I have just put something in that seems to work. When debugging the WM_COPYDATA case is executed, but again I dont know what to do with the COPYDATASTRUCT.

我想在两个进程之间发送文本。

I would like to send text between the two processes.

因为你可能告诉我刚刚开始,我在Code :: Blocks中使用GNU GCC Compiler,我试图避免MFC和依赖。

As you can probably tell I am just starting out, I am using GNU GCC Compiler in Code::Blocks, I am trying to avoid MFC and dependencies.

推荐答案

有关如何使用邮件的示例,请参阅http://msdn.microsoft.com/en-us/library/ms649009(VS.85).aspx 。您还可以查看 http://www.flounder.com/wm_copydata.htm

For an example of how to use the message, see http://msdn.microsoft.com/en-us/library/ms649009(VS.85).aspx. You may also want to look at http://www.flounder.com/wm_copydata.htm.

dwData 成员由您定义。想象它像一个数据类型枚举,你要定义。

The dwData member is defined by you. Think of it like a data type enum that you get to define. It is whatever you want to use to identify that the data is a such-and-such string.

cbData member是 lpData 指向的数据的大小(以字节为单位)。

The cbData member is the size in bytes of the data pointed to by lpData. In your case, it will be the size of the string in bytes.

lpData 成员指向数据

因此,要传输单个字符串....

So, to transfer a single string....

LPCTSTR lpszString = ...;
COPYDATASTRUCT cds;
cds.dwData = 1; // can be anything
cds.cbData = sizeof(TCHAR) * (_tcslen(lpszString) + 1);
cds.lpData = lpszString;
SendMessage(hwnd, WM_COPYDATA, (WPARAM)hwnd, (LPARAM)(LPVOID)&cds);

然后,接收.... ....

Then, to receive it....

COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
if (pcds->dwData == 1)
{
    LPCTSTR lpszString = (LPCTSTR)(pcds->lpData);
    // do something with lpszString...
}

这篇关于使用WM_COPYDATA在进程之间发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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