OOMI - PowerPoint PPT Presentation

1 / 52
About This Presentation
Title:

OOMI

Description:

The Runtime Does all the Grungy Stuff. Interceptors Can Add Value Later ... Are the principal mechanism to create COM objects ... – PowerPoint PPT presentation

Number of Views:79
Avg rating:3.0/5.0
Slides: 53
Provided by: poulejna
Category:
Tags: oomi

less

Transcript and Presenter's Notes

Title: OOMI


1
OOMI
  • A short introduction to
  • Microsoft's
  • Component Object Model (COM)

2
Agenda
  • Goals of COM?
  • COM History
  • Programming COM servers
  • Using COM servers
  • (client side programming)
  • COMs architechure

3
Goals of COM
To provide a component object model that
facilitates
  • Binary encapsulation
  • Clients do not have to be re-compiled if server
    objects change
  • Binary compatibility
  • Client and server objects can be developed with
    different development environments and in
    different languages
  • Access Location transparency
  • in-process
  • cross-process
  • cross-machine
  • Zero sacrifice in-proc performance
  • Simplest model possible
  • Enable extensibility and adaptability

4
The COM Runtime
  • COM is a proprietary Microsoft standard
  • But other companies have implemented COM on other
    platforms (e.g. Software AG on Unix)
  • Highly debugged and tuned
  • The COM Runtime first shipped in 1993
  • Used by 1000s of commercial applications
  • DCOM first released in Windows NT 4.0, August
    1996
  • Win95 version released January 1997
  • COM/DCOM Available today on
  • Win95, Win98 and WinME
  • NT, Win2K and XP
  • Solaris, HPUX, Linux, MVS, VMS, Mac and others
  • Free! (Built-into Win32 Platforms)
  • No separate client access license or expensive
    developer version
  • Full source code licensable

5
COM History
  • COM is some what tainted by its legacy

6
The Clipboard and DDE
Clipboard
Destination
Source
The brown fox
The brown fox
The brown fox
  • The user produce some data in a source program
    and stores them on the clipboard.
  • The user paste the date from the clipboard into
    the destination program.
  • This process can be automated with DDE
  • Dynamic Data Exchange
  • DDE is based on Windows Message system (and was a
    pain to program)
  • DDE is an old technology but is still used in
    some programs

7
16-bit OLE 1.0
  • Object Linking Embedding 1.0 utilized the
    clipboard to copy not only the data, but also
    information about the data source.
  • A user copying a graph would actually copy 3
    pieces of information to the clipboard
  • Presentation data
  • Class information
  • The raw data
  • Copying the raw data created an embedded object
  • Copying a file reference created a linked object
  • Pasting the graph into e.g. a word document
    produced a compound document.
  • OLE 1.0 used DDE as its interprocess
    communication mechanism.

8
16-bit OLE 2.0
  • Object Linking Embedding 2.0 was implemented
    using a new technology
  • The Component Object Model - COM
  • OLE 2.0 (COM) features
  • Binary standard for objecs
  • Lifetime management
  • Structured storage
  • Inter-application drag and drop
  • In-place editing
  • OLE Automation
  • The 16-bit Windows OS wasnt really capable of
    all this often available system resources went
    down to 0!

9
OLE Controls
  • Visual Basic 3.0 had a mechanism for extending
    itself with custom controls
  • Visual Basic Controls VBX controls
  • With Visual Basic 4.0 came an enhanced technology
    for custom controls
  • OLE Controls - OCX controls
  • An OCX characteristics
  • must be loaded into a container
  • Is implemented in a DLL
  • Exports COM interfaces
  • So COM legacy is tied to VB amongst others

10
32-bit OLE
  • With the release of NT 3.51 (an shortly after
    Windows 95) came 32-bit OLE.
  • 32-bit OLE used some NT features like Unicode
    strings, but lacked others like NT security.
  • The inter-process infrastructure was build on
    MS-RPC (Remote Procedure Call)

11
ActiveX
  • Before the release of NT 4.0 MS announced Network
    OLE, but the press called it OLE 3.0, so MS dropt
    the name OLE, and just called it COM and DCOM.
  • But only for a short time
  • When the Internet reached Microsoft the came up
    with a new name ActiveX
  • ActiveX Controls are light weight OLE Controls
    and can be used on Web pages.
  • DCOM first released in Windows NT 4.0, August 1996

12
ActiveX Builds on COM
  • COMs initial thrust
  • integrating desktop applications with OLE
  • COM technology is generically useful, being
    applied to a range of other areas
  • Inherently distributed
  • So What is ActiveX?
  • A marketing name for a set of technologies and
    services, all based on COM

13
Active Components
  • ActiveX Controls
  • Are COM components
  • Have design-time UI called property page(s)
  • Implements MS defined standard interfaces
  • Must have automation/dual interface
  • Supports events
  • Can be written in C, Java, VB, Delphi, ...
  • Self-registering
  • Optimized for download and execute
  • Work on both Active Client or Server
  • Can talk indirectly over HTTP or directly over COM

14
Microsoft Transaction Server
  • Microsoft Transaction Server(MTS) was
    introduced at the PDC in Long Beach in 1996
  • Runtime executionenvironment for server-based
    components
  • Extends COM archi-tecture with
    transactionsemantics
  • Provides concurrency,multi-threading, queuing,
    atomicity, etc.
  • Makes is easy to encapsulate business logic in
    middle-tier

15
COM/DCOM/OLE Architecture
In-Place Activation
ActiveX Controls
Property Change Notification
Linking
Embedding
Events
Drag and Drop
Property Pages
Uniform Data Transfer
Automation
Persistent Objects
Connectable Objects
Structured Storage
Monikers
Type Information
Component Object Model, Distributed Component
Model
Brockschmidt, Kraig, Inside OLE Microsoft Press
16
What Is COM?
  • Unification of COM and MTS
  • Plus...
  • Extensions to base COM
  • Extensions to MTS services
  • New Services
  • Minimal impact on how you write components
  • Remoting architecture doesnt change (DCOM)

17
COM Strategy
18
COM Philosophy
  • Attribute-based Programming
  • Write your Logic
  • Add Annotations (Set Attributes)
  • The Runtime Does all the Grungy Stuff
  • Interceptors Can Add Value Later

19
Making it easy
  • System provided implementations of
  • IUnknown
  • AddRef / Release
  • QI
  • Class factory
  • DLLRegisterServer, DllUnregisterServer,
    DllLockServer
  • IDL
  • TypeInfo
  • IDispatch
  • IConnectionPoint, IConnectionPointContainer
  • IProvideClassInfo
  • IPersist

20
Future of COM
  • COM DCOM may still have a place especially
    COM as an Component architecture not as
    Distributed Middleware
  • .NET Remoting Web services is a threat to DCOM
  • But know back to business

21
Programming COM servers
  • Classes Interfaces in C

define interface struct // The
interface. interface ICar virtual void
SpeedUp(long delta) 0 virtual void
CurrentSpeed(long currSp) 0 // The basic
Car. class Car public ICar private long
m_currSpeed public // ICar implementation.
void SpeedUp(long delta) m_currSpeed
delta
void main() // An array of ICar interfaces.
ICar theCars2 theCars0 new Car()
theCars1 new HotRod()
theCarsi-gtSpeedUp(10)
22
COM is not C objects
  • COM is an Component Model
  • And as as such is very different from C
  • The Binary component makes the difference
  • Implemented as a DLL or an EXE (Service or stand
    alone)

23
The Composition of a COM DLL
Global functions (normal extern C)
Mandatory interface
Class factory also calledclass object
Standardinterface
coclass
Custominterface
24
Interface
  • A group of related functions that specifies a
    contract
  • name, interface signature, semantics, and
    marshaling buffer format
  • Denotes behavior only, not state
  • Identified by a GUID Global Unique Identifier
  • Called IID Interface ID
  • Must derive from IUnknown
  • either directly or through other interfaces

25
Microsoft IDL (MIDL)
  • Language for expressing all COM concepts
  • Like OMGs CORBA IDL
  • MIDL is
  • programming-language independent
  • evolved from OSF/RPC IDL
  • not computationally complete but better than C
    header files
  • In COM IDL files are compiled with a MIDL
    compiler
  • It is NOT the same as CORBA IDL

26
MIDL output
RawComCar.idl
Midl.exe
RawComCar.h Contains C and C definitions for
each COM type
RawComCar_i.c Contains the GUIDs for each COM
type
RawComCar.tlb Binary IDL primarily for non C/C
clients
RawComCar_p.cdlldata.c Files used to build a
custom stub and proxy DLL to marshal your COM
interfaces
27
COM Interfaces in MIDL
// RawComCar.idlimport "oaidl.idl" // The ICar
interface uuid(710D2F54-9289-4f66-9F64-201D56FB66
C7), object interface ICar IUnknown
HRESULT SpeedUp(in long delta) HRESULT
CurrentSpeed(out, retval long currSp)
IID (interface identifkation)
Items in square brackets are called
attributes.(attributes in COM are not related to
attributes in UML)
Interface
Root Interface
28
GUID
  • A GUID is a 128-bit number that is statically
    unique
  • GUIDs are used to identify severel different COM
    subjects, e.g. interface IID, coclass CLSID
  • Can be created by a tool or programmatically

Wtypes.h has many defines ease working with
GUIDs, Ex define REFGUID const GUID
constdefine REFIID comst IID const And
objbase.h has some helper functions and operator
overloads
29
COM Class coclass
  • Named, concrete implementation of one or more
    interfaces
  • Identified by a CLSID ( GUID)
  • sometimes ProgID too
  • Type libraries may describe incoming, outgoing
    interfaces

30
COM Class in MIDL
// RawComCar.idl // The Raw Car
Library. uuid(D679F136-19C9-4868-B229-F338AE16365
6), // Library ID (LIBID) version(1.0), library
RawComCarLib importlib("stdole32.tlb") //
Our COM class. uuid(096AC71D-3EB6-4974-A071-A3B1
C0B7FC8D) // Class ID (CLSID) coclass
ComCar default interface ICar interface
IRadio // an other COM class. uuid(7AD9AFC
9-771C-495c-A330-006D54A23650) // Class ID
(CLSID) coclass ScriptableCar default
interface IScriptableCar
31
Implementing the COMCar
// ComCar.h interface for the ComCar
class. include ltwindows.hgt // MIDL generated
file! include "rawcomcar.h" // ComCar implements
IUnknown, ICar and IRadio. class ComCar public
ICar, public IRadio public ComCar() virtua
l ComCar() // IUnknown impl. STDMETHOD_(ULONG,
AddRef)() STDMETHOD_(ULONG,Release)() STDMETHO
D (QueryInterface)(REFIID riid, void) // ICar
impl. STDMETHOD (SpeedUp)(long
delta) STDMETHOD (CurrentSpeed)(long
currSp) // IRadio impl. STDMETHOD
(CrankTunes)() // data members ULONG
m_refCount // Ref counter. long m_currSpeed //
Current speed!
32
ComCars implementation of IUnknown
STDMETHODIMP_(ULONG) ComCarAddRef() return
m_refCount STDMETHODIMP_(ULONG)
ComCarRelease() if(--m_refCount
0) delete this return m_refCount STDMETHOD
IMP ComCarQueryInterface(REFIID riid, void
ppInterface) // Remember! Always AddRef()
when handing out an interface. if(riid
IID_ICar) ppInterface (ICar)this ((IUn
known)(ppInterface ))-gtAddRef() return
S_OK
33
All this not necessary
  • The above code is not necessary
  • Use ATL COM Wizards in MS VS

34
Objects vs. Components
  • COM Object
  • an instance of a COM Class
  • COM Component
  • binary unit of code that creates COM objects
  • includes packaging code , registration code,
    class factory, etc.

35
COM Objects
  • Instances of COM Implementations
  • References to COM objects are called interface
    pointers
  • Interface pointers refer to main memory locations
  • References support location transparency
  • Object references are persistent

36
COM Classes
  • Named implementations
  • Have one or several interfaces
  • Are the principal mechanism to create COM objects
  • Can return interface pointers to specific COM
    objects

37
COM Objects, Interfaces and Classes
Interface
implements
Implementation
uuid GUID
1..
1..
1
1
1..
1..
instantiates
0..
0..
Object
location int
0..
0..
createslocates
implements
Class
ClassObject
instantiates
clsid GUID
1
1
1
1
38
UML Attributes
  • COM does support UML attributes (state
    information)
  • Attributes must be represented as set and get
    operations by the designer
  • COM has a keyword to designate this Property
  • propget
  • propput
  • Example

interface IOrganization IUnknown propget
HRESULT Name(out BSTR val)
39
COM Operations
interface IClub IOrganization propget
HRESULT NoOfMembers(out short val) propget
HRESULT Address(out ADDRESS val) propget
HRESULT Teams(in long cMax, out long pcAct,
out,size_is(cMax),length_is(pcAct)
ITeam val) propput HRESULT Teams(in long
cElems, in,size_is(cElems) ITeam
val) propget HRESULT Trainers(out ITrainer
val3) propput HRESULT Trainers(in
ITrainer val3) HRESULT
transfer(in IPlayer p)
40
COM HRESULTS
  • HRESULTS are 32-bit integers
  • Structured into four fields

Severity Code
Reserved
41
COM Operation Invocations
  • Invocation is defined by client objects
  • Invocation determines
  • Interface pointer of server object
  • Name of invoked operation
  • Actual parameters
  • Invocation is executed synchronously
  • Invocation can be defined
  • statically
  • dynamically
  • Clients have to interpret HRESULTS!

42
COM Architecture
  • The Model
  • The ORB
  • The Services

43
COM Principles
  • Rigorous Encapsulation
  • Black box -- no leakage of implementation details
  • All object manipulation through strict interfaces
  • Polymorphism
  • via multiple interfaces per class
  • Discoverable QueryInterface

IUnknown
IDispatch
COMObject
IRobot
44
COM Architecture In process
COM Runtime
In process
Once COM connects client and object, the client
and object communicate directly without added
overhead
45
COM Architecture Local
Out of process - Local
46
COM Architecture Out of process - Remote
COMrun time
COMrun time
Out of process - Remote
47
COM Architecture
Clients always call in-process code objects are
always called by in-process code. COM provides
the underlying transparent RPC.
48
The COM ORB
  • The model is about how the technology is used
  • The ORB is how its implemented
  • In COM the ORB is called the COM Runtime

49
Structure of the COM ORB
Components and Applications
The COM Runtime
Core Services(Automation, Monikers, Storage,
ComCat, Data Transfer, IR)
COM and Distributed COM
Registry
Pluggable Security(SSPI)
MS-RPC
NTLM
Pluggable Transports
DCE
Kerberos
ETC...
TCP
UDP
IPX
SPX
HTTP
Falcon
50
Architecture
OXID object exporter identifier associates RPC
bindings to objects SCM Service control manager
activates remote objects
51
Core COM Services
  • Security
  • Lifecycle Management
  • Type Information (Interface Repository)
  • Monikers (Naming)
  • Automation (Dynamic Invocation)
  • Data Transfer
  • Component Categories
  • Registry

52
Recommended Books
  • Essential COM
  • Don Box, Addison-Wesley
  • Inside COM
  • Dale Rogerson, Microsoft Press
  • Professional DCOM
  • Roger Grimes, Wrox Press
  • Component Software
  • Clemens Szyperski, Addison-Wesley

53
MSDN Library Resources
  • COM Specification
  • COM Programmers Cookbook
  • Designing COM Interfaces
  • COM Home Page
  • http//www.microsoft.com/com/
Write a Comment
User Comments (0)
About PowerShow.com