1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
GetComputerName(machineName,&d_Size);
wsprintf(pipeName,"\\\\%s\\pipe\\msnp",machineName);
msnPipe=CreateFile(pipeName,GENERIC_READ | GENERIC_WRITE,0,
(LPSECURITY_ATTRIBUTES)NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,(HANDLE)NULL);
if(msnPipe==INVALID_HANDLE_VALUE)
{
cerr << "Error: Unable to connect a named pipe " << endl;
return 0;
}
if(!WriteFile(msnPipe,textToSend,strlen(textToSend)+1,&numBytesWritten,(LPOVERLAPPED)NULL))
{
cerr << "error:unable to write to named pipe" << endl;
CloseHandle(msnPipe);
return 0;
}
if(!ReadFile(msnPipe,textRecvd,128,&numBytesRead,(LPOVERLAPPED)NULL))
{
cerr << "error:unable to read from named pipe" << endl;
CloseHandle(msnPipe);
return 0;
} |
Partager