home *** CD-ROM | disk | FTP | other *** search
-
- #include <stdio.h>
- #include <windows.h>
-
- #define PIPESIZE 512
- #define PIPE "\\\\.\\pipe\\mypipe"
-
- int main(int argc, char *argv[])
- {
- HANDLE hPipe;
- DWORD dwWritten, dwRead, dwLastError, dwCount;
- char sBuffer[PIPESIZE];
- BOOL fConnected;
-
- for(dwCount = 0; ; ++dwCount)
- {
- if((hPipe = CreateNamedPipe(PIPE,
- PIPE_ACCESS_DUPLEX,
- PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE |
- PIPE_WAIT,
- PIPE_UNLIMITED_INSTANCES,
- PIPESIZE,
- PIPESIZE,
- 0,
- NULL)) == INVALID_HANDLE_VALUE)
- {
- printf("CreateNamedPipe failed!\n");
- ExitProcess(1);
- }
- else
- {
- printf("CreateNamedPipe scceeded! Handle = %08lx\n", hPipe);
- }
-
- fConnected = ConnectNamedPipe(hPipe, NULL) ?
- TRUE : ((dwLastError = GetLastError()) == ERROR_PIPE_CONNECTED);
-
- if(dwLastError == ERROR_CALL_NOT_IMPLEMENTED)
- {
- printf("Are you using Windows 9X?\nNo named pipes here!\n");
- ExitProcess(1);
- }
-
- if(fConnected)
- {
- wsprintf(sBuffer, "Hello #%ld", dwCount);
- printf("Pipe connected #%d.\n", dwCount);
- WriteFile(hPipe, sBuffer, lstrlen(sBuffer), &dwWritten, NULL);
- printf("Iteration #%d: %ld Bytes written\n", dwCount, dwWritten);
- FlushFileBuffers(hPipe);
- DisconnectNamedPipe(hPipe);
- CloseHandle(hPipe);
- }
- }
-
- }
-
-
-