What is the difference between CoCreateInstance () and CoGetClassObject () when creating objects on the same computer?

I understand that CoCreateInstance finds a COM server for a given class identifier, instantiates an object for this identifier, and extracts the interface from this object instance. CoGetClassObject () finds the COM server for the class identifier, creates an instance of the factory class for this class identifier, and retrieves this factory class interface, which can then be used to create real objects.

How else do these functions differ when used to create objects on the same computer? Do they work the same but call different code that gets called on the exact same COM server?

+5
source share
2 answers

CoGetClassObject essentially returns you a factory pointer for a specific interface. Under the hood, CoCreateInstance uses CoGetClassObject. The advantage of calling CoGetClassObject is that it only allows you to create the factory class once if you want to create many instances of a specific object.

The MSDN section on CoGetClassObject has a brief discussion on how you can take advantage of this functionality.

+8
source

, JaredPar - CoGetClassObject factory ( DLLGetClassObject DLL inproc). factory . CoCreateInstance CoGetClassObject, factory, . CoCreateInstance . , coclass , , factory, .

+1

All Articles