0

I have a COM component that was originally written in Visual Studio 6. It is in a windows service which I have running on one of my development machines. I have written a quick MFC test app to call it and this works fine when run from this machine, the code looks like

COSERVERINFO si; 
MULTI_QI qi; 
COAUTHINFO cai = { RPC_C_AUTHN_NONE, RPC_C_AUTHZ_NONE, 0,RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE,0, EOAC_NONE };
si.dwReserved1 = 0; 
si.pwszName =L"{machine name}"; 
si.pAuthInfo = &cai; 
si.dwReserved2 = 0; 

qi.pIID = &IID_IMyComponent; 
qi.pItf = NULL;
qi.hr = 1; 

HRESULT hr = CoCreateInstanceEx(CLSID_MyComponent,NULL,CLSCTX_REMOTE_SERVER ,&si,1,&qi);

However, when I move the MFC test app to my other development machine and try and call the component on the other machine it fails. The hresult returned from CoCreateInstanceEx is -2147024891

I have already created the proxy stub DLL and registered it on both machines. Am I missing something else?

UPDATE: I now updated the COUTHINFO structure to the below and it works.

    COAUTHINFO cai = { RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, 0, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE,0, EOAC_NONE };
Jonnster
  • 3,094
  • 5
  • 33
  • 45

3 Answers3

2

The ERROR_ACCESS_DENIED is most likely due to the wrong parameters supplied with COAUTHINFO. You set Authentication, Authorization levels to NONE, which is not enough to get permissions to connect with remote machine. Try to set these values: RPC_C_AUTHN_DEFAULT (have COM negotiate the best authentication service), RPC_C_AUTHZ_NONE, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE. Also see the MSDN source - COAUTHINFO structure

SChepurin
  • 1,814
  • 25
  • 17
  • Yes my mistake. I just copied that line from an example. I have now read up on the COAUTHINFO structure and changed the line as shown in the edit to the original post. It now works. Thanks. – Jonnster Jul 04 '12 at 08:23
0

An HRESULT of -2147024891 (or 0x80070005 when converted to hex) is ERROR_ACCESS_DENIED. So it's a permission error when trying to connect to the remote machine.

shf301
  • 31,086
  • 2
  • 52
  • 86
  • I am logged in as the same user on both machines. However, the windows service is running as Local System on that machine. Is this the issue? – Jonnster Jul 03 '12 at 15:42
0

The error means E_ACCESS_DENIED. Make sure the current user has the rights to access the component. Run dcomcnfg (or "Component Services") on the server box, under "DCOM Config" find the right component, under "Security" change the permissions to allow both activation and access for the calling user.

Or make sure the calling user is an admin on the server box.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • I am logged in as the same domain user on both machines and I do have admin on both machines. – Jonnster Jul 03 '12 at 15:44
  • I can't find my component in DCOMCNFG. Should it be in there? – Jonnster Jul 03 '12 at 15:48
  • I found it in the DCOMCNFG and changed the settings for the specific domain user that is logged into both machines. It didn't make any difference. – Jonnster Jul 03 '12 at 16:01