xp与win7间通过命名管道通信遇到的问题 求教
最近在看命名管道,遇到了一个问题,描述如下:
命名管道服务器如果在xp上运行,管道客户端在win7上进行连接,可以正常通信,反过来,
命名管道服务器在win7上运行,客户端在xp上连接,无法连接,WaitNamedPipe返回错误
1385,msdn上对该错误的描述是:
ERROR_LOGON_TYPE_NOT_GRANTED
1385
Logon failure: the user has not been granted the requested logon type at this computer
好像是权限问题,不允许登陆,把防火墙关掉也没用。感觉应该是win7上对外来的连接有什么
限制,关键代码如下:
服务器(采用完成端口实现)
bool CSession::InitPipe(void)
{
for (unsigned int i = 0; i < MaxInstanceNum; i++)
{
HANDLE hPipe = NULL;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
if (InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION) == 0)
{
ErrRecord("InitializeSecurityDescriptor Error");
return FALSE;
}
if (SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE)== 0)
{
ErrRecord("SetSecurityDescriptorDacl Error");
return FALSE;
}
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = TRUE;
hPipe = CreateNamedPipe(
PipeName, // pipe name
PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED|WRITE_DAC, // read/write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances PIPE_UNLIMITED_INSTANCES
OutBuffSize, // output buffer size
InBuffSize, // input buffer size
INFINITE, // client time-out
&sa); // 此处填充NULL效果也一样
if (hPipe == INVALID_HANDLE_VALUE)
{
ErrRecord("...CreateNamedPipeW Error");
return FALSE;
}
if(!g_ComPortHandle->BindDevWithCompletionPort(hPipe,i)) //句柄与完成端口绑定
{
return FALSE;
}
memset(&g_PipeMsg[i].PipeOp,0,sizeof(PRE_IO_DATA));
g_PipeMsg[i].PipeOp.nHandle = hPipe;
g_PipeMsg[i].PipeOp.nType = OP_CONNECT;
g_PipeMsg[i].Index = i;
g_PipeMsg[i].Free = TRUE;
memset(g_PipeMsg[i].PipeOp.Buffer,'\0',sizeof(g_PipeMsg[i].PipeOp.Buffer));
InitializeCriticalSection(&g_PipeMsg[i].cs);
ConnectNamedPipe (g_PipeMsg[i].PipeOp.nHandle, &(g_PipeMsg[i].PipeOp.ol));
}
return TRUE;
}
客户端:
int ConnectServer(void)
{
while (1)
{
if (WaitNamedPipe(PIPEPATH, 2000) == FALSE)
{
printf("Client Wait fail ,Code = %d\n",GetLastError());
Sleep(1000);
}else
{
break;
}
}
hPipe = CreateFile(PIPEPATH, GENERIC_READ |GENERIC_WRITE , 0, NULL, OPEN_EXISTING,0, NULL);
if (hPipe == INVALID_HANDLE_VALUE)
{
printf("CreateFile Error ,Code = %d\n",GetLastError() );
}
return 0;
}
命名管道服务器如果在xp上运行,管道客户端在win7上进行连接,可以正常通信,反过来,
命名管道服务器在win7上运行,客户端在xp上连接,无法连接,WaitNamedPipe返回错误
1385,msdn上对该错误的描述是:
ERROR_LOGON_TYPE_NOT_GRANTED
1385
Logon failure: the user has not been granted the requested logon type at this computer
好像是权限问题,不允许登陆,把防火墙关掉也没用。感觉应该是win7上对外来的连接有什么
限制,关键代码如下:
服务器(采用完成端口实现)
bool CSession::InitPipe(void)
{
for (unsigned int i = 0; i < MaxInstanceNum; i++)
{
HANDLE hPipe = NULL;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
if (InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION) == 0)
{
ErrRecord("InitializeSecurityDescriptor Error");
return FALSE;
}
if (SetSecurityDescriptorDacl(&sd,TRUE,NULL,FALSE)== 0)
{
ErrRecord("SetSecurityDescriptorDacl Error");
return FALSE;
}
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = TRUE;
hPipe = CreateNamedPipe(
PipeName, // pipe name
PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED|WRITE_DAC, // read/write access
PIPE_TYPE_MESSAGE | // message type pipe
PIPE_READMODE_MESSAGE | // message-read mode
PIPE_WAIT, // blocking mode
PIPE_UNLIMITED_INSTANCES, // max. instances PIPE_UNLIMITED_INSTANCES
OutBuffSize, // output buffer size
InBuffSize, // input buffer size
INFINITE, // client time-out
&sa); // 此处填充NULL效果也一样
if (hPipe == INVALID_HANDLE_VALUE)
{
ErrRecord("...CreateNamedPipeW Error");
return FALSE;
}
if(!g_ComPortHandle->BindDevWithCompletionPort(hPipe,i)) //句柄与完成端口绑定
{
return FALSE;
}
memset(&g_PipeMsg[i].PipeOp,0,sizeof(PRE_IO_DATA));
g_PipeMsg[i].PipeOp.nHandle = hPipe;
g_PipeMsg[i].PipeOp.nType = OP_CONNECT;
g_PipeMsg[i].Index = i;
g_PipeMsg[i].Free = TRUE;
memset(g_PipeMsg[i].PipeOp.Buffer,'\0',sizeof(g_PipeMsg[i].PipeOp.Buffer));
InitializeCriticalSection(&g_PipeMsg[i].cs);
ConnectNamedPipe (g_PipeMsg[i].PipeOp.nHandle, &(g_PipeMsg[i].PipeOp.ol));
}
return TRUE;
}
客户端:
int ConnectServer(void)
{
while (1)
{
if (WaitNamedPipe(PIPEPATH, 2000) == FALSE)
{
printf("Client Wait fail ,Code = %d\n",GetLastError());
Sleep(1000);
}else
{
break;
}
}
hPipe = CreateFile(PIPEPATH, GENERIC_READ |GENERIC_WRITE , 0, NULL, OPEN_EXISTING,0, NULL);
if (hPipe == INVALID_HANDLE_VALUE)
{
printf("CreateFile Error ,Code = %d\n",GetLastError() );
}
return 0;
}
...全文
相关推荐
Windows服务编写(Windows Service,system权限)程序显示界面与用户交互(xp,win7通用)
实现服务与用户界面进程间的通信。遵循这些步骤,你就能构建一个能够在Windows XP和Windows 7上运行的、具有系统权限且能与用户交互的Windows服务程序。
跨平台文件共享解决方案:Win7与XP兼容工具
本文还有配套的精品资源,点击获取 简介:本文介绍了一款为Windows 7和Windows XP操作系统设计的共享工具,它简化了文件和资源共享的设置过程,解决了操作系统版本间的兼容性问题。用户可借此工具轻松实现跨平台共享,无需复杂的配置和专业知识。 1. 文件共享基础和SMB协议 文件共享是网络环境下最基本也是最重要的服务之一,它允许网络中的用户访问和管理其他用...
用DDK开发win2000xp下USB设备驱动程序
##### 4.4 USB四种通信管道的管理USB设备通过不同的管道与主机进行通信,主要包括控制管道、批量管道、中断管道和同步管道。管理这些管道包括:- 控制管道用于传输控制请求。
PHP连接sql server 2005环境配置及问题解决
Windows下PHP连接SQL Server 2005设定:首先确保Windows操作系统(推荐使用Win7或XP)已安装正确,接着确定PHP相关文件已经位于C盘下,并且配置文件php.ini位于C:
Windows 2000XP下PCI总线WDM设备驱动程序的开发.pdf
**4.3 与应用程序的通信**驱动程序与应用程序之间的通信通常通过设备文件或者命名管道等方式实现。在WDM模型中,开发者可以通过创建设备对象并注册设备的文件操作函数来实现这一功能。


其它技术问题
