Co Create Instance

It's COMs version of new!

(COM = MicroSoft's ComponentObjectModel.)

Well it's complicated but in a nutshell: COM/COM+ call to instantiate a COM object regardless of it's location and bring it to life, returning an Interface Pointer to it.

What it does: Given a class id (a GUID) and an interface ID (another GUID), it finds and loads the appropriate component's code, finds the ClassFactory for the class ID, and asks it to create an instance of that class, and return the requested interface. You can ask for the IUnknown interface, supported by all COM objects, but it's more efficient, especially on remote calls, to ask for the interface you really need.

If you're going to create many instances of a given class, it makes sense to do the work yourself:

If you want to "pass parameters" to your COM object constructor -- the moral equivalent of "new ClassName(parameters)" -- define a non-standard factory interface with an IYourCustomClassFactory::CreateInstance?(your-parameters)" signature. Clients will have to use CoGetClassObject? to create your instances -- which will be a problem for VisualBasic and scripting languages.

See CoCreateInstanceEx? if you want better control of where the object will be created -- local or remote, or if you need to create *LOTS* of instances on a remote (network) server.


Often abbreviated (I wonder why) to CCI. See ComAbbreviations.


EditText of this page (last edited April 19, 2001) or FindPage with title or text search