用户名不同的计算机之间的调用dcom
2009-10-07 20:29:43 来源:WEB开发网例子2:
HRESULT hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, NULL);
COAUTHIDENTITY us;
us.User = m_strName.AllocSysString();
us.UserLength = wcslen(us.User);
us.Password = m_strPassword.AllocSysString();
us.PasswordLength = wcslen(us.Password);
us.Domain = m_strDomain.AllocSysString();
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;
MULTI_QI qi;
CComBSTR bstr = strComputer;
LPWSTR name = bstr.m_str;
si.dwReserved1 = 0;
si.pwszName = name;
si.pAuthInfo = m_bAccess ? &auth : NULL;
si.dwReserved2 = 0;
IID iid = __uuidof(m_pIRemoteControl);
qi.pIID = &iid;
qi.pItf = NULL;
do
{
hr = CoCreateInstanceEx(__uuidof(RemoteControl), NULL, CLSCTX_SERVER, &si, 1, &qi);
if(FAILED(hr) || FAILED(qi.hr))
break ;
m_pIRemoteControl = (IRemoteControl *)qi.pItf;
}while(0);
-----------------------------------
例子3:
HRESULT hr = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, NULL);
COAUTHIDENTITY us;
us.User = m_strName.AllocSysString();
us.UserLength = wcslen(us.User);
us.Password = m_strPassword.AllocSysString();
us.PasswordLength = wcslen(us.Password);
us.Domain = m_strDomain.AllocSysString();
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;
MULTI_QI MultiQi={&IID_IUnknown,NULL,NOERROR};
COSERVERINFO si;
CComBSTR bstr = strComputer;
LPWSTR name = bstr.m_str;
si.dwReserved1 = 0;
si.pwszName = name;
si.pAuthInfo = m_bAccess ? &auth : NULL;
si.dwReserved2 = 0;
hr = CoCreateInstanceEx(__uuidof(RemoteControl), NULL, CLSCTX_SERVER, &si, 1, &MultiQi);
if(FAILED(hr))
{
MessageBox("创建对象实例失败!");
return;
}
//通过IUnkonwn指针去查询接口指针,返回IAccount指针
pUnknown = (IUnknown *) MultiQi.pItf;
hr = pUnknown->QueryInterface(IID_IAccount,(void**)&pAccount);
if(FAILED(hr))
{
MessageBox("没有查找的接口指针!");
return false;
}
pUnknown->Release();
更多精彩
赞助商链接