What is COM (Component Object Model)?
As defined by Microsoft, the Component Object Model (COM) is an object-based software architecture that allows applications to be built from binary software components. COM is the foundation for various Microsoft technologies including OLE, ActiveX, Distributed COM (DCOM), COM+, and Microsoft Transaction Server (MTS).
COM is not a programming language, rather it is a specification. The goal of COM is to allow applications to be built using components. These COM components can be created by different vendors, at different times, and using different programming languages. Also, the COM components can run on different machines or different operating systems.
The following concepts are fundamental to the way COM works:
COM Interfaces: A group of related functions implemented by the COM class. COM interfaces are the mechanisms by which COM objects expose their functionality to applications and other components. An interface is a table of pointers to functions that are implemented by the object. The table represents the interface, and the functions to which the table points represent the methods of that interface. COM objects can expose multiple interfaces. Each interface has its own unique interface ID (IID).
IUnknown: This is the basic COM interface on which all other interfaces are based; it provides reference counting and interface querying mechanisms. IUnknown allows navigation to all other interfaces exposed by the object.
Reference counting: This is a mechanism by which an interface determines it is no longer being used and is therefore free to remove itself. IUnknown uses the methods AddRef and Release to implement reference counting.
QueryInterface: This is the IUnknown method used to query an object for a given interface.
Aggregation: This is a technique by which one object can make use of another.
Marshaling: This mechanism lets objects be used across thread, process, and network boundaries, thus providing location independence.