C++ 通过命名管道发送DWORD
我试图通过一个命名管道发送一个DWORD数组,但我一直在想如何发送一个DWORD。 到目前为止,我得到的是:C++ 通过命名管道发送DWORD,c++,windows,named-pipes,C++,Windows,Named Pipes,我试图通过一个命名管道发送一个DWORD数组,但我一直在想如何发送一个DWORD。 到目前为止,我得到的是: // Create a pipe to send data HANDLE pipe = CreateNamedPipe( L"\\\\.\\pipe\\my_pipe", PIPE_ACCESS_OUTBOUND, PIPE_TYPE_BYTE, 1, 0, 0, 0,
// Create a pipe to send data
HANDLE pipe = CreateNamedPipe(
L"\\\\.\\pipe\\my_pipe",
PIPE_ACCESS_OUTBOUND,
PIPE_TYPE_BYTE,
1,
0,
0,
0,
NULL
);
/* Waiting for the other side to connect and some error handling cut out */
//Here I try to send the DWORD
DWORD msg = 0xDEADBEEF;
DWORD numBytesWritten = 0;
result = WriteFile(
pipe,
(LPCVOID)msg,
sizeof(msg),
&numBytesWritten,
NULL
);
但是WriteFile(…)
调用失败并返回false
接收端:
/* CreateFile(...) */
DWORD msg[128];
DWORD numBytesRead = 0;
BOOL result = ReadFile(
pipe,
msg,
127 * sizeof(DWORD),
&numBytesRead,
NULL
);
我是失败得很惨还是方向正确?result=WriteFile(
result = WriteFile(
pipe,
&msg, // <---- change this line
sizeof(msg),
&numBytesWritten,
NULL
);
管
&msg,//我的英雄和救世主!谢谢你,现在我已经设法让它开始工作了!编辑:讨厌的5分钟限制,直到我能接受答案。加上msg=0xDEADBEEF的一分钟,让我咯咯笑了。而且饿了。:)另外,我在快速谷歌搜索后学到了一些东西: