Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#define MAX_BUF 1024
#define pipename "\\\\.\\pipe\\LogPipe"
int main()
{
HANDLE pipe = CreateFile(pipename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (pipe == INVALID_HANDLE_VALUE)
{
printf("Error: %d", GetLastError());
}
char message [] = "Hi";
DWORD numWritten;
WriteFile(pipe, message, 3, &numWritten, NULL);
return 0;
}
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#define BUFSIZE 512
#define pipename "\\\\.\\pipe\\LogPipe"
int main(int argc, TCHAR *argv[])
{
while (true)
{
HANDLE pipe = CreateNamedPipe(pipename, PIPE_ACCESS_INBOUND | PIPE_ACCESS_OUTBOUND , PIPE_WAIT, 1, 1024, 1024, 120 * 1000, NULL);
if (pipe == INVALID_HANDLE_VALUE)
{
printf("Error: %d", GetLastError());
}
char data[1024];
DWORD numRead;
ConnectNamedPipe(pipe, NULL);
ReadFile(pipe, data, 1024, &numRead, NULL);
if (numRead > 0)
printf("%s\n", data);
CloseHandle(pipe);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment