任何正确配置DCOM,使得客户端程序能够访问远程计算机组件 ,以下是客户端代码,访问组件时出错,CoCreateInstanceEx返回一个错误(拒绝访问);
请各位大虾指正
CoInitializeEx( NULL,COINIT_APARTMENTTHREADED );
COAUTHIDENTITY myIdent;
myIdent.Domain = L"office";
myIdent.DomainLength = 7;
myIdent.User = L"zhengpingsheng";
myIdent.UserLength = 15;
myIdent.Password = L"123";
myIdent.PasswordLength = 4;
myIdent.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI ;
COAUTHINFO myInfo;
ZeroMemory(&myInfo,sizeof(myInfo));
myInfo.dwAuthnLevel = RPC_C_AUTHN_LEVEL_NONE;
myInfo.dwAuthnSvc = RPC_C_AUTHN_WINNT;
myInfo.dwCapabilities = EOAC_NONE;
myInfo.dwAuthzSvc = RPC_C_AUTHZ_NONE;
myInfo.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE ;
myInfo.pAuthIdentityData = &myIdent;
myInfo.pwszServerPrincName = NULL;
COSERVERINFO ServerMath;
ServerMath.dwReserved1 = 0;
ServerMath.pwszName = L"172.16.138.58";
ServerMath.pAuthInfo = &myInfo;
ServerMath.dwReserved2 = 0;
IDTest *pMath = NULL; MULTI_QI myQI;
myQI.pIID = &IID_IDTest;
myQI.pItf = NULL;
myQI.hr = 0 ;
try
{
HRESULT hResult = CoCreateInstanceEx(CLSID_DTest,NULL,CLSCTX_SERVER,&ServerMath,1,&myQI);
}
catch(...)
{
AfxMessageBox("");
} pMath = (IDTest *)myQI.pItf;
long lResult;
pMath->Add(10,10,&lResult);
CString str;
str.Format("%d",lResult);
AfxMessageBox(str);
CoUninitialize();
请各位大虾指正
CoInitializeEx( NULL,COINIT_APARTMENTTHREADED );
COAUTHIDENTITY myIdent;
myIdent.Domain = L"office";
myIdent.DomainLength = 7;
myIdent.User = L"zhengpingsheng";
myIdent.UserLength = 15;
myIdent.Password = L"123";
myIdent.PasswordLength = 4;
myIdent.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI ;
COAUTHINFO myInfo;
ZeroMemory(&myInfo,sizeof(myInfo));
myInfo.dwAuthnLevel = RPC_C_AUTHN_LEVEL_NONE;
myInfo.dwAuthnSvc = RPC_C_AUTHN_WINNT;
myInfo.dwCapabilities = EOAC_NONE;
myInfo.dwAuthzSvc = RPC_C_AUTHZ_NONE;
myInfo.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE ;
myInfo.pAuthIdentityData = &myIdent;
myInfo.pwszServerPrincName = NULL;
COSERVERINFO ServerMath;
ServerMath.dwReserved1 = 0;
ServerMath.pwszName = L"172.16.138.58";
ServerMath.pAuthInfo = &myInfo;
ServerMath.dwReserved2 = 0;
IDTest *pMath = NULL; MULTI_QI myQI;
myQI.pIID = &IID_IDTest;
myQI.pItf = NULL;
myQI.hr = 0 ;
try
{
HRESULT hResult = CoCreateInstanceEx(CLSID_DTest,NULL,CLSCTX_SERVER,&ServerMath,1,&myQI);
}
catch(...)
{
AfxMessageBox("");
} pMath = (IDTest *)myQI.pItf;
long lResult;
pMath->Add(10,10,&lResult);
CString str;
str.Format("%d",lResult);
AfxMessageBox(str);
CoUninitialize();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货