You are on page 1of 62

CST-201

Component Programming

COM / DCOM

T. V. Prasad
Assistant Director (IT Services)
Bureau of Indian Standards
In this presentation….

• Part 1 – Introduction
• Part 2 – The Component Object
Model (COM) Technology
• Part 3 – Distributed COM (DCOM)
• Part 4 – Microsoft Component Services
Part 1

Introduction
The COM Technology

COM is a proprietary technology of


Microsoft Corporation
introduced in 1993 and
built around Windows platform.
COM is a Windows standard that
defines how components must
be created, modified and loaded
into memory and finally, shared

Microsoft
COM
COM is a standard for communicating
between objects. The basic idea is to
have a standard that says objects will
accept and send messages in a
particular way, thus enabling objects
written in disparate languages to
communicate with each other as if they
were written in the same language
Genesis of COM and
change in technologies
• Disk Operating System (DOS)
• Object Embedding & Linking (OLE)
• Conventional GUI based OS, e.g, Windows
• Dynamic Data Exchange (DDE)
• Object Oriented Programming (OOP)
• Component Object Model (COM)
• Distributed COM (DCOM)
• COM+
Merits of COM
• Automatic transactions
• Configurable security
• Automatic thread support (many users at a time)
• Support for multiple databases and resource
managers
• Database connection pooling
• Component state management (easy versioning)
• Process isolation through packages
• Integration with main-frame transactions
• A broad range of development tools
Demerits of COM/DCOM
• Programmers need to change their thinking and
methodology from being property-oriented to
service-oriented
• Installation of DCOM components is more
involved since it has to be made sure that client
knows about the services offered by server-side
components and their location
• Components located over network can be slow
due to network traffic
• Security could be concerning while deploying
components
• Error handling could be cumbersome since error
has to be sent to the client
Applications of COM/DCOM
Manufacturing, Hospital, Airline,
Railways, Commerce, Banking
Industry, Telecom, Transportation,
Tourism, Education, Science &
Research, Government, Space,
Defence, Law & Order
– and many more in everyday life
Software Tools for COM

• Basic and Visual Basic


• Visual FoxPro
• C, C++ and Visual C++
• Small Talk
• Ada
• Visual J++
Example of COM
Some COM objects are visual in nature.
For instance, any ActiveX control (such as
calendar control) that comes with most of
the Visual programming languages is a
COM object. Although, it may not have
been written in that language, it has been
designed to work with any application that
complies with the COM standard for
accepting visual COM objects.
Example of COM
Try invoking three Word documents through
Windows Explorer. If earlier versions of MS Office
is being used, three separate copies of Word for
separate documents would be loaded.
This is not the case with present MS Office, as one
would see that there would be three “Word like
editors” one for each document whereas only copy
of the Word component is loaded into the memory.
More speed, less space usage and many more….
Part 2

The
Component Object Model (COM)
Technology
Important terms – 1
• Object – combination of code and data that can
be treated as a unit
• Component – reusable piece of executable code
that can be used with other applications with
minimum efforts; could be .EXE, .DLL or .OCX
• Interface – set of functions grouped together
under one name; COM can support more than
one interface
• DLL – dynamic link library is a highly reusable
component that can communicate with objects in
client/server application
Object

Properties
or
Attributes
or
Data

Methods
or
Functions
or
Code
Usage of COM

Some objects are full applications in themselves,


with portions “exposed” for outside world to use.
These applications have been designed not only
for use by end users but also by developers. For
example, a faxing application can have objects
exposed for use so that a developer can automate
faxing a document. Microsoft Office applications
have portions exposed so that a developer can
use the applications by “remote control”.
Component Object

Interfaces B Object

C
Interface extend toward clients

Client Object
Interface
Application Pointer
Applications connect each other

Application
Object

Interface
Pointer

Object
Application
Important terms – 2
• Distributed environment – a network
environment where information or COM
components can span on server as well
as client machines
• GUID – globally unique identifiers are
128 bit integers used to identify every
interface and component object class
• Business rules – the middle layer of the
three layer COM architecture
3-level architecture of COM

Front end Business Layer Back end

Oracle
Client 1
Products
Standard
Object
EXE

