VC如何利用匿名管道实现进程间通信?

 我来答
匿名用户
2013-05-09
展开全部
void CParentProcessDlg::OnOK()
{
SECURITY_ATTRIBUTES SecurityPipe;
SecurityPipe.bInheritHandle = TRUE;
SecurityPipe.lpSecurityDescriptor = NULL;
SecurityPipe.nLength = sizeof(SECURITY_ATTRIBUTES);
if (CreatePipe(&m_hRead,&m_hWrite,&SecurityPipe,0))
{
STARTUPINFO strinfo;
memset(&strinfo,0,sizeof(STARTUPINFO));
strinfo.cb = sizeof(STARTUPINFO); strinfo.hStdInput = m_hRead;
strinfo.dwFlags = STARTF_USESTDHANDLES;
strinfo.hStdOutput = m_hWrite; PROCESS_INFORMATION procInfo;
memset(&procInfo,0,sizeof(PROCESS_INFORMATION)); CreateProcess(NULL,"ChildProcess.exe",&SecurityPipe,&SecurityPipe,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&strinfo,&procInfo);
char data[]="明日科技";
unsigned long len;

if (! WriteFile(m_hWrite,data,8,&len,NULL))
{
MessageBox("数据写入失败");
}
}
else
MessageBox("匿名管道创建失败");
}
void CChildProcessDlg::OnButtonread()
{
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
if (hInput != INVALID_HANDLE_VALUE )
{
char data[10];
memset(data,0,10);
unsigned long len;
int pos = ReadFile(hInput,data,10,&len,NULL);
m_Data = data;
UpdateData(FALSE);
CloseHandle(hInput);
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式