Beruflich Dokumente
Kultur Dokumente
Model
Presented by
I Unknown
Highlights
Problemsin C++ Software distribution
COM goals
Mechanism
Interfaces
IUnknown
CoClass
Component
Software Distribution
methods
Disadvantages:
Application A ClassX.obj • Duplication of binary code
(on disk and memory)
• Update of class X requires rebuild
Application B ClassX.obj (even if interface does not change)
Application C ClassX.obj
Dynamic Linking
DLL is binary code that is
Application A ClassX.obj linked to the application at
run-time.
Application B ClassX.obj To use a DLL you will have
to add an import library to
Application C ClassX.obj your project.
ClassX ClassX
private: a private: a,b
methods methods
Problem:
Application A
Version 2.0 C++ supports syntactic
SizeOf(ClassX) = 8 encapsulation via its private and
protected keywords but has no
Application B ClassX.dll
Version 1.0 notion of binary encapsulation.
Version 2.0
SizeOf(ClassX) = 4 SizeOf(ClassX) = 8
Application C Update of Class X still requires
Version 1.0
SizeOf(ClassX) = 4 recompilation
Separating Interface from Implementation
Solved problems:
• update of class X requires recompilation
DLL
IClassX ClassX
private: m_pThis private: a
Problem:
The binary signature is compiler dependent !
IClassX ClassX
private: m_pThis private: a
Compiler Y
Abstract Bases as Binary
Interfaces
IClassX Problem:
• Binary interface can be compiler dependent
virtual void f(int b) = 0
virtual int g(int c) = 0
Solution:
The binary firewall imposed by the interface class can
not use compiler-variant language features.
ClassX
• No data members (attributes)
Assumption:
All compilers on a given platform produce equivalent machine
code for the virtual function call mechanism !!!
Object Extensibility
The techniques presented so far allow clients:
• Select and load binary components dynamically. This means their
implementation can evolve over time without recompilation of the
client.
However:
• The interface of an object cannot evolve over time, because of the
compilation against the signature of the interface class.
Problem:
Interfaces must be immutable and cannot change once published.
Solution:
Allow an implementation class to expose more than one interface.
Problem:
It’s hard to keep track off the number of references to an object
(needed to manage the lifetime).
Solution:
We allow object to manage its own lifetime !
What have we done?
LookUpWord( )
AddToDictionary( )
RemoveFromDictionary( )
Client2
GetSynonym( )
New Interface
COM Server Implementation
CLSID and IID generation
Viusalstudio\common7\tools\guidgen.exe
Registration of CLSID
HKEY_CLASSES_ROOT\CLSID directory
RegSvr32.exe
Calls DllRegisterServer() function of DLL:
Interface implementation
Add(), Sub()
CoClass imlementaion
Addref()
Release()
QueryInterface()
Add(), Sub()
Class Factory Implementation
O/S calling function implementation and DEF file editing
DllUnRegisterServer()
DllRegisterServer()
DLLGetClassObject()
CoClass
(Component Object Class)
Consists
interfaces
its implementation
CLSID
COM Object
Class Factory
CoClass
Generats CoClasses in a DLL
Interface: IClassFactory
Methods: CreateInstance, LockServer