Client 2
Standard Access
EXE Customer
Object
Accounting Package
– A Case Study
Accounting procedure throughout the world
follows same principles for General Ledger,
Accounts Receivable, etc. but there are
numerous applications running everywhere
Enormous time is required for software
development. It is notable that over 100
million accounting packages are available in
the market
Contd…
If one COM-compliant accounting module is
available, then all a programmer has to do is
write a custom GUI and processing; but leave
the accounting procedure to the software.
Clearly, the programmer do not have to think
about the accounting system at all.
Similar applications can be envisaged for
power plants, super markets, banks, etc.
This goes with the saying “Don’t reinvent
wheel” (rather use the existing technology).
Straightaway, it can be said that COM sets
standards (or business rules) of the business.
Edge over 2-tier architecture
• Easily replaceable – entire coding or business
rules need not be changed; small change can be
made and get that part only replaced
• Ideal for changing business requirements –
business logic can be localized, nicely organized
and then distributed to clients
• Reusable – write the code once and then use it
in many applications
• Hides complexities –management of complex
validation part and business rules could be
handled easily
Support behind COM

COM is the underlying architecture


that forms the foundation for higher-
level software services, like those
provided by OLE, such as component
software, custom controls, inter-
application scripting, data transfer and
other software interactions
Focus on Component
Software Architecture
• Defines a binary standard for
component interoperability
• Programming language independent
• Provided on multiple platforms viz.,
Windows, Mac, UNIX
• Provides robust evolution of component
based applications and systems
• Is extensible
Binary Standard
For any given platform, COM defines a
standard way to Virtual Function Tables
(Vtables) in memory, and a standard way
to call functions through the Vtables.
Thus, any language that supports calling
functions via pointers can be used to write
components which can interoperate with
other components written to the same
binary standard
Further, COM provides…

• Communications between components,


even across process and network
boundaries
• Shared memory memory management
between components
• Error and status reporting
• Dynamic loading of components
COM supports
Object Orientation
• Classes can be defined
• Classes can be used to create objects
• Encapsulation by hiding its data and methods
is supported
• Abstraction in which complexities are isolated
and focus is primarily on necessary concepts
thus providing software reuse
• Also supported are
– Inheritance
– Polymorphism
Still a step ahead…

COM is

• Language independent
• Location independent
Part 3

Distributed COM
(DCOM)
Distributed COM
COM behaves like a distributed component
as, neither is it bound in the process space
of one process, nor is it stopped by remote
computer. When a call from a remote host
is marshaled, the model used is called
Distributed Component Object Model or
DCOM

DCOM was introduced in 1996


Distributed COM

In fact, every MTS-based


application is built from COM
components, and client can
access those applications
remotely through DCOM
Process Space in memory
Two types of processes occupy memory in
Windows: OS processes and User or any other
processes
OS is the main controller of all resources of the
computer so it is given a separate process
space; no processes can enter this space
All other processes have a separate process
space in which they keep their variables, and the
OS grants a place which is shared by all, this is
where shared code is written
Terms related to DCOM
• Server – a piece of code that implements
component object
• In-process – the server code executes in the
same process space as the client (as DLL)
• Out-of-process or remote – the server code
runs in another process on the same machine
or in another process on a remote machine (as
an EXE)
• Local process – the code runs in the same
process space on the same machine
GUID
Every COM component is registered in the Windows
registry and has a unique 16-byte number. This
number is unique for every COM component of this
world.
Whenever the COM component or a library is called,
it is checked by its GUID in the registry.
If the COM component is a registered, then
information about its server is found, and the server is
loaded into memory. In case, there is no registered
component then an error message is generated
Marshalling

If the COM component is a registered


component then the server that will
run the component is located and
services of the component are utilized.
Marshalling – Case I

If another process, P2 requests reference


to the same COM component, then instead
of calling it again in P2, P2 is given a
hypothetical object of the COM component.
Even though P2 interacts with the object in
some other process but it functions as if it
has its own copy of the object
Marshalling – Case II

If the component is registered but the


