home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Programming Win32 Under the API
/
ProgrammingWin32UnderTheApiPatVillani.iso
/
Chapter7
/
7-4
/
client.c
next >
Wrap
C/C++ Source or Header
|
2000-03-08
|
922b
|
52 lines
#include <stdio.h>
#include <windows.h>
#define PIPESIZE 1024
#define PIPE "\\\\.\\pipe\\mypipe"
int main(int argc, char *argv[])
{
HANDLE hPipe;
DWORD dwWritten, dwRead, dwError;
char sBuffer[PIPESIZE];
BOOL fConnected;
for(;;)
{
if((hPipe = CreateFile(PIPE,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL)) != INVALID_HANDLE_VALUE)
{
break;
}
if((dwError = GetLastError()) != ERROR_PIPE_BUSY)
{
printf("Could not open pipe, hPipe = %08lx error = #%d.\n",
hPipe, dwError);
ExitProcess(1);
}
if(!WaitNamedPipe(PIPE, 20000))
{
printf("Could not open pipe #2.\n");
ExitProcess(1);
}
}
ReadFile(hPipe, &sBuffer, PIPESIZE, &dwRead, NULL);
sBuffer[dwRead] = 0;
printf("%ld Bytes read, Data = \"%s\"\n", dwRead, sBuffer);
FlushFileBuffers(hPipe);
DisconnectNamedPipe(hPipe);
CloseHandle(hPipe);
}