/* filename: pclient.c */
#define UNICODE
#include <windows.h>
#include <stdio.h>
int main() {
wchar_t buf[1024];
int numBytes = 0;
BOOL writeGood = FALSE;
HANDLE hPipe = NULL;
hPipe = CreateFile(L"\\\\.\\pipe\\purpose",
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hPipe == INVALID_HANDLE_VALUE) {
_putws(L"hPipe error.\n");
return 0;
}
writeGood = WriteFile(hPipe, L"AAAAAAAAAAAAAAAA", 32, &numBytes, NULL);
printf("numBytes for writefile = %d\n", numBytes);
if (writeGood == FALSE) return 0;
Sleep(500);
writeGood = WriteFile(hPipe, L"BBBBBBBBBBBBBBBB", 32, &numBytes, NULL);
printf("numBytes for writefile = %d\n", numBytes);
if (writeGood == FALSE) return 0;
Sleep(500);
writeGood = WriteFile(hPipe, L"C", 4, &numBytes, NULL);
printf("numBytes for writefile = %d\n", numBytes);
_putws(L"all done, stop...");
system("pause");
CloseHandle(hPipe);
return 0;
}
LyogZmlsZW5hbWU6IHBjbGllbnQuYyAqLwoKI2RlZmluZSBVTklDT0RFCgojaW5jbHVkZSA8d2luZG93cy5oPgojaW5jbHVkZSA8c3RkaW8uaD4KCmludCBtYWluKCkgewogIHdjaGFyX3QgYnVmWzEwMjRdOwogIGludCBudW1CeXRlcyA9IDA7CiAgQk9PTCB3cml0ZUdvb2QgPSBGQUxTRTsKCiAgSEFORExFIGhQaXBlID0gTlVMTDsKICBoUGlwZSA9IENyZWF0ZUZpbGUoTCJcXFxcLlxccGlwZVxccHVycG9zZSIsCiAgICAgICAgICAgICAgICAgICAgIEdFTkVSSUNfUkVBRCB8IEdFTkVSSUNfV1JJVEUsCiAgICAgICAgICAgICAgICAgICAgIDAsCiAgICAgICAgICAgICAgICAgICAgIE5VTEwsCiAgICAgICAgICAgICAgICAgICAgIE9QRU5fRVhJU1RJTkcsCiAgICAgICAgICAgICAgICAgICAgIDAsCiAgICAgICAgICAgICAgICAgICAgIE5VTEwpOwoKICB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