//如果不支持,我就放弃了。
//连接点机制是否可以作为DCOM跨主机时回传客户异步消息的手段?
//跨进程本机调试已通过。 HRESULT hr = CoInitializeSecurity( NULL, //Points to security descriptor 
  -1, //Count of entries in asAuthSvc 
  NULL, //Array of names to register 
  NULL, //Reserved for future use 
  RPC_C_AUTHN_LEVEL_NONE, //The default authentication //level for proxies 
  RPC_C_IMP_LEVEL_IMPERSONATE, //The default impersonation //level for proxies 
  NULL, //Reserved; must be set to NULL 
  EOAC_NONE, //Additional client or //server-side capabilities 
  NULL //Reserved for future use 
  );  COAUTHIDENTITY us;

us.User           = L"xxxxxxx";
us.UserLength     = wcslen(us.User);
us.Password       = L"xxxxx";
us.PasswordLength = wcslen(us.Password);
us.Domain         = L"";
us.DomainLength   = wcslen(us.Domain);
us.Flags          = SEC_WINNT_AUTH_IDENTITY_UNICODE;

COAUTHINFO auth;

auth.dwAuthnSvc           = RPC_C_AUTHN_WINNT;
auth.dwAuthzSvc           = RPC_C_AUTHZ_NONE;
auth.pwszServerPrincName  = NULL;
auth.dwAuthnLevel         = RPC_C_AUTHN_LEVEL_CONNECT;
auth.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
auth.dwCapabilities       = EOAC_NONE;
auth.pAuthIdentityData    = &us; COSERVERINFO si;
si.dwReserved1 = 0; si.pwszName    = L"192.168.0.1";
si.pAuthInfo   = &auth;
si.dwReserved2 = 0;
MULTI_QI MultiQi={&IID_IUnknown,NULL,NOERROR};
hr=CoCreateInstanceEx(CLSID_Communi,NULL,CLSCTX_REMOTE_SERVER,&si,1,&MultiQi);
if(FAILED(hr))
{

 char * pMsgBuf;

 BOOL fOk = FormatMessage(
         FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, 
        // NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
         NULL, hr, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), 
         (LPTSTR) &pMsgBuf, 0, NULL);
        
//WriteLog("C:\\initdcom.txt",pMsgBuf);
    AfxMessageBox(pMsgBuf);
return false;
}
if (FAILED(MultiQi.hr))
{
   char * pMsgBuf;

 BOOL fOk = FormatMessage(
         FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, 
        // NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
         NULL, MultiQi.hr, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), 
         (LPTSTR) &pMsgBuf, 0, NULL); // WriteLog("C:\\initdcom.txt",pMsgBuf);
AfxMessageBox(pMsgBuf);
 return false;;
}IUnknown *pUnknown;
//通过IUnkonwn指针去查询接口指针,返回IAccount指针
pUnknown = (IUnknown *) MultiQi.pItf;


ICommuni * pCommuni;
hr = pUnknown->QueryInterface(IID_ICommuni,(void**)&pCommuni);
if(FAILED(hr))
{
 char * pMsgBuf;

 BOOL fOk = FormatMessage(
         FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, 
         NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
        // NULL, hr, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), 
         (LPTSTR) &pMsgBuf, 0, NULL); //WriteLog("C:\\initdcom.txt",pMsgBuf);
    
AfxMessageBox(pMsgBuf);
AfxMessageBox("没有查找的接口指针!");
return false;
}

AfxMessageBox("SRC创建组件成功!");
  
 
 if(SUCCEEDED(hr))
 {
  CSinkObj *pSink=NULL;
  pSink=new CSinkObj;
  
  hr=pSink->DispEventAdvise(pCommuni);
 
  /*
  ///////找到连接点/////////////////////////////
 IConnectionPointContainer* pConnectionPointContainer = NULL;    
 IConnectionPoint* pConnectionPoint = NULL ;
 DWORD dwCookie;
 hr = pCommuni->QueryInterface(IID_IConnectionPointContainer, (void**)   &pConnectionPointContainer);    
 ASSERT(SUCCEEDED(hr));
 hr = pConnectionPointContainer->FindConnectionPoint(DIID__ICommuniEvents, &pConnectionPoint); 
 ASSERT(SUCCEEDED(hr));//注册---------------------------------------------------
hr=pConnectionPoint->Advise((IUnknown*)pSink, &dwCookie);    
*///CString strLog;
//strLog.Format("%d",dwCookie);
 //这里总是过不去。########################################################
//##################################pCommuni->xxxxx()可以用,表明接口好的
ASSERT(SUCCEEDED(hr));
if(FAILED(hr))
{
 char * pMsgBuf;

 BOOL fOk = FormatMessage(
         FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, 
         //NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
        NULL, hr, MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), 
         (LPTSTR) &pMsgBuf, 0, NULL);      AfxMessageBox(pMsgBuf);
     AfxMessageBox("注册到连接点失败!");

return false;
}

解决方案 »

  1.   

    我也碰到同样的问题,com本质论最后的聊天程序就是使用的连接点,可惜作者没有任何的介绍,我空有源代码,却不知道怎么用,晕。
      

  2.   

    在www.http//codeproject.com上有一个实例“A DCOM Tutorial”它分7步讲清了怎样做一个DCOM服务器和客户端,并有源代码下载,我试过可行的。
      

  3.   

    当然支持了,你的代码有问题,得到的接口指针指向一个代理,要为其设置代理权限后才能使用,否则会报没有访问权限。激活权限和访问权限是两回事,你只设置了激活权限。
    Create成功后,先查询IUnknown接口,才使用CoSetProxyBlanket函数设置权限,就可以正常使用了。
    具体自己搜一下。