Title: ComponentObjectModel, DCOM and Software Components
1ComponentObjectModel, DCOMandSoftware Components
- Nat Brown
- COM Program Management
- Microsoft Corporation
- With additions by R. Cook
2How to Compose Applications?
- From components written in any language
- From components executing on multiple machines
- Allow an application to delegate UI actions and
screen space to components (e.g. embed
spreadsheet in a document) - Allow applications to be used as components to
build other applications (automation)
3What is Automation?
- Automation is the ability to control an
application from another. - Sometimes referred to as scripting.
- For example, script can start Excel, load a
spreadsheet, add data, save, quit Excel. - Visual Basic for Applications (VBA) is a
scripting language which makes use of automation. - Perl (and PerlScript) makes use of automation.
4What is a COM Component?
- Supports the IUnknown abstract interface
- May support other interfaces
- No inheritance or other language dependencies
- Every interface has a UNIQUE 128-bit (uuidgen
in Windows and OS/X) - Every copy of an interface is reference-counted,
although this does not preclude a high-level
implementation of garbage collection
5What is a COM Component?
- Every class has a UNIQUE 128-bit CLSID
- A class (implementation) can support multiple
interfaces - A class can have a text name, referred to as a
PROGID
6What is a COM Component?
C namespace EsriSamples Guid("97FDB5D7-41D
8-4260-BF72-3EB2CDD36747") ProgID("ZoomInCmd.Z
oomIn") public class ZoomIn ICommand ...
7- class CMyClass public Iunknown //C
- private ULONG m_cRef // COM reference count
- public
- STDMETHODIMP QueryInterface(REFIID riid, void pp
vObject) - IUnknown punk nullptr
- if (riid IID_IUnknown)
- punk static_castltIunknown gt(this)
- // TODO List other implemented interfaces here.
- ppvObject punk
- if (punk nullptr) return E_NOINTERFACE
- punk-gtAddRef()
- return S_OK
- STDMETHODIMP_(ULONG) AddRef()
return m_cRef - STDMETHODIMP_(ULONG) Release()
- ULONG cRef --m_cRef
- if (cRef 0) delete this
- return cRef
8Interface Definition Language - IDL
-
- object,
- uuid(75D873CD-7B63-11D3-9D43-00C0F031CDDE),
- helpstring("IServer Interface"),
- pointer_default(unique)
-
- interface IServer IUnknown
-
- HRESULT HelloWorld(in, string char
pszMessage) -
9The COM Programming ModelA scalable programming
model
10DCOM ArchitectureFlexible and extensible
Client Machine
Server Machine
D C O M
D C O M
COM Object
Clients
11DCOM ArchitectureFlexible and extensible
Server Machine
Client Machine
D C O M
D C O M
COM Object
Clients
12DCOM ArchitectureEfficient and scalable
- Multiplexing - Single Port per-protocol, per
server process, regardless of of objects - Scalable - Connection-Less Protocols like UDP
Preferred - Established Connection-Oriented (TCP) Sessions
Reused by same client
Server
Client
Client
13DCOM ArchitectureEfficient and scalable
- Low Bandwidth
- Keep-Alive Messages bundled for all connections
between Machines
Server Machine
Client Machine
Keep-Alive Traffic for all connections
Client 1
Server
Logical Connections or Sessions
Client 2
14Ease-of-Use First Steps
Clients
Network
Receiver
Queue
Connections
Context
Security
Management
Configuration
Thread Pool
Service Logic
Synchronization
Shared Data
Server
MTS easier servers
Easier components?
15Additional Technologies
- COM
- MTS - Microsoft Transaction Server
- MSMQ - Microsoft Message Queue
- ADS - Active Directory Service
- As distributed registry
- As namespace abstraction
- All Microsoft products are COM based
- IIS - Internet Information Server
- Exchange
- Internet Explorer
- Word, Excel, etc.
16First Steps
- Basically there is a general model of use
- 1) A typical controller process will request that
a COM server generate a COM object. - 2) The server is loaded or located, the request
is submitted, a response is returned. - 3) If request results in a valid COM object then
controller process interacts with the object. - 4) Destroy COM object.
17First Steps
- Lets say we need to change the title and subject
of a Microsoft Word document
1) Need to somehow run Word 2) Need to load up
the document 3) Need to change the title and
subject 4) Need to save the document 5) Need to
quit Word
18First Steps
- How would we implement such a system?
- Request a Word application COM object
- Query the appropriate interface
- Call a function in the Word application COM
object which loads a document. It returns a Word
document COM object - Modify the Title and Subject properties from the
Word document COM object - Call into the Word document COM object to save to
disk - Destroy both the document and application COM
objects