我本机地址192.168.18.252,在本机上运行服务,运行客户端,一切正常.
在另一台电脑192.168.18.169上运行客户端(服务器在我的电脑上已开启),GetLastError返回错误代码1326.
注:我的电脑可以通过网络访问(需要用户名和密码,可我不知道RpcStringBindingCompose怎么把密码用户写进去),防火墙已经关闭.
客户端代码如下:
int main()
{
    unsigned char* pszStringBinding = NULL;

    // 创建一个字符串绑定句柄.这里不进行连接.
    if(RpcStringBindingCompose(
        NULL,                              // 用于绑定的UUID.
        (unsigned char*)("ncacn_np"),      // 使用named pipe.
        (unsigned char*)"\\\\192.168.18.252",              // 网络地址.
        (unsigned char*)("\\pipe\\hello"), // named pipe端口.
        NULL,                              // 使用依赖网络的协议.
        &pszStringBinding))                // 字符串绑定输出.
     {
cout << "绑定错误!!!" << endl;
getchar(); 
   return (1);
     }
handle_t hRpcExplicitBinding = NULL;

// 确认字符串绑定句柄的格式并把它传换成一个绑定句柄.
// 这里也不进行连接.
if(RpcBindingFromStringBinding(
pszStringBinding, &hRpcExplicitBinding))

cout << "绑定错误ee!!!" << endl;
getchar(); 
return (1);
} RpcTryExcept
{
       char str[40]="Hello RPC World from RpcExplicitc!"; 

// 调用 RPC 函数,显式地使用绑定句柄 hRpcExplicitBinding.
// 这里进行连接.
RpcStringProc(hRpcExplicitBinding,(unsigned char*)str);  // 返回的结果.
        cout << str << endl;

// 暂停.
getchar();  
  }
RpcExcept(1)
{
cerr <<"Runtime reported exception:"<<GetLastError()<< endl;
}
RpcEndExcept

// 调用远程过程完成,释放字符串和绑定句柄.
if(RpcStringFree(&pszStringBinding))
{
return (1);
}

// 释放绑定句柄资源并与服务程序断开.
if(RpcBindingFree(&hRpcExplicitBinding))
{
return (1);
}

return (0);
}

解决方案 »

  1.   

    你是用ncacn_np即name pipe的方式连接的,可你的网络地址却写成了IP地址,你应该写你想要连接的服务端的主机名,即计算机名称,如果要写IP地址,你得用另一种协议了,至于用户名和密码我觉得不需要输的,只要你的服务端相应的对客户端限制的选项去掉就可以了(不过不确定),它和普通的共享文件是不一样的,你可以试试
      

  2.   

    命名管道是可以用IP地址的,我在另一台XP系统上,先通过共享连接到我的主机,
    保存连接,程序就可以运行了!