Hi all,
I'd like to use an interface provided by a third-party COM component on my local computer. But I failed with CoCreateInstance. Here is the piece of the code:

IXXX *p;
GUID sourceobjID;
HRESULT hr = ::CLSIDFromProgID(L"the ProgID of the lib", &sourceobjID);
hr = CoCreateInstance(sourceobjID, NULL, CLSCTX_INPROC_SERVER, IID_IXXX, (void**)&p);

I've tried CoInitializeSecurity, it doesn't work;
And I've tried every kind of
CLSCTX to fill in CoCreateInstance, only CLSCTX_INPROC_SERVER gives me s result of E_ACCESSDENIED, others give me Class not registered.
I can see the type library in oleview. And my OS is XP with SP2. I'm running as administrator.

Could anyone help me to find out the problem Thanks!!


Re: Visual C++ General CoCreateInstance returns E_ACCESSDENIED on local machine

Ayman Shoukry - MSFT

For such issues, please use the win32 dev newsgroups at Folks there will be more familiar with such issues.


Ayman Shoukry
VC++ Team

Re: Visual C++ General CoCreateInstance returns E_ACCESSDENIED on local machine


you are obviously dealing with a dll. So you can directly call LoadLibrary to get the class factory and then use the class object to create an instance for you. this will let you see at which step CoCreateInstance failed.

all the following are possible:

- you don't have access to the dll (even if you are indeed part of an admin group).

- you don't have access to a dependent dll or something else (a network resource, for example)

- we have a custom class factory here and it returned a misleading error code. - find out the true problem.

hope this helps.

Re: Visual C++ General CoCreateInstance returns E_ACCESSDENIED on local machine


Thanks for your help. I used dumpbin.exe to check which interfaces can be exported from the dll. There came 4 results. The most useful one is DllGetClassObject. So I wrote a short piece of code trying to get an instance of the class then I can use it to access the interface. Unfortunally, I failed at the call of DllGetClassObject. I got the 'E_ACCESSDENIED' error again at the call line. So I guess there must be some privilege things prevent me from doing this. I am running as the administrator, the only member in the admin group. How can I grant myself enough rights to access the dll, as well as it's dependencies Is there possible to add some security limitations in the dll to prevent third-party users from using it

For your refenrence, I list my new piece of code here:
typedef HRESULT (__stdcall* MYFUNC)(REFCLSID, REFIID, VOID**);
HMODULE handle = LoadLibrary(L"xxxx.dll");
MYFUNC a = (MYFUNC)GetProcAddress(handle, "DllGetClassObject");
GUID sourceobjID;
HRESULT hr = ::CLSIDFromProgID(L"ProgID of the dll", &sourceobjID);
IClassFactory *p = NULL;
hr = (a)(sourceobjID, IID_IClassFactory, (void**)&p); //failed here, hr == E_ACCESSDENIED