//如果不支持,我就放弃了。
//连接点机制是否可以作为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;
}
//连接点机制是否可以作为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;
}
解决方案 »
- 编程如何实现挂起暂停指定的驱动呢?
- 收藏 不显示删除回复显示所有回复显示星级回复显示得分回复 关于SQL2000 msado访问时间超长的问题
- MFC中如何清除文本框中的内容
- 求救啊求救啊求救啊求救啊求救啊,
- 用VC制作一把尺子,精确到毫米(80分)
- 遇到变态问题--CTreeCtrl的InsertItem(200分)
- 请问哪位有BMP->JPEG 的源程序 就是Base 压缩方案的源程序
- VC 中如何调用SQL SERVER的存储过程?
- 谁要Codejock的XT-ToolKit 1.9.1.0
- 请问一个关于BeginWaitCursor的问题
- CEdit的派生类的OnLButtonDbClk()中,用SetSel()想高亮显示选中行,无效???? 哪里有问题呢? 谢谢
- 请问,一个窗体最多可以放多少个控件?
Create成功后,先查询IUnknown接口,才使用CoSetProxyBlanket函数设置权限,就可以正常使用了。
具体自己搜一下。