#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#define PIPE_NAME "\\\\WHL-DC-002\\Pipe\\Wohlhabend3215"
void main(void) {
	HANDLE PipeHandle;
	DWORD BytesWritten;
	DWORD BytesReaden;
char buffer[256];
	if (WaitNamedPipe(PIPE_NAME, NMPWAIT_WAIT_FOREVER) == 0)
	{
		printf("WaitNamedPipe failed with error %d\n",
			GetLastError());
		_getch();
		return;
	}
	if ((PipeHandle = CreateFile(PIPE_NAME,
		GENERIC_READ | GENERIC_WRITE, 0,
		(LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,
		(HANDLE) NULL)) == INVALID_HANDLE_VALUE)
	{
		printf("CreateFile failed with error %d\n", GetLastError());
			_getch();
		return;
	}
	if (WriteFile(PipeHandle, "This is a test", 14, &BytesWritten, 
		NULL) == 0)
	{
		printf("WriteFile failed with error %d\n", GetLastError());
		CloseHandle(PipeHandle);
			_getch();
		return;
	}
	printf("Wrote %d bytes", BytesWritten);
	printf("\n");
	if (ReadFile(PipeHandle, buffer, 256, &BytesReaden, 
		NULL) == 0)
	{
		printf("ReadFile failed with error %d\n", GetLastError());
		CloseHandle(PipeHandle);
			_getch();
		return;
	}
     printf("Read %d bytes\n",BytesReaden);
     buffer[BytesReaden]='\0';
//	printf("Wrote %d bytes", BytesWritten);
printf(buffer);
printf("\n");
	CloseHandle(PipeHandle);
		_getch();
}

