COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM? Challenges facing the software...

56
COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie

Transcript of COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM? Challenges facing the software...

Page 1: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM / DCOM

Xiaolan Lu

Mingzhen Wang

Dong Xie

Page 2: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Why COM / DCOM?

Challenges facing the software industry Component software provides a solution General approach of dealing with

components Microsoft’s solution – COM/DCOM

Component Object Model

Distributed Component Object Model

Page 3: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Challenges for Software Industry

Applications are large and complex Applications are not modular Applications are not easily integrated Operating systems have similar

problems

Page 4: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

General Approach of Dealing with Challenges

Client

API

Vendor #1’s Component

Vendor #2’s Component

Page 5: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Problems with the Traditional Approach

The evolution of an API is a problem. Advertising and maintaining different

versions of the API can be problematic. Enabling components to communicate

with each other is challenging. The programming language to create

components greatly impacts the component communication through an API.

Page 6: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Microsoft’s Solution – COM and DCOM

Component Object Model (COM) Distributed Component Object Model

(DCOM)

Page 7: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Component Software

A component is reusable piece of software in binary form that can be plugged into other components from other vendors with relatively little effort.

Example – spell checker

Page 8: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Features of Component Software

Reusable software components Components in binary form Components easy to combine

Page 9: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

What’s COM

COM is a standard for the interaction of binary objects.

COM is also an integration technology.Objects developed independentProvide standard model

Page 10: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

What is COM? (continued)

Client Application

COM:EstablishedConnection

ServerApplication

Object

Page 11: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

The Goals of COM?

By providing a binary and network standard, COM enables interoperability among applications of different vendors. Object-based programming Promote interoperability Components cooperate

Allow applications to connect as software objects. Provide operation

Page 12: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

The Goals of COM

For example: Word processor

Spreadsheet

Mainframe database Objects support a predefined standard interface

for data exchange

Page 13: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

The Goals of COM

Because COM is a binary standard, objects can be implemented in a number of different programming languages.

Objects can be used from clients that are written using completely different programming languages

Page 14: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

The Goals of COM

Vendor independence

• ODBC driver• Lots of effort to transfer code• COM objects export only interface• Easily upgrade without recompiling

Page 15: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

What is DCOM?

Extension of COM Client and server on different computers

Page 16: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM Objects in Same Processes From Same

Machine

Page 17: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM Objects in Different Processes From Same

Machine

Page 18: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

How DCOM Establishes Connections among COM Objects From Different

Machines

Page 19: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Nice Features of DCOM

Location independence• Hide the location• The way to connect and call methods is identical.

Language neutrality• Developers can choose the languages

• Take advantage of free threading. Scalability Fault tolerance Easy deployment

Page 20: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

How COM/DCOM works Objects and interfaces The COM Client/Server Model

Page 21: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Object and InterfaceObject and Interface

Interfaces and C++ Class Interface Definitions: IDL How an Interface Works Object Picture

Page 22: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

How An Interface WorksHow An Interface Works

Interface Pointer

pointer Pointer to function1

Pointer to function2

Pointer to function3

……

Interface function tableFunction1(..) { … }

Function2(..) { … }

Function3(..) { … }

Page 23: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Object PictureObject PictureA and B are interfaces The object implements each member function of the interface and

provides pointers to those functions to COM. COM then makes those functions available to any client.

objectA

B

Page 24: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

The COM Client/Server ModelThe COM Client/Server Model

Relationship between client, COM, and server COM Object and Class Identifiers COM Clients COM Servers Location Transparency

Page 25: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Relationship between client, COM, and Relationship between client, COM, and serverserver

ClientApplication

COM

Server

Object

(1) “Create Object”

(2) Locate implementation

(3) Get object interface pointer, return to Client

(4) Call interface members

Page 26: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM Object and Class IdentifiersCOM Object and Class Identifiers

A COM class– A particular implementation of certain interfaces– Machine code

– to be used by different applications

A COM object– Identified by a unique128-bit CLSID that associates an object

class

A CLSID– GUID like an interface identifier

Page 27: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM ClientsCOM Clients

A COM Client asks COM to instantiate objects in two way:– To call the COM function CoCreateInstance– Use a class factory

To manufacture an object of a class

Page 28: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM ClientsCOM Clients

Client

Server

Class Factory

Object

(1)“Create An Object”

(2)Manufacture object(3)Return new

interface pointer to client

Page 29: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM ServerCOM Server

Two basic kinds of object servers– Dynamic Link library (DLL) Based

The server is implemented in a module that can be loaded into and will execute within, a client’s address space

– EXE Based The server is implemented as a stand-alone executable module

Page 30: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM ServersCOM Servers

Server ModuleServer

Object

Class Factory:creates Object

IClassFactory

Object Interfaces Implementation identical for any module

Implementation differs for DLLs and EXESExposure for

class factory

Unloading Mechanism

Page 31: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM ServerCOM Server

Server Flavors: In-Process Server

– A server can be loaded into the client’s process and serves “in-process object’

Local Server– A sever runs in a separate process on the same machine as the

client and serves “local object”

Remote Server– A server runs on a separate machine and therefore always runs in

another process as well to serve “remote objects”

Page 32: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Location TransparencyLocation Transparency

A single programming model– Dealing with in-process or remote objects is transparent

and identical to dealing with in-process objects

Page 33: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Location Transparency Location Transparency

ClientApplication

In-processserver

In-processobject

COM

LocalObjectProxy

RemotObjectproxy

Local Server Process

COM

Stub

Local Server

LocalObject

Remote Machine

Remote Server Process

Remote Server

RemoteObject

COM

Stub

Page 34: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Architecture for Distributed objectsArchitecture for Distributed objects

Client

proxy

RPC Runtime RPC Runtime

Transport

stub

Object

Transport

channel channel

COM Library COM Library

Process Boundary

Page 35: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM Library

COM is a specification for how objects and their clients interact through the binary standard of interfaces.

COM is also an implementation contained “COM Library” (such as DLL on Microsoft Windows)

Page 36: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM Library (continued)COM Library includes:• A small number of fundamental API functions: facilitate

the creation of COM applications.• Implementation locator service: class identifier

server? location?• Transparent remote procedure calls• Memory management

Page 37: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

COM as a Foundation

Binary standard of interface:• Key to COM’s extensible architecture• Foundation upon which is build the rest of and the

other systems(OLE etc)

1. COM infrastruction2. OLE

Page 38: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

1) COM Infrastruction

Persistent Storage: A set of interface and an implementation of those interfaces that create structured storage, otherwise known as a “file system within a file”Persistent, Intelligent Names (Monikers): The ability to give a specific instantiation of an object a particular name that would allow a client to reconnect to that exact same object instance with the same state at a later time.Uniform Data Transfer: Standard interfaces through which data is exchanged between a client and an object and through which a clent can ask an object to send notification in case of data change

Page 39: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

The Component Object Model and Component Objects

Intelligent NamesPersistent Storage

Uniform Data Transfer

COM is built in progressively higher level technologies thatdepend upon lower level technologies.

Page 40: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

2) OLE

Microsoft’s OLE technology: a collection of additional higher-level technologies that build upon COM and its infrastruction.OLE 2– includes mostly user-interface oriented features based on usability,

application integration, and automation of tasks. – All of these features are implemented by means of specific interfaces on

different objects and defined sequences of operation in both clients and servers and their relationships and dependencies on the lower level infrastructure of COM

Page 41: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

The Component Object Model and Component Objects

Intelligent Names

Automation

Persistent Storage

Uniform Data Transfer

Linking

Embedding

In-Place Activation(Visual Editing)

CompoundDocuments

Drag & Drop

COM

OLE

OLE builds its features on COM.

Page 42: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

OLE(Continued)

Drag & Drop: The ability to exchange data by picking up a selection with the mouse and visibly dropping it onto another window.

Automation: The ability to create “programmable” applications that can be driven externally from a script running in another application to automate common end user tasks. Automation enables cross-application macro programming.

Compound Documents: The ability to embed or link information in a central document encouraging a more document-centric user interface.

Page 43: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

How to create a Client

1. Initializing the COM Libraries2. Getting the CLSID of an Object3. Creating an instance of an Object4. Using a COM Object5. Uninitializing the COM Libraries

Page 44: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

1) Initializing the COM Libraries

{HRESULT hr;hr = CoInitialize(NULL);if (FAILED(hr))

return FALSE…

}

Page 45: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

2) Getting the CLSID of an Object

CLSIDs: a unique class name with a 128-bit numberProgIDs: CLSID ProgIDs (readable)

{…CLSID clsid;hr = CLSIDFromProgID(OLESTR(“Simple.Object”), &clsid);if (FAILED(hr))

return FALSE;…

}

Page 46: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

3) Creating an instance of an Object

{…IStream * pStream;hr = CoCreateInstance(

clsid,NULL,CLSCTX_LOCAL_SERVER,IID_Istream,(LPVOID *) &pStream);

…}

Page 47: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

4) Using a COM Object

{…if (SUCCEEDED(hr)){ //Use the interface pointer

pStream->Read(…);pStream->Release();

…}

Page 48: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

5) Uninitializing the COM Libraries

{…CoUninitialize();…

}

Page 49: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

How to create a COM Object

Deriving a C++ Class from an InterfaceImplementing the Methods of an InterfaceControlling the life time of a COM Object

Page 50: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Deriving a C++ Class from an Interface

In C++, interface is defined as a structure that contains only pure virtual functions.

Class Csimple : public Istream{

// IUnknown methods// IStream methods

};

Page 51: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Implementing the Methods of an Interface

Examples: AddRef and Release MethodsAddRef:ULONG _stdcall CSimpleObject::AddRef(void){ return ++m_cRef; //return InterlockedIncrement(&m_cRef);}

Page 52: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Implementing the Methods of an Interface (continued)

ReleaseULONG _stdcall CSimpleObject::Release(void){

if (0 == --m_cRef){ delete this; return 0;}

return m_cRef;}

Page 53: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Controlling the life time of a COM Object

1. Simplest strategy (Object server – one object): object – central reference countif (reference count == 0) delete itself

2. COM object server – more than one object Reference counter of all object == 0 Server

shut down

Page 54: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Costs and LimitationsLow cost development tools from Microsoft (such as VC++ and VB)Construction of clients and servers is straightforwardInitial price for COM/DCOM is low on Windows platforms. Unclear about other platformsBeyond basic costs to produce the technology, any serious software development using COM/DCOM requires substantial programmer expertise.However, Microsoft has strong organization to assist individuals developing COM clients and objects

Page 55: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

References

Book:• Mastering COM DevelopmentWeb site:http://www.sei.cmu.edu/str/descriptions/com.htmlhttp://www.microsoft.com/com/resources/specs.asphttp://www.microsoft.com/com/tech/DCOM.asp

Page 56: COM / DCOM Xiaolan Lu Mingzhen Wang Dong Xie. Why COM / DCOM?  Challenges facing the software industry  Component software provides a solution  General.

Questions?Questions?