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?
-
The problem here is that you are confusing the class object and the object itself.
CoGetClassObjectwill give you a pointer to an object that implementsIClassFactoryand 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
IUnknownpointer by callingQueryInterfaceon theIClassFactorypointer. This pointer still points to the instance of the class object, hence doingQueryInterfacefor the interface you are interested in results in an error. Instead you need to callIClassFactory::Createinstanceto get theIUnknownpointer to the actual object and do theQueryInterfaceon that pointer.Aaron : Thanks - but now: "This connectable object does not support the outgoing interface specified"Franci Penov : If you post sample code what you are trying to do, we might be able to help. -
Also, take a look at CoCreateInstance function.
0 comments:
Post a Comment