server that is required to run the
component is located on a remote
computer then the process defined in
Case I is repeated
The only difference being it is done for a
remote computer, and consequently, has
greater overhead
COM Type Libraries
It is basically documentation about collections,
objects, methods (with their parameters), and
properties (with their data types) that are
exposed for use by COM client applications
VB uses the type libraries to give online and in-
line assistance. For instance, when calling a
method in a COM object, it displays the expected
parameters automatically
A type library can be a part of an object file, with
extension .OLB and for a standalone file
extension will be .TLB
Creating a COM Object
CreateObject() is the mechanism for
creating an instance of a COM object, eg.
X = CreateObject(“Word.Application”)
Y = CreateObject(“Word.Application”)
Z = CreateObject(“Excel.Application”)
This will open up two Word and one Excel
instances, which can be seen on the
toolbar at the bottom of Windows screen
Getting reference of
a running COM Object
GetObject() is similar to CreateObject(), eg.
X = GetObject(“c:\bills.xls”)
This will instantiate an Excel object, open
the file and get a reference of it

Y = GetObject( ,“Excel.Application”)
This will get reference to the already
running application, and if none is running
then an OLE error is flashed
Key benefits of ActiveX
automatically extend to DCOM

• Language neutral
• Broad tools support
• Broad industry support
• Accessible technology
Use of Interfaces

• Ability to provide functionality in


applications to evolve over time
• Fast and simple object interaction
• Interface reuse
• Local/remote transparency
• Programming language independent
Attributes of Interfaces
• An interface is not a class
• An interface is not a component object
• Clients only interact with pointers to
interface
• Components objects can implement
multiple interfaces
• Interfaces are strongly typed using GUIDs
• Interfaces are immutable and can not be
versioned
Query Interface

It is a mechanism that allows clients to


dynamically discover (at runtime)
whether or not an interface is supported
by a component object

At the same time, it is this mechanism a


client uses to get an interface pointer
from a component object
Strengths of DCOM

• DCOM is based on the most widely


used component technology today
• DCOM is the best networking
technology to extend component
applications across the Internet
• DCOM is an open technology that
runs on multiple platforms
DCOM Benefits

• Growth path for desktop developers


• Common component model for
clients and servers
• Multi-platform support
• Based on public, open standards
DCOM ideally positioned to become
mainstream Internet technology for
business applications
• Transport neutral
• Provides distributed Java today
• Evolutionary technology
• Common components for
browser and web-server
• Security
• Standards based
Local/Remote Transparency
Local server
Client Process Interprocess
process
Communication
In process
Component COM
object
Client Application

Local
object
Cross process
COM with lightweight RPC
Local Remote server
object process

Remote COM
object Cross network
with true RPC Remote
object
Local/Remote
Transparency Benefits
• Common solutions to problems that are
independent of distance between client
and server
• Programmers leverage their learning
• System implementation is centralized
• Interface designers concentrate on
design aspects
Part 4

Microsoft
Component Services
Microsoft Transaction Server

MTS is a part of Windows NT server that


helps in creating necessary infrastructure
services for building robust enterprise
wide applications plus standards into a
mainstream business tool
Since introduction in 1996, MTS has
remained the first commercial software to
combine transactions with components
Microsoft
Internet Information Server
• IIS is a part of Windows NT server that
supports web enabled applications and
their connectivity to the databases
• IIS supports standard Internet protocols
and services such as HTTP, SSL, CGI.
• IIS supports applications based on Active
Server Pages (ASP), VBScript, etc.
Active Server Pages
• ASP contains a simple program – a script –
written in a simple language such as Visual
Basic (Scripting Edition) or VBScript and
executed at the server
• Benefits to the developers are
– Access to COM objects
– Integration with MTS-based applications
– Transactional ASP scripts
– Process isolation
– Support for standard, well-known languages
Microsoft Message Queue

MSMQ is a part of Windows NT server that


provides support for non-blocking and
asynchronous communication for
distributed applications
Features of MSMQ
• COM based access
• Integration with MTS
• Automatic message journaling
• Automatic notification
• Built-in data integrity, data privacy,
and digital signature services
• Message priority support
• Support for multiple platforms
Microsoft COM Services
MSMQ

DCOM

MTS Database

Database
ASP
HTTP IIS Script
COM+

• The development of component services


continues with COM+
• By enhancing and extending the existing
services, COM+ further increases the
value and performance of the services
COM provides
Features of COM+
• A publish and subscribe service – allows
multiple clients to “subscribe” to various
“published” events
• Queued components – allows clients to invoke
methods on COM components using an
asynchronous model (for unreliable networks)
• Dynamic load balancing – automatically
spreads client requests across multiple
equivalent COM components
• Full integration of MTS into COM – includes
broader support for attribute based programming
and services such as transactions, security, and
many more…
End of presentation

Thank you

You might also like