Académique Documents
Professionnel Documents
Culture Documents
What is COM?
A standard for interoperable software A runtime library providing low-level or hard-to-implement functionality A competitive, capitalist marketplace for selling functionality to application developers An endless source of healthy obfuscation
That Last Slide Was Pulled From Booboos Rear End. What is COM, Really?
A sacred covenant held by the worlds best developers. All software functionality is encapsulated through a COM class (coclass) and exposed through COM interfaces
Mooooo
Blah Blah Blah Blah Blah Blah Blah Blah Blah
Booboo
About Interfaces
The client communicates with the server through interface pointers (think base class pointers) Methods implemented by the coclass are invoked through interface pointers Interface pointers are acquired through IUnknown Because all interfaces derive IUnknown, any interface pointer on an object can be acquired through any other interface pointer on the object The method to acquire an interface pointer is IUnknown::QueryInterface (think dynamic_cast)
IUnknown
m_pUnkVtbl
QueryInterface() AddRef()
IFoo IBar
m_pFooVtbl m_pBarVtbl
pQueryInterface pAddRef
Release()
Oink
FooFunc1() FooFunc2()
FooFunc3()
Reference Counting
To regulate destruction of objects, COM requires that all coclasses implement a reference counter COM objects can have their methods invoked from other threads, processes, and even machines. Reference Counting eliminates a number of problems associated with synchronization
IUnknown
m_pUnkVtbl
IFoo
m_pFooVtbl
Foo
An In-process Server
(same apartment)
IUnknown
IUnknown
STA
IFoo IBar Oink_Proxy IBar IFoo Oink_Stub IUnknown
IFoo
COM Invisible Window
Client Code
IBar
Oink
STA
IUnknown
m_pUnkVtbl
Process Boundary
IFoo
m_pFooVtbl
Foo_Proxy
QueryInterface_Stub()
IUnknown
m_pUnkVtbl
IFoo
Shake_Proxy() pQueryInterface_Proxy pAddRef_Proxy pRelease_Proxy pShake_Proxy pRattle_Proxy pRoll_Proxy Roll_Proxy() Roll_Stub() Rattle_Proxy() Rattle_Stub() Shake_Stub()
m_pFooVtbl
Foo
IPC
Local Server
IUnknown
m_pUnkVtbl
IFoo
m_pFooVtbl
Foo_Proxy
Client Machine
QueryInterface_Stub()
IUnknown
m_pUnkVtbl
MS-RPC
Shake_Proxy() pQueryInterface_Proxy pAddRef_Proxy pRelease_Proxy pShake_Proxy pRattle_Proxy pRoll_Proxy Roll_Proxy() Roll_Stub() Rattle_Proxy() Rattle_Stub() Shake_Stub()
IFoo
m_pFooVtbl
Remote Server
Things To Note
All interface method calls are synchronous; a remote call to a New York server must complete its round-trip before the client can continue execution Asynchronous services are available through Microsoft Message Queue (MSMQ) and ICallFactory (Windows 2000) Encryption, authentication, and impersonation services are available with remote server connections (at least on NT)
Confused?
Where Am I?
WRONG!
Faery Tales!
COMprehension
COM is a set of many, many technologies. COM is really Microsofts software engineering strategy Computer people (you) are betting the bank on Microsoft Microsoft is betting the bank on COM COM Owns You
COM Defined
A single sentence cant define COM, because COM is such a monumental and omnipresent set of technologies.
So what is a COM technology? Any software creation that leverages interfaces and coclasses, as described in the earlier slides.
The Month View is from the Microsoft Windows Common Controls-2 6.0 controls library
Property Pages
How does Visual Basic know which properties to put in the box?
Events
How does Visual Basic know which events the control exposes?
What is a VB Control?
Standard Interfaces
Programming sucks. Best to fall back on platform-provided functionality A container/client can interact with any server/control simply by implementing the required site interfaces Application developers who license your components are already familiar with the interfaces Standard interfaces can use the Microsoftprovided proxy/stubs
COM Security
CoInitializeSecurity sets the authentication requirements for the current process The COSERVERINFO structure specifies the machine name and authentication info for clients connecting to remote objects CoImpersonateClient allows the server to impersonate the client when accessing other servers
Books of COMpetency
The C++ Programming Language (Bjarne Stroustrup) Programming Windows (Charles Petzold) Advanced Windows (Jeffrey Richter) Design Patterns (Gamma, Helm, Johnson, Vlissides) Essential COM (Don Box)