Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 通过命名管道发送DWORD_C++_Windows_Named Pipes - Fatal编程技术网

C++ 通过命名管道发送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,

我试图通过一个命名管道发送一个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 
    );
我是失败得很惨还是方向正确?

result=WriteFile(
result = WriteFile(
    pipe,
    &msg, // <---- change this line
    sizeof(msg),
    &numBytesWritten, 
    NULL 
    );

&msg,//我的英雄和救世主!谢谢你,现在我已经设法让它开始工作了!编辑:讨厌的5分钟限制,直到我能接受答案。加上msg=0xDEADBEEF的一分钟,让我咯咯笑了。而且饿了。:)另外,我在快速谷歌搜索后学到了一些东西: