Upload
shashank-sood
View
232
Download
0
Embed Size (px)
Citation preview
8/4/2019 COM Ppt Final
1/31
COM
8/4/2019 COM Ppt Final
2/31
WHAT IS COM
COM stands for Component Object Model. It is aMicrosoft specification that describes how to createreusable objects for programmers working in aWin32 programming environment. This makes it
easy to develop objects that can be distributedindependently of an application program file.
In earlier versions of VB or other windowsprogramming environment, the COM under other
names such as OLE Server or Activex Server.
8/4/2019 COM Ppt Final
3/31
COMPONENT AND OBJECT
It is an independent piece of code that may beshared with several different programs.
Object is a set of code that is designed to bereusable with a well defined interface.
COM is based on Client-Server Model ,each COM
object operates s a Server that receives andprocesses requests from a client program andgenerates responses
8/4/2019 COM Ppt Final
4/31
Requests
CLIENT PROGRAMCONTAINER
COM Object(Control)
Response
8/4/2019 COM Ppt Final
5/31
COM OBJECTCANINTERACT WITH CLIENT
PROGRAM
IN
THREE
WAYS
:
PROPERTY:
A Property represents variable in your objects,
although its often implemented as a pair ofroutines: One to retrieve the value form the propertyand another to assign a value to the property.
8/4/2019 COM Ppt Final
6/31
METHOD AND EVENT
Method is merely a function or subroutine that canbe called from a client program.
An event is a subroutine whose parameters aredefined in the control and that exists in the clientprogram. It is called by the control to informprograms of various situations.
8/4/2019 COM Ppt Final
7/31
NECESSICITY OF COM
Components and Objects are used to develop anapplication. Since many languages have the abilityto include objects in source code, why should youuse COM?
COM is the foundation of most things that Microsoftdoes. Without COM ,Visual Basic wouldnt work,
nor would Windows, SQL Server, or any numberof Microsoft products. The true test of Microsofts
confidence in COM is that its applications arebased on COM technology. Word 2000 and Excel2000 are based heavily on COM, as are many otherMicrosoft applications.
8/4/2019 COM Ppt Final
8/31
When you build multiple program using objects, theobjects are compiled into the object code. This hasa couple of disadvantages:
If you have multiple programs, each executableprogram has its own copy of the objects. Thismeans that any time you change the objects, youmust recompile all of the programs that use them.
You must use the same programming language that
the objects were written in to create yourapplication programs. This restricts your choice ofprogramming languages
8/4/2019 COM Ppt Final
9/31
Since COM Objects are stored in their ownindependent object file, you can change the objectwithout recompiling the applications that use it. Youcan also add new interface to the COM objects to
offer new features and capabilities.
8/4/2019 COM Ppt Final
10/31
FROM DDE TO COM
Many of the features we see in todays COM
technology go back many years. COM draws itsroots from a number of different technologyincluding DDE (Dynamic Data Exchange), Object
Linking Embedding.(OLE).
8/4/2019 COM Ppt Final
11/31
DDE:
In early days of Windows , people used a clipboardmuch like they do today. Users could copy parts ofa document in program on to the clipboard andpaste them into a document in another program.
However, when dealing with complex graphicaldocuments, users found that a simple clipboarddidnt work very well.
In late 1980s Microsoft developed a technology
called DDE to allow programmers to simplify the
process of sharing the data using a clipboard. Thistechnology was available for only Microsoftapplications, so it was not universal solution.
8/4/2019 COM Ppt Final
12/31
OLE:
In 1991 Microsoft created a more general solutionto this problem called OLE . This technologyallowed users to combine documents from multipleapplications into a single compound document
developers could build the best possible wordprocessor without worrying about adding a limitedfunction spread sheet. For example, we can embedexcel worksheet into word document. The word
document is acting as a container for excelworksheet. This is really the foundation of OLE.
8/4/2019 COM Ppt Final
13/31
While working on OLE the Microsoft engineersrecognized that the issue of creating compounddocuments was really a special case of determining howtwo or more system or application componentscommunicate with each other. In the past a number of
different techniques were employed. Some times simplesubroutine calls were used. Other times more complexmessaging systems was used. Programmers were oftenrequired to use several different techniques forcommunication among components.
While implementing OLE Microsoft employed a numberof new technologies; for most among them was COM.
8/4/2019 COM Ppt Final
14/31
COM:
COM creates a layer of abstraction betweensoftware components . Each COM object isdesigned to operate as a server to a clientapplication or another software module. The COMobject is an instance of a specific class that definesone or more interfaces to the functions it provides.Each interface contains one or more methods toperform specific functions.
With COM, doesnt matter if the component is
implemented as a simple set of subroutines as anindependent process that communicates with theapplication using complex synchronizationtechniques.
8/4/2019 COM Ppt Final
15/31
Although COM determines how two components
communicate with one another, OLE requires anumber of other standard methods in addition tothose required by COM. These includes thecapability for the object to present its own user
interface, send events to the controllers containersand lets a container sets the properties of thecontrol.
8/4/2019 COM Ppt Final
16/31
SERVICES PROVIDED BY COM
The Services provided by COM are summarizedbelow:
OBJECT MANAGEMENT:
COM provides object management a service byusing reference counting. With reference counting,
COM enables developers to control when objectreferences and their objects are released frommemory.
8/4/2019 COM Ppt Final
17/31
OBJECT PERSISTANCE:
COM provides object persistence services that
allow objects to be stored in a file. This isparticularly important when you wish to extract anapplication specific object from a document file.
8/4/2019 COM Ppt Final
18/31
STRUCTURED STORAGE:
When objects are stored in files, they are stored
using the structured storage services provided inCOM. With structured storage we can store data ina hierarchical format within a file very much as filesare stored in directories and sub directories.Structured storage allows applications to read and
save items to files with out restricting the lay out ofthe file .
8/4/2019 COM Ppt Final
19/31
DATA TRANSFER:
COM provides DATA TRANSFER, a service that
enable you to transfer and share data betweenapplications.
NAMING AND BINDING SERVICES:
With Naming and Binding services, applicationcreate, store and manage objects that providecomplex operations such as downloading of files.These services are usually not directly accessed bythe programmers however you will use theseservices via objects and functions that a classprovides
8/4/2019 COM Ppt Final
20/31
WHATS INSIDE A COM OBJECT
COM objects communicate to the world through aseries of interfaces. Standard interfaces aregenerally used to access information about theCOM objects. These interfaces include or perform
various COM related tasks. Custom interfaces arethose interfaces designed by the user as COMobjects.
8/4/2019 COM Ppt Final
21/31
The interfaces implemented in one of two basicways:
IN-PROCESS OBJECT SERVERS:
It run in the same address space as the clientprocess. Using them dose not add much moreoverhead to your application than calling a functionor subroutine.It is loaded from a regular DLL file,which contain a set of standardized function and
tables that you load and use COM objectdynamically.
8/4/2019 COM Ppt Final
22/31
FINDING AND LOADING IN-PROCESS COM
OBJECTS:
When an object in the COM library is accessed forthe first time, the COM library is loaded into your
address space, just like any other DLL. However,unlike DLL files, which require Windows to searchin a number of places to find the files, COM objectsare quickly located by using a GUID.
8/4/2019 COM Ppt Final
23/31
A GUID(Globally Unique Identifier) is a 128 bitnumber i.e. unique, not just in a specific computer,but in the entire world. The same people thatdeveloped the Distributed Computing Environment
derive this value from complex algorithm desined.The GUID generator uses your system clock andthe MAC address from your network interface cardto create a value that is guaranteed to be unique on
your system. If your computer does not have anetwork interface card, the GUID will be createdfrom a value based on your hard disk space andthe total time since the computer was booted.
8/4/2019 COM Ppt Final
24/31
OUT OF PROCESS OBJECT SERVERS:
It run in a different address space. They come intwo different flavors: Local and remote. Using theseobjects is more expensive in terms of overhead;however, in long run, they may actually help yourapplication to run faster. While your program callsthem like a function or a subroutine, a lot of workneeds to be done to marshal your request to
another process, wait for results, and then marshalsthe results in the same fashion as an IN-PROCESSCOM object.
8/4/2019 COM Ppt Final
25/31
FINDING AND LOADING OUTOF- PROCESS
COM OBJECTS:
Finding out-of-process objects is similar to locatinginprocess objects. The calling program supplies theobjects CLSID, which is used to find information
about the object in the windows registry.
8/4/2019 COM Ppt Final
26/31
RUNNING OUT OF PROCESS COM OBJECTS
REMOTELY:
If your computer is attached to a network, windowsincludes the capability to run your object on anothermachine. The same interface that your programsees with a local out-of-process COM object still
exist , but now they direct your request to anothercomputer where the objects exist.
To direct your COM calls to another computer, COMuses a proxy component that intercepts your calls
to methods and properties and passes them on tothe remote computer using Remote ProcedureCalls (RPC).
8/4/2019 COM Ppt Final
27/31
INTERFACES
An interface is a contact between a COM serverand a COM client. It specifies the methods,properties, and events that are used tocommunicate between the client and the server.
This is perhaps the most important part of the COMobject, because the interface isolates the internalworking of the COM object from how it is used bythe client.
Every COM object presents at least two interfaces
to the outside world. In most cases, more than twowill be present because a number of interfaces arededicated by the COM architecture.
CC SS G O O O G
8/4/2019 COM Ppt Final
28/31
ACCESSING INFORMATION THROUGH AN
INTERFACE:
An interface is a binary specification that allows youto locate a particular variable or function in the codemodule. This information stored in data structurecalled a virtual method table. A VMT is an array of
function pointers, where each pointer points to aparticular method or property contained in theobject.
Each function pointed to by the VTM contains
not only the address of the function, but additionalinformation, such as the name of the function, thedata type it will return, and the name and data typefor each of its parameters.
8/4/2019 COM Ppt Final
29/31
BINDING TO AN INTERFACE:
In order to use a COM object, you must find andload the library containing the object. Then youmust create a link between the object variable youplan to use and the desired interface. This process
is known as binding. There are two basic types of binding: early and
late.
In late binding, visual basic is unable to determinethe type of the object your are using.
With early binding, you must declare your objectvariable with a specific object type with thisinformation visual basic is able to bind your variableto the object at designed time.
8/4/2019 COM Ppt Final
30/31
COM Object
COM Proxy
Applicationprogram
COM Proxy
8/4/2019 COM Ppt Final
31/31
THANK YOU