使用WM_COPYDATA在进程之间发送数据
我希望在进程之间发送文本。我发现了很多这样的例子,但没有一个我可以工作。这是我到目前为止所拥有的:
对于发送部分:
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
。
我想在两个进程之间发送文本。
你可能会说我才刚刚开始,我在 Code::Blocks 中使用 GNU GCC 编译器,我试图避免 MFC 和依赖项。
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:
for the sending part:
COPYDATASTRUCT CDS;
CDS.dwData = 1;
CDS.cbData = 8;
CDS.lpData = NULL;
SendMessage(hwnd, WM_COPYDATA , (WPARAM)hwnd, (LPARAM) (LPVOID) &CDS);
the receiving part:
case WM_COPYDATA:
COPYDATASTRUCT* cds = (COPYDATASTRUCT*) lParam;
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有关如何使用该消息的示例,请参阅 http:// /msdn.microsoft.com/en-us/library/ms649009(VS.85).aspx。您可能还想查看http://www.flounder.com/wm_copydata.htm。
dwData
成员由您定义。将其视为您可以定义的数据类型枚举。它是您想要用来识别数据是这样那样的字符串的任何东西。cbData
成员是lpData
指向的数据的大小(以字节为单位)。在您的情况下,它将是字符串的大小(以字节为单位)。lpData
成员指向要复制的数据。因此,要传输单个字符串......
然后,接收它......
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.
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.The
cbData
member is the size in bytes of the data pointed to bylpData
. In your case, it will be the size of the string in bytes.The
lpData
member points to the data you want to copy.So, to transfer a single string....
Then, to receive it....
这并不是真正的答案,而是调试时有用的提示 SendMessage(WM_COPYDATA...
好吧,Microsoft Spy++ 可能真的会派上用场。
您可以在这里找到它:
...并且
快乐的 C++ 学习 - 特别是在 C# 中,API 可以是真正的“乐趣”。 ;)
That's not really an answer but useful hint when debugging SendMessage(WM_COPYDATA...
Well Microsoft Spy++ might really come in handy.
You may find it here:
... and
Happy C++'ing - especially in C# that API can be real 'fun'. ;)