int main(int argc, const char **argv)
wcout << "Connecting to pipe..." << endl;
HANDLE pipe = CreateFile(
"\\\\.\\pipe\\screenshot",
if (pipe == INVALID_HANDLE_VALUE) {
wcout << "Failed to connect to pipe." << endl;
wcout << "Reading data from pipe..." << endl;
char* lpbuf = (char*)VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL;
DWORD dwCreationDisposition = OPEN_ALWAYS;
DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
HANDLE hTemplateFile = NULL;
HANDLE handle = CreateFile("test.jpg", dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
WriteFile(handle, lpbuf, size, &numBytesRead, NULL);
wcout << "Failed to read data from the pipe." << endl;