6787442 Component Object Model

download 6787442 Component Object Model

of 13

Transcript of 6787442 Component Object Model

  • 8/8/2019 6787442 Component Object Model

    1/13

    Component Object ModelRequirement the code written in one languageshould be reused in the applications developedusing other language.

    Solution is COM

    COM it is a specification or a set of rules providedsuch that language interop can be achieved.

    Note in order to specify a code as a component itis manditory that the class definitions has toinherits IUNKNOWN interface.

  • 8/8/2019 6787442 Component Object Model

    2/13

    Methods in IUNKNOWN interface

    QueryInterface it is used to maintain the address of all the

    member functions defined in the class definitions in a

    VARRAY table structure.

    AddRef It is used to increment the reference counter valueby 1 when ever the application uses the definitions of the

    form component.

    Release when ever the application which uses the COM

    component definitions is closed in a normal procedure thenRelease Method is used to release the reference counter

    information.

    Note if the reference counter value is equal to zero then

    the resources occupied by the COM component will be

    released.

  • 8/8/2019 6787442 Component Object Model

    3/13

    COM TypesCom is of 2 types

    In Process COM [.dll]

    Application

    Com Server

    In Process COM

    PMAThe processing of the component

    will be done here

    Operating System

  • 8/8/2019 6787442 Component Object Model

    4/13

    IN Process COMWhen ever a COM type application uses the definitions ofthe inprocess COM then a request will be given to the COMserver where the component will be identified based on its

    GUID and processing of the component will take place at thePMA [ Private Memory Area ] of the OS and the request willbe given back to the application.

    Advantages The performance of the application will bevery fast.

    Limitations Always a IN process component depends on aapplication the Component cant be used independently.

    As the processing of the component will be performed at thePMA of the operating system the resources of the OS will beblocked.

  • 8/8/2019 6787442 Component Object Model

    5/13

    OUT Process COM

    Application

    Memory Block

    COM Server

    OUT Process COM.exe

    PMA

    Operating System

  • 8/8/2019 6787442 Component Object Model

    6/13

    OUT Process COM (.exe)When ever a application uses the OUT process componentthen a request will be given to the COM server where COM isidentified and the processing of the Component will be

    performed at a individual memory block and the responsewill be given to the application with the support of PMA.

    Advantages OUT process components can be used withinan application or it can be used independently.

    The resources of the O/S is not blocked.

    Disadvantages the application which uses the OUTprocess components will be slow when compared to theapplications which uses the in process components.

  • 8/8/2019 6787442 Component Object Model

    7/13

    Problem when COM component is used

    within the .net applications

    .Net Application

    COM Server

    COM Component

    Operating System

    A dot net application cant send a request directly to the COM Component or itcant send a request to the COM Server

  • 8/8/2019 6787442 Component Object Model

    8/13

    Solution to use COM in dot net applicationsThe environment in which .net applications will be processed is managed

    environment.The environment in which COM components will be processed is unmanaged

    environment.UnManaged Env Managed Env

    COM Server

    COM Component

    .NetApplication

    .Net Interop COM

    COMMON LANGUAGE RUNTIME

    COM Marshalling

    Runtime Callable Wrapper

    Managed Code

    Un Managed Code

  • 8/8/2019 6787442 Component Object Model

    9/13

    When ever the dot net application uses thedefinitions of the COM Component a request will begiven to the CLR which uses the COM marshalling

    resource and identifies the application uses thedefinition of the COM Component and it defines aRuntime Callable Wrapper which sends a request tothe Com Server where the Component is identified

    based on its GUID and the definitions of the COMcomponent will be returned to the RCW and basedon that definitions a relevant .net interop COM willbe defined which will be used by the applications.

  • 8/8/2019 6787442 Component Object Model

    10/13

    Microsoft CDO for NTS1.2 library

    [COM Component ]CDONTS { Collabarative Data objects for new Tech.

    Service }

    Usage

    used to send / receive MailsProperties

    From,To,Subject,Cc,Bcc,BodyFormat,MailFormat,B

    ody

    See example.

  • 8/8/2019 6787442 Component Object Model

    11/13

    COM using dot net

    UnManaged Env

    Managed Env

    COM Server

    .Net assembly

    [Class Defns]

    COMMON LANGUAGE RUNTIME

    COM Callable Wrapper

    Interop Com

    IUNKNOWN

    IDISPATCH

    CLASS DEF

    Com TypeApp

  • 8/8/2019 6787442 Component Object Model

    12/13

    When ever a COM type application uses the

    definitions of the .net assembly then a request will

    be given to the CLR from the COM Server where theCLR uses its COM collable Wrapper [CCW] resource

    to identify the .net assembly and to define the

    relevant interrop COM which will be registered in

    the COM Server and then the COM Type applicationuses the definitions of the Dot net assembly as if it

    is using a Com Component only.

  • 8/8/2019 6787442 Component Object Model

    13/13

    Step 1:Select class library template.

    The main of the application if used in the .net

    environment will be considered as a name space and

    if used from the COM type application it will beconsidered as a project name.

    Step 2: open the solution explorer and select

    class1.cs file right click on it and click on d

    Steps to define a .net assembly to be used

    only by the COM type application