一
void
{
//
if(OpenClipboard())
{
EmptyClipboard();
GlobalUnlock(hClip);
SetClipboardData(CF_TEXT,hClip);
CloseClipboard();
}
}
void
{
//
if(OpenClipboard())
{
GlobalUnlock(hClip);
CloseClipboard();
}
}
二
父进程
void
{
//
SECURITY_ATTRIBUTES
sa.bInheritHandle=TRUE;
sa.lpSecurityDescriptor=NULL;
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
if(!CreatePipe(&hRead,&hWrite,&sa,0))
{
}
STARTUPINFO
ZeroMemory(&sui,sizeof(STARTUPINFO));
sui.cb=sizeof(STARTUPINFO);
sui.dwFlags=STARTF_USESTDHANDLES;
sui.hStdInput=hRead;
sui.hStdOutput=hWrite;
sui.hStdError=GetStdHandle(STD_ERROR_HANDLE);
PROCESS_INFORMATION
if(!CreateProcess("..\\Child\\Debug\\Child.exe",NULL,NULL,NULL,
{
CloseHandle(hRead);
}
else
{
}
}
void
{
//
char
DWORD
if(!ReadFile(hRead,buf,100,&dwRead,NULL))
{
}
MessageBox(buf);
}
void
{
//
char
DWORD
if(!WriteFile(hWrite,buf,strlen(buf)+1,&dwWrite,NULL))
{
}
}
子进程
void
{
CView::OnInitialUpdate();
//
hRead=GetStdHandle(STD_INPUT_HANDLE);
hWrite=GetStdHandle(STD_OUTPUT_HANDLE);
}
void
{
//
char
DWORD
if(!ReadFile(hRead,buf,100,&dwRead,NULL))
{
}
MessageBox(buf);
}
void
{
//
char
DWORD
if(!WriteFile(hWrite,buf,strlen(buf)+1,&dwWrite,NULL))
{
}
}
三
服务端进程
void
{
//
hPipe=CreateNamedPipe("\\\\.\\pipe\\MyPipe",
if(INVALID_HANDLE_VALUE==hPipe)
{
}
HANDLE
hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
if(!hEvent)
{
}
OVERLAPPED
ZeroMemory(&ovlap,sizeof(OVERLAPPED));
ovlap.hEvent=hEvent;
if(!ConnectNamedPipe(hPipe,&ovlap))
{
}
if(WAIT_FAILED==WaitForSingleObject(hEvent,INFINITE))
{
}
CloseHandle(hEvent);
}
void
{
//
char
DWORD
if(!ReadFile(hPipe,buf,100,&dwRead,NULL))
{
}
MessageBox(buf);
}
void
{
//
char
DWORD
if(!WriteFile(hPipe,buf,strlen(buf)+1,&dwWrite,NULL))
{
}
}
客户端进程
void
{
//
if(!WaitNamedPipe("\\\\.\\pipe\\MyPipe",NMPWAIT_WAIT_FOREVER))
{
}
hPipe=CreateFile("\\\\.\\pipe\\MyPipe",GENERIC_READ
if(INVALID_HANDLE_VALUE==hPipe)
{
}
}
void
{
//
char
DWORD
if(!ReadFile(hPipe,buf,100,&dwRead,NULL))
{
}
MessageBox(buf);
}
void
{
//
char
DWORD
if(!WriteFile(hPipe,buf,strlen(buf)+1,&dwWrite,NULL))
{
}
}
四
服务端进程
void
{
//
HANDLE
hMailslot=CreateMailslot("\\\\.\\mailslot\\MyMailslot",0,
if(INVALID_HANDLE_VALUE==hMailslot)
{
}
char
DWORD
if(!ReadFile(hMailslot,buf,100,&dwRead,NULL))
{
}
MessageBox(buf);
CloseHandle(hMailslot);
}
客户端进程
void
{
//
HANDLE
hMailslot=CreateFile("\\\\.\\mailslot\\MyMailslot",GENERIC_WRITE,
if(INVALID_HANDLE_VALUE==hMailslot)
{
}
char
DWORD
if(!WriteFile(hMailslot,buf,strlen(buf)+1,&dwWrite,NULL))
{
}
CloseHandle(hMailslot);
}
跨网络的进程间通信可用:命名管道和邮槽(邮槽可实现一对多通信)
邮槽发送的数据量较小(424字节),发送大量数据可采用管道来完成