我能够在.EXE中创建一个命名管道,并通过管道从.DLL通过管道发送数据,通过.EXE加载到一个单独的进程中,并成功接收和打印数据。但是,当我反转管道的方向时,.EXE发送数据并且.DLL接收数据,管道将无法工作。有没有理由说.DLL无法创建管道并读取数据?
这是读者代码(创建和读取管道):
struct in{
int x;
};
OutFile in;
DWORD dwRead;
HANDLE hPipe = CreateNamedPipe(TEXT("\\\\.\\pipe\\Firehose"),
PIPE_ACCESS_DUPLEX | PIPE_TYPE_BYTE | PIPE_READMODE_BYTE,
PIPE_WAIT,
1,
sizeof(OutFile),
sizeof(OutFile),
NMPWAIT_USE_DEFAULT_WAIT,
NULL);
while (hPipe != INVALID_HANDLE_VALUE){
if (ConnectNamedPipe(hPipe, NULL) != FALSE) {
while (ReadFile(hPipe, &in, sizeof(in), 0, NULL) != FALSE){
if(in.x == 0) dataRecieved = true;
else dataRecieved = false;
}
}
DisconnectNamedPipe(hPipe);
}
以下是发件人代码:
struct in{
int x;
}
in data{5};
HANDLE hPipe = CreateFile(TEXT("\\\\.\\pipe\\Firehose"),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hPipe != INVALID_HANDLE_VALUE){
WriteFile(hPipe,
&data,
sizeof(data),
0,
NULL);
CloseHandle(hPipe);
}