64,648
社区成员
发帖
与我相关
我的任务
分享
void CNamedPipeCltView::OnPipeConnect()
{
// TODO: Add your command handler code here
if(!WaitNamedPipe("\\\\.\\pipe\\MyPipe", NMPWAIT_WAIT_FOREVER))
{
MessageBox("没有可利用的命名管道实例!");
return;
}
hPipe = CreateFile("\\\\.\\pipe\\MyPipe", GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(INVALID_HANDLE_VALUE == hPipe)
{
MessageBox("打开命名管道失败!");
hPipe = NULL;
return;
}
}
void CNamedPipeCltView::OnPipeRead()
{
// TODO: Add your command handler code here
char buf[100];
DWORD dwRead;
if(!ReadFile(hPipe, buf, 100, &dwRead, NULL))
{
MessageBox("读取数据失败!");
return;
}
MessageBox(buf);
}
void CNamedPipeCltView::OnPipeWrite()
{
// TODO: Add your command handler code here
char buf[] = "i love you!";
DWORD dwWrite;
if(!WriteFile(hPipe, buf, strlen(buf) + 1, &dwWrite, NULL))
{
MessageBox("写入数据失败!");
return;
}
}