Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Life cycle of Component Object Model (COM) Object

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Component Object Model (COM) object life-cycle process is technique of useful resource upkeep and component interplay carried out by means of Component Object Model (COM). COM is typical software structure developed by way of Microsoft that offers framework for integrating software program components.

This framework permits developers to construct structures with aid of assembling reusable components. By defining Application programming interface (API), COM approves introduction and integration of factors in customized purposes or approves various factors to interact. Interplay is viable solely if elements adhere to binary structure targeted by means of Microsoft. Components written in exclusive programming languages can interoperate if they adhere to this binary structure.

Life-cycle technique of COM starts off-evolved when client requests to create and use object of COM. Following steps are concerned in COM object life cycle :

  1. Client request :
    COM client request is first segment of object creation. Here, COM client is each and every utility that invokes COM API to instantiate new COM object. It then passes unique CLSID or class id to COM and in return asks for instantiated object. COM client is accountable for two particular tasks, which have to be included at starting of this segment if they did no longer accomplish in application startup :

    • COM client needs to affirm that COM Library model is new adequate to support performance predicted by means of application. In general, application can use up to date version of library, however no longer older one.
    • COM client has to initialize COM Library.
      Client of COM object continually asks COM to instantiate objects in precisely identical manner and doesn’t depend on kind of server in use i.e., it may be in-process server, local server, or any other. Talking about methods so there are two types of methods, which client makes use of to make request. Easiest approach is to call COM function CoCreateInstance. In response to this, there is creation of one object of given Class id and it returns interface pointer of any requested type.

      There is alternate option for same, i.e by calling CoGetClassObject, client can achieve and get interface pointer, which is called class factory object for CLass ID. This class factory helps interface referred to as IclassFactory via which consumer asks factory to manufacture object of its class.

  2. Server location :
    Subsequent step concerned in COM object life-cycle is Server location.
    process. In this step, COM locates object implementation and initiates server system for object. A unique element referred to as Service Control Manager or SCM which is accountable for location and execution of COM server that implements COM object. SCM ensures that when client request is made, suitable server is linked and geared up to acquire request. SCM stores all class records in system registry, beneath unique textual content key named with object’s class ID.

    For example, Service Control Manager supports file storage and stores file pathnames of COM servers, which helps for their localization and easily once can find about its location. COM client obtains these records via COM library.

    The actions, taken by means of SCM, rely on kind of COM server :

    • In-Process –
      In this process, file path of DLL containing th object server implementation is provided by SCM. Then library of COM is responsible for loading DLL and further asks it for its interface pointer of it’ class factory.

    • Local –
      In this process, SCM further finds and begins local execution, which registers interface pointer of class factory.

    • Remote –
      At last, in this process, local SCM then contacts SCM running on appropriate remote pc, and forwards request to far off SCM. Then further remote SCM obtains interface pointer of class factory in one of two ways described above processes.

      Its function of remote SCM to keep connection to that class factory and return RPC connection to local SCM.

  3. Object creation :
    In life cycle of COM object, third phase which is referred to as Object Creation, creates object by means of giving class ID. It includes three inside steps :

    • Obtain class factory for CLSID.
    • Ask class factory to instantiate object of class, and return interface pointer to COM client.
    • Initialize COM object.
  4. Interaction :
    When object is initialized, then fourth phase begins for this process, which is referred to as Interaction. During this phase, client can interact with newly instantiated COM object with help of interface pointers.

    Creation phase is responsible for giving client single interface pointer having limited scope of using functionality. If COM client requires at any particular time to perform operation outside that scope, then to do so it needs to call interface function QueryInterface so as to ask for another interface on same object.

  5. Disconnection :
    The closing process phase is Disconnection that takes place when COM client no longer desires COM object. The groundwork of this step is Reference Counting mechanism. This mechanism offers COM object functionality to manipulate its very own lifetime. Hence, as alternative to releasing object directly, COM client needs to inform object to free itself.

    COM specifies Reference Counting mechanism to furnish this control. Each object keeps 32-bit reference rely upon that tracks how many clients are linked to it. The use of 32-bit counter, which can handle up to more than 4 billion clients, capacity that there is certainly no threat of overloading count.

    There are 2 interface functions, AddRef and Release, control count which belongs base COM interface IUnknown. AddRef function is to increment count and Release functions are to decrements count. When reference decremented to zero, then it means that all clients who are using COM objects and are who were associated with it are now disconnected, and COM object can ruin itself, i.e., self-destruction of object takes place.

My Personal Notes arrow_drop_up
Last Updated : 27 Jul, 2020
Like Article
Save Article
Similar Reads