I am able to create a Named Pipe in a .EXE and send data through the pipe from a .DLL loaded into a separate process through the .EXE and successfully receive and print the data. However, when I reverse the direction of the pipe, where the .EXE sends the data and the .DLL receives the data , the pipe will not work. Is there a reason why a .DLL cannot create a pipe and read data?
Here is the reader code (creates and reads pipe):
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);
}
Here is the sender code:
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);
}