学习VC++深入浅出——命名管道的使用
2008-03-19 23:08
495 查看
学习VC++深入浅出——命名管道的使用
HANDLE hPipe;
void CNamedPipeSrvView::OnPipeCreate()
...{
// TODO: Add your command handler code here
hPipe= CreateNamedPipe("//./pipe/MyPipe",
PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,0,
1,1024,1024,0,NULL);
if(INVALID_HANDLE_VALUE ==hPipe)
...{
MessageBox("创建命名管道失败!");
hPipe= NULL;
return ;
}
HANDLE hEvent;
hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
if(!hEvent)
...{
MessageBox("创建事件对象失败");
CloseHandle(hPipe);
hPipe =NULL;
return ;
}
OVERLAPPED ovlap;
ZeroMemory(&ovlap,sizeof(OVERLAPPED));
ovlap.hEvent = hEvent;
if(!ConnectNamedPipe(hPipe,&ovlap))
...{
if(ERROR_IO_PENDING!=GetLastError())
...{
MessageBox("等待客户端连接失败!");
CloseHandle(hPipe);
CloseHandle(hEvent);
hPipe =NULL;
return ;
}
}
if(WAIT_FAILED==WaitForSingleObject(hEvent,INFINITE))
...{
MessageBox("等待对象失败!");
CloseHandle(hPipe);
CloseHandle(hEvent);
hPipe =NULL;
return ;
}
CloseHandle(hEvent);
}
void CNamedPipeSrvView::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 CNamedPipeSrvView::OnPipeWrite()
...{
// TODO: Add your command handler code here
char buf[]="http://zhangdali.org";
DWORD dwWrite;
if(!WriteFile(hPipe,buf,strlen(buf)+1,&dwWrite,NULL))
...{
MessageBox("写入数据失败!");
return ;
}
}
void CNamedPipeCltView::OnPipeWrite()
...{
// TODO: Add your command handler code here
char buf[]="http://zhangdali.org";
DWORD dwWrite;
if(!WriteFile(hPipe,buf,strlen(buf)+1,&dwWrite,NULL))
...{
MessageBox("写入数据失败!");
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::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 ;
}
}
HANDLE hPipe;
void CNamedPipeSrvView::OnPipeCreate()
...{
// TODO: Add your command handler code here
hPipe= CreateNamedPipe("//./pipe/MyPipe",
PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,0,
1,1024,1024,0,NULL);
if(INVALID_HANDLE_VALUE ==hPipe)
...{
MessageBox("创建命名管道失败!");
hPipe= NULL;
return ;
}
HANDLE hEvent;
hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
if(!hEvent)
...{
MessageBox("创建事件对象失败");
CloseHandle(hPipe);
hPipe =NULL;
return ;
}
OVERLAPPED ovlap;
ZeroMemory(&ovlap,sizeof(OVERLAPPED));
ovlap.hEvent = hEvent;
if(!ConnectNamedPipe(hPipe,&ovlap))
...{
if(ERROR_IO_PENDING!=GetLastError())
...{
MessageBox("等待客户端连接失败!");
CloseHandle(hPipe);
CloseHandle(hEvent);
hPipe =NULL;
return ;
}
}
if(WAIT_FAILED==WaitForSingleObject(hEvent,INFINITE))
...{
MessageBox("等待对象失败!");
CloseHandle(hPipe);
CloseHandle(hEvent);
hPipe =NULL;
return ;
}
CloseHandle(hEvent);
}
void CNamedPipeSrvView::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 CNamedPipeSrvView::OnPipeWrite()
...{
// TODO: Add your command handler code here
char buf[]="http://zhangdali.org";
DWORD dwWrite;
if(!WriteFile(hPipe,buf,strlen(buf)+1,&dwWrite,NULL))
...{
MessageBox("写入数据失败!");
return ;
}
}
void CNamedPipeCltView::OnPipeWrite()
...{
// TODO: Add your command handler code here
char buf[]="http://zhangdali.org";
DWORD dwWrite;
if(!WriteFile(hPipe,buf,strlen(buf)+1,&dwWrite,NULL))
...{
MessageBox("写入数据失败!");
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::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 ;
}
}
相关文章推荐
- 学习VC++深入浅出——匿名管道的使用
- 学习VC++深入浅出——ADO的使用
- 学习VC++深入浅出——剪贴板的使用
- windows下命名管道、邮件槽使用学习
- windows下命名管道、邮件槽使用学习
- 学习VC++深入浅出——ADO的使用
- VC 命名管道使用的注意事项
- VC的命名管道学习笔记总结
- 学习VC++深入浅出——DLL的使用
- .net 命名管道(NamedPipe) 的使用
- 学习VC++深入浅出——常用对话框的操作
- SQL Server中的命名管道(named pipe)及其使用
- 在.NET中使用命名管道完成进程间通信
- 命名管道的创建和使用
- Java学习笔记摘录(标识符/变量是什么/如何命名变量/数据类型/变量的使用规则)
- Linux进程间通信——使用命名管道
- solidworks二次开发 学习日记--3使用solidworks sdk api 和vc做简单开发
- VC学习一日一练(3)---MFC中使用多线程技术
- Linux下的IPC-命名管道的使用
- linux 进程学习笔记-named pipe (FIFO)命名管道