The Component Object Model

The Component Object Model is a specification that describes the process of communicating through interfaces, acquiring access to various interfaces through the QueryInterface member function, determining pointer lifetime through reference counting, and reusing objects by extending them. An object, in this context, is an item in the system that exposes interfaces (groups of related functions) to manipulate the data or properties of the object. It is created directly or indirectly by calling the CoCreateInstance function, which creates a new instance of the object and returns a pointer to an interface for the object.

When two objects within the system want to communicate with each other, one object calls member functions in the other object's interface by using a pointer to the interface. The call to CoCreateInstance returns this interface pointer. For instance, two objects might want to communicate with each other during a drag-and-drop operation. If one object is to be dropped on another object, the first one calls into the other's interface to request acceptance of the drop.

All interfaces used in the Component Object Model—including IShellLink, the one used to manipulate shortcuts—are derived from the base interface, IUnknown. All interfaces support three base member functions:

An application that manipulates shortcuts must initialize the component object library with a call to CoInitialize or OleInitialize. When I created the SHORTCUT sample, I put this call in my InitInstance handler before calling any other functions. Each call to CoInitialize must be balanced with a call to CoUninitialize. CoUninitialize should be called when an application shuts down, because it ensures that the application won't quit until it has received all its pending messages. I normally put the call to CoUninitialize in the ExitInstance handler.