In COM, when you want to create an instance of some COM Server object, do you first need to get a pointer to it’s IUnknown interface and only then create a class object using CoGetClassObject?
As far as I understand it, IUnknown is used to manage object lifetimes, so from my understanding, whatever object the client wants to create, one needs a pointer to it’s IUnknown interface implementation first.
Sound correct? If not, can anyone tell me how it works?
IUnknownmanages the lifespan of an existing COM object. Before the object is created, there is noIUnknownpointer to speak of.CoGetClassObjectis used to get theIUnknowninterface for an object that is expected to create the objects of interest. I.e., it is an object factory, an usually implementsIClassFactory, which declares theCreateInstancemethod that you use to create objects.Instead of using class factories explicitly, it is often simpler to just call
CoCreateInstance.