Interface in COM

Embed Size (px)

Citation preview

  • 8/8/2019 Interface in COM

    1/18

    Presented by:

    Satyajit Deshmukh(S.Y.I.F.)

    Under Guidance:

    Prof. Sandeep Sukdhev

    Sir

  • 8/8/2019 Interface in COM

    2/18

    What is COM ?

    Component Object Model (COM) is a binary

    interface standard for software componentry

    introduced by Microsoft in 1993.

    It is used to enable interprocess communication

    and dynamic object creation in a large range of

    programming languages.

    Casting between different interfaces of an object

    is achieved through the QueryInterface() function.

  • 8/8/2019 Interface in COM

    3/18

    What is COM ?

    For some applications, COM has been replaced at least to

    some extent by the Microsoft .NET framework, and support

    for Web Services through the Windows Communication

    Foundation (WCF).

    COM objects can still be used with all .NET languages

    without problems.

    COM was originally designed for suitable development anddeployment of desktop applications.

    The preferred method of inheritance within COM is the

    creation of sub-objects to which method calls are delegated.

  • 8/8/2019 Interface in COM

    4/18

    Technical details

    COM programmers build their software using COM-aware

    components.

    Different component types are identified by class IDs,which

    are Globally Unique Identifiers.

    Each COM component exposes its functionality through one

    or more interfaces.

    COM interfaces have bindings in several languages, such

    as C, C++, Visual Basic, and several of the scripting

    languages. All access to components is done through the methods of

    the interfaces. This allows techniques such as inter-

    process, or even inter-computer programming

  • 8/8/2019 Interface in COM

    5/18

    What is Interface?

    An interface is a named table of function pointers (methods)

    An interface is not a class

    An interface is not a COM component

    COM clients only interact with pointers to interfaces

    COM components can implement multiple interfaces

  • 8/8/2019 Interface in COM

    6/18

    What is Interface?

    Interfaces are strongly typed

    Interfaces are immutable

    An interface consists of a pointer to a

    virtual function table

  • 8/8/2019 Interface in COM

    7/18

    Interface Definition Language

    IDL is a generic term for a language that lets a program or

    object written in one language communicate with another

    program written in an unknown language.

    An IDL file is what COM provides that allows developers to

    define object-oriented classes, interfaces, structures,

    enumerations and other user-defined types in a language

    independent manner.

    (IDL) is a standard language for defining function and method

    interfaces for distributed or component-based applications.

  • 8/8/2019 Interface in COM

    8/18

    IDL

    It is same as c/c++ in addition of keywords like Interface &

    library for defining interfaces and collections of classes,

    respectively.

    The IDL file is compiled by the MIDL compiler into a type

    library (.TLB file).

    In distributed object technology, it's important that new

    objects be able to be sent to any platform environment anddiscover how to run in that environment.

  • 8/8/2019 Interface in COM

    9/18

    Difference between declaration

    In IDL language

    Ex. a function used to

    calculate sales tax

    float calculate_tax ( in floattaxable_amount );

    In C/C++ language

    Ex. a function used to

    calculate sales tax

    interface order {float calculate_tax ([in] float

    taxable_amount);

    float calculate_total([in]

    item_list items);

    bool place_order([in,out]item_list items);

    }

  • 8/8/2019 Interface in COM

    10/18

    Why is it so ?

    Function declarations are collected into interfaces, which

    represent all the defined methods for a class.

    Once youve defined an interface, it can be used as a

    parameter type for function declarations and may be

    extended by other interfaces using the C extension

    operator (:).

    In my example, I assume youve also created an item_list

    interface, which you would use as the sole parameter of

    the calculate_total and place_order functions.

  • 8/8/2019 Interface in COM

    11/18

    COM Interfaces

    An interface is a named set of pure method prototypes.

    The interface name typically reflects the functionality of its

    methods and, by convention, begins with the capital letterI.

    Thus, IMalloc might represent an interface that allocates,

    frees,and manages memory.

    Similarly, ISem might be an interface that encapsulates the

    functionality of a semaphore.

  • 8/8/2019 Interface in COM

    12/18

    COM Interfaces

    As a developer, you typically define your own custom

    interfaces.

    the COM interface becomes a contractual agreementbetween client and server, and enables the communication

    protocol to function properly.

    The contract between client and server is to provide a

    service; but it is not a guarantee how that service isimplemented. The implementation details are hidden in the

    CoClass.

  • 8/8/2019 Interface in COM

    13/18

    Pointers in Interface & COM

    interface In the COM model, the communication protocol between

    COM clients and servers in handled using pointers to the

    COM interfaces.

    The interface pointers are used to pass data between COM

    clients and COM servers.

    An interface pointer is a 32-bit pointer to an object instancethat points, in turn, to the implementation of each method in

    the interface.

  • 8/8/2019 Interface in COM

    14/18

    Obtaining the first COM interface

    pointer

    All interaction with a remote COM server is done via its

    interface pointers and the most common way to obtain thefirst interface pointer is using the function create-instance.

    This takes the CLSID of the server and returns an interface

    pointer for the i-unknown interface unless another interface

    name is specified.

  • 8/8/2019 Interface in COM

    15/18

    How it works??

  • 8/8/2019 Interface in COM

    16/18

  • 8/8/2019 Interface in COM

    17/18

  • 8/8/2019 Interface in COM

    18/18

    All of you take tea I will go for ride