OOPortal OOPortal

Basic COM  «Prev  Next»
Lesson 6 COM interface properties
Objective List the binary layout requirements of a COM interface.


A COM interface contains a group of related COM methods. COM interfaces have the following properties. The runtime binary layout of a COM interface contains vtable. A vtable is a table of pointers to interface methods.
A COM interface pointer is a pointer to a vtable.
Methods in a vtable are accessed by table position, not by method name. The placement of functions in a vtable is called vtable order.
Characteristics of a vtable


Besides providing application-specific functionality, a COM interface must also provide methods to support interface navigation and lifetime management. These methods are QueryInterface, AddRef, and Release. Collectively, these three methods are called IUnknown. The first three pointers in every vtable associated with a COM interface must point to the IUnknown methods (i.e. QueryInterface, AddRef, and Release) in order.


COM does not support implementation inheritance. Unlike C++, in COM there is no way to inherit member functions and member variables from a base class. However, the standard convention used in COM is to say, "All COM interfaces inherit from IUnknown." What we really mean is that all COM interfaces implement the methods of IUnknown in vtable order, i.e., QueryInterface, AddRef, and Release are the first three functions in every COM interface.

C++ and virtual member functions

C++ is the language of choice for developing COM applications. One of the reasons for this is that C++ compilers place virtual member functions of a class into a vtable.
Recall from the previous lesson that the first parameter to a COM interface method must be a pointer back to the interface that contains it. C++ provides automatic support for this requirement by passing in the this pointer as an implicit first parameter.


COM interfaces are identified by a unique ID called an IID. An IID (interface ID) is a 128-bit number. IIDs are named after the interface they identify. For example, IUnknown has a predefined IID called IID_IUnknown. IIDs are also called GUIDs or UUIDs.

Defining Com Interface - Exercise

Click the Exercise link below to apply what you have learned about COM interface requirements.
Defining Com Interface - Exercise