views:

494

answers:

2

Note:

  • Using CoGetClassObject, to create multiple objects through a class object for which there is a CLSID in the system registry

  • Single threaded apartment

For instance:

hresult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

IClassFactory *pIClassFactory;

hresult = CoGetClassObject (clsid, CLSCTX_LOCAL_SERVER, NULL, IID_IClassFactory, (LPVOID *)&pIClassFactory);


hresult = pIClassFactory->QueryInterface (IID_IUnknown, (LPVOID *)&pUnk);


hresult = pUnk->QueryInterface (__uuidof(IExample), (LPVOID *)&pISimClass);

Note:

  • E_NOINTERFACE is returned
    • *ppvObject is set to NULL

Question:

  • How can I confirm, that it is indeed registered - if this is the problem?
+3  A: 

The problem here is that you are confusing the class object and the object itself. CoGetClassObject will give you a pointer to an object that implements IClassFactory and intended to create an instance of the object you are interested in. It is not an actual instance of that object.

In your example, you are getting an IUnknown pointer by calling QueryInterface on the IClassFactory pointer. This pointer still points to the instance of the class object, hence doing QueryInterface for the interface you are interested in results in an error. Instead you need to call IClassFactory::Createinstance to get the IUnknown pointer to the actual object and do the QueryInterface on that pointer.

Franci Penov
Thanks - but now: "This connectable object does not support the outgoing interface specified"
Aaron
If you post sample code what you are trying to do, we might be able to help.
Franci Penov
A: 

Also, take a look at CoCreateInstance function.

Nemanja Trifunovic