WINDOWS/C语言/管道通信实现机制

Windows管道通信范例 fSuccess = ReadFile(hPipe,ReadData,BUFSIZE,&cbBytesRead,NULL); if (! fSuccess || cbBytesRead == 0) break; else { cout << "Read data : "<<ReadData<<endl; } //写数据 fSuccess = WriteFile( hPipe, // handle to pipe s.c_str(), // buffer to write from BUFSIZE, // number of bytes to write &cbWritten, // number of bytes written NULL); // not overlapped I/O if (! fSuccess || cbReplyBytes != cbWritten) break; ------------------------------------- //创建线程 hThread = CreateThread( NULL, // no security attribute 0, // default stack size (LPTHREAD_START_ROUTINE) InstanceThread, (LPVOID) hPipe, // thread parameter 0, // not suspended &dwThreadId); // returns thread ID if(hThread == NULL) { cout << "create thread failure!\n"; exit(0); } else CloseHandle(hThread);

















评论11