Vous êtes sur la page 1sur 13

Component Object Model

Requirement the code written in one


language should be reused in the
applications developed using other
language.
Solution is COM
COM  it is a specification or a set of
rules provided such that language
interop can be achieved.
Note in order to specify a code as a
component it is manditory that the
class definitions has to inherits
IUNKNOWN interface.
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 value by 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 then Release Method is
used to release the reference counter
information.
Note  if the reference counter value is equal
COM Types
Com is of 2 types
In Process COM [.dll] 
Operating System

Com Server

Application In Process COM

PMA
The processing of the
component
will be done here
IN Process COM
When ever a COM type application uses the
definitions of the inprocess COM then a
request will be given to the COM server where
the component will be identified based on its
GUID and processing of the component will
take place at the PMA [ Private Memory Area ]
of the OS and the request will be given back to
the application.
Advantages  The performance of the
application will be very fast.
Limitations  Always a IN process component
depends on a application the Component cant
be used independently.
As the processing of the component will be
OUT Process COM
Operating System

COM Server

Application OUT Process COM


.exe

Memory Block PMA


OUT Process COM (.exe)
When ever a application uses the OUT process
component then a request will be given to the
COM server where COM is identified and the
processing of the Component will be
performed at a individual memory block and
the response will be given to the application
with the support of PMA.
Advantages  OUT process components can
be used within an application or it can be used
independently.
The resources of the O/S is not blocked.
Disadvantages  the application which uses
the OUT process components will be slow
when compared to the applications which uses
Problem when COM component is used
within the .net applications
Operating System

COM Server

.Net Application
COM Component

A dot net application cant send a request directly to the COM Component or it
cant send a request to the COM Server
Solution to use COM in dot net applications
The environment in which .net applications will be processed is
managed environment.
The environment in which COM components will be processed is
UnManaged
unmanaged Env
environment. Managed Env
COMMON LANGUAGE RUNTIME
COM Marshalling
COM Server
Runtime Callable Wrapper

COM Component
Un Managed Code

.Net Application

.Net Interop COM

Managed Code
When ever the dot net application uses
the definitions of the COM Component a
request will be given to the CLR which
uses the COM marshalling resource and
identifies the application uses the
definition of the COM Component and it
defines a Runtime Callable Wrapper
which sends a request to the Com
Server where the Component is
identified based on its GUID and the
definitions of the COM component will
be returned to the RCW and based on
that definitions a relevant .net interop
Microsoft CDO for NTS 1.2 library
[COM Component ]
CDONTS { Collabarative Data objects
for new Tech. Service }
Usage  used to send / receive Mails
Properties 
From,To,Subject,Cc,Bcc,BodyFormat,Mai
lFormat,Body
See example.
COM using dot net

UnManaged Env
Managed Env

COM Server COMMON LANGUAGE RUNTIME

COM Callable Wrapper


IUNKNOWN

Interop Com IDISPATCH

CLASS DEF

.Net assembly
[Class Defn’s]
Com Type App
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 the CLR 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 application uses the
definitions of the Dot net assembly as if
it is using a Com Component only.
Steps to define a .net assembly to be used
only by the COM type application
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 be considered as a project
name.
Step 2: open the solution explorer and select
class1.cs file right click on it and click on d

Vous aimerez peut-être aussi