COM Objects and Interfaces Clause Samples

COM Objects and Interfaces. COM is based on objects. To clarify, in COM an object is some piece of compiled code, and is not to be confused with objects that are used in object-orientated programming. COM objects are well encapsulated. This means that you cannot get access to the internal implementation of the object. The only way to access an object is through an interface. The objects are contained by components. An interface is a description of a collection of methods and can be seen as a contract between a component and a client. The client can communicate with the COM objects only through an interface. It is important to realize that the interface does not contain any implementation at all. The functionality of the methods is implemented in a COM object. The interface is defined in a language called IDL (Interface Definition Language). It is important to observe that it is only a definition, the implementation of the methods can be made in any language. This IDL definition is what makes the standard binary. All COM objects and interfaces must have a unique identification number, GUID (Globally Unique Identifier). The GUID is a 128-bit number and its purpose is to make sure that there is only one interface in the world with this specific ID. To generate a GUID you can run either of the programs Guidgen.exe or Uuidgen.exe. For a COM object class the GUID is called CLSID (Class Identifier), and for an interface it is called IID (Interface Identifier). These IDs are stored in the Windows registry and are used by the client when it connects to the object. If a client would like to use one of the methods provided by an interface, it has to contact the server. The server, who contains the implementation of the methods, then constructs a COM object containing the methods of the interface. The client is then given an interface pointer to the object and can thereby access it. More than one client can access the same interface at the same time, if this is the case each client gets its own object. When the client does not want to use the object anymore, the object is released and the server removes it. COM Client COM object COM object rfaces COM Server/ Component Interface pointers