Skip to content

Instantly share code, notes, and snippets.

@FedericoPonzi
Last active May 1, 2021 15:09
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save FedericoPonzi/6c8e765f7ef12782add9 to your computer and use it in GitHub Desktop.
Save FedericoPonzi/6c8e765f7ef12782add9 to your computer and use it in GitHub Desktop.
#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