Component Object Modeling
Transcript of Component Object Modeling
-
8/2/2019 Component Object Modeling
1/20
3/22/2012 1
COMPONENT
OBJECT MODELING(COM)
-
8/2/2019 Component Object Modeling
2/20
23/22/2012
Binary standard for windows objects
Components made by different software vendorsto be combined into a variety of applications.
COM defines a standard for componentinteroperability
Programming language independent
Is available on multiple platforms,
Is extensible.
-
8/2/2019 Component Object Modeling
3/20
33/22/2012
COM provides mechanisms for the following:
Communications between components, evenacross process and network boundaries
Shared memory management betweencomponents
Error and status reporting
Dynamic loading of components
-
8/2/2019 Component Object Modeling
4/20
43/22/2012
COM Fundamentals
Binary Standard
COM defines a standard way to
Lay out virtual function tables (vtables) in memory
and a standard way to call functions through the
vtables.
Any language that can call functions viapointers all can be used to write components
that can interoperate with other componentswritten to the same binary standard.
-
8/2/2019 Component Object Modeling
5/20
53/22/2012
The double indirection
(the client holds a pointer to a pointer to avtable)
allows for vtable sharing among multipleinstances of the same object class.
On a system with hundreds of objectinstances,
vtable sharing can reduce memoryrequirements considerably.
-
8/2/2019 Component Object Modeling
6/20
63/22/2012
What This Means
-
8/2/2019 Component Object Modeling
7/20
73/22/2012
Versioning mechanism allows one system component to be updated
without requiring updates to all the other componentsin the system.
Versioning in COM is implemented using interfaces andIUnknown::QueryInterface
. COM completely eliminates the need for version
repositories
When a software module is updated, it is generally to add new functionality or to improve existing functionality.
In COM, you add new functionality to your component
object by adding support for new interfaces.
-
8/2/2019 Component Object Modeling
8/20
83/22/2012
Objects and components
In COM, an object is some piece of compiledcode
that provides some service to the rest of the system.
Component objects usually have someassociated data,
A given component object will never have directaccess to another component object in itsentirety.
-
8/2/2019 Component Object Modeling
9/20
93/22/2012
Architectural feature of COM
Component objects alwaysaccess othercomponent objects through interfacepointers.
It allows COM to completely preserveencapsulation of data and processing,
It also allows for transparent remoting(cross-process or cross-network calling)
-
8/2/2019 Component Object Modeling
10/20
103/22/2012
COM Interfaces
Object interact through interface COM Interfaces consists of group of
logically related,
well defined functions/methods That use known parameters and return types
An Interface consists only of
methods/functions There is no way to access the data with in
an interface
-
8/2/2019 Component Object Modeling
11/20
113/22/2012
An interface is not a class
A class can be instantiated to form acomponent object,
An interface cannot be instantiated by itselfbecause it carries no implementation.
A component object must implement thatinterface
Thus the basic principle of polymorphism fully
applies to component objects. .
-
8/2/2019 Component Object Modeling
12/20
123/22/2012
Clients only interact with pointers tointerfaces.
Component objects can implement multipleinterfaces.
Interfaces are strongly typed.
Every interface has its own interface identifier, aglobally unique ID (GUID)
-
8/2/2019 Component Object Modeling
13/20
133/22/2012
A typical picture of a component object
that supports three interfaces A, B, and C
-
8/2/2019 Component Object Modeling
14/20
143/22/2012
Interfaces extend toward the clients
connected to them.
-
8/2/2019 Component Object Modeling
15/20
153/22/2012
Each interface contains a list of methods that itexposes
In DLL these functions must physically resides in DLL
COM components must be logged in system registry
Client that use COM component must get a pointer to
an interface to access COM object
For COM object at least one interface IUnknown is
always implemented
-
8/2/2019 Component Object Modeling
16/20
163/22/2012
IUnknown
Base interface All other COM interfaces are derived from it
It contain three methods to
Allow you to get pointer to an objects interface
Manage the objects interface pointers
1. QueryInterface
2. AddRef3. Release.
-
8/2/2019 Component Object Modeling
17/20
173/22/2012
QueryInterface
Mechanism that allows clients to dynamicallydiscover (at run time)
whether or not an interface is supported by acomponent object;
If supported a pointer is returned
Mechanism that a client uses to get an interfacepointer from a component object
It takes an interface ID and returns a pointer tothat interface
-
8/2/2019 Component Object Modeling
18/20
183/22/2012
AddRef:
Increments count of number of clients using
the interface
Release
Called in place of delete operator
Decrements the count of number of clientsusing the interface
When count is zero The object knows that it is no longer
And remove itself from memory
-
8/2/2019 Component Object Modeling
19/20
193/22/2012
COM identifiers
COM object is accessed through use ofUUID/GUID
A GUID is a 128-bit value
Classification of GUIDs
IIDs (interface identifier)
COM defines IID for each interface
IID is used to manipulate interface
CLSIDs (Class identifiers)
Each class of COM object has it
CLSID is used when creating objects of given class
Unique CLSID for a COM class is stored in the WindowsRegistry
-
8/2/2019 Component Object Modeling
20/20
203/22/2012
Role of registry
Window registry stores the CLSIDs of allCOM classes available on the system
Use function CLSIDFromProgID() to find entry in registry
Get the CLSIDs for an object class
This function reads the registry andTranslates a string in to class ID number
Regedit.exe