#include <windows.h> #pragma comment(linker,"/subsystem:windows") int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state ) { char buffer[]="hello,pipe!"; char result[16]={0}; SECURITY_ATTRIBUTES sa={0}; sa.bInheritHandle = TRUE; sa.lpSecurityDescriptor = NULL; sa.nLength = sizeof(SECURITY_ATTRIBUTES); HANDLE hR=NULL; HANDLE hW=NULL; DWORD num; //创建一个管道 CreatePipe( &hR, &hW, &sa, NULL ); //向管道里写入内容 WriteFile( hW, buffer, sizeof(buffer), &num, NULL ); //读取管道里的内容 ReadFile( hR, result, sizeof(result), &num, NULL ); MessageBox( NULL, result, "从管道里读取到的东西", 0 ); return 0; }