【发布时间】:2014-12-18 12:17:19
【问题描述】:
我试图通过命名管道发送一组 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,
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
);
我是在惨败还是朝着正确的方向前进?
【问题讨论】:
-
加上一个 msg=0xDEADBEEF,让我咯咯笑……又饿了。 :) 另外,我在快速谷歌后学到了一些东西:en.wikipedia.org/wiki/Hexspeak
标签: c++ windows named-pipes