Presentation is loading. Please wait.

Presentation is loading. Please wait.

Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation.

Similar presentations


Presentation on theme: "Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation."— Presentation transcript:

1

2 Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation

3 Fundamentals of COM Slide 3 Agenda “Fundamentals of COM” “Fundamentals of COM”  components “Fundamentals of MTS” “Fundamentals of MTS”  distributed, component-based applications “COM+ Architecture” “COM+ Architecture”  future directions for COM, MTS

4 Fundamentals of COM Slide 4 Agenda Why COM? Why COM? Programming Model Programming Model Sample Code Sample Code Next Steps Next Steps

5 Fundamentals of COM Slide 5 Why COM? Imagine a world where developers can assemble applications from existing, reusable, pieces of code... Imagine a world where developers can assemble applications from existing, reusable, pieces of code...  “component” -- a reusable, binary, piece of software that provides a service Scenarios Scenarios  User-Interface Controls  Line-of-business applications  Manufacturing process control  etc...

6 Fundamentals of COM Slide 6 Component Architecture What would the requirements be? What would the requirements be?  component interoperability  Robust evolution (versioning)  Language independence  Location transparency  Scalability COM does all of these things! COM does all of these things! Tools choose how to expose COM Tools choose how to expose COM

7 Fundamentals of COM Slide 7 COM Fundamental Principles What the designers of COM were striving for... Binary components Binary components  Any programming language  Any location (in-process, cross-process, cross-machine)  No centralized authority Zero sacrifice in-proc performance Zero sacrifice in-proc performance Simplest model possible Simplest model possible  Enable extensibility and adaptability

8 Fundamentals of COM Slide 8 COM Principles Rigorous Encapsulation Rigorous Encapsulation  Black box -- no leakage of implementation details  All object manipulation through strict interfaces Polymorphism Polymorphism  via multiple interfaces per class  “Discoverable”: QueryInterface

9 Fundamentals of COM Slide 9 COM Programming Model Client Object 1 Object 2

10 Fundamentals of COM Slide 10 COM Identifiers text strings not unique, slow text strings not unique, slow Globally Unique Identifiers (GUIDs) are 128-bit integers Globally Unique Identifiers (GUIDs) are 128-bit integers  statistically guaranteed to be unique  each interface has a unique GUID (IID)  each class has a unique GUID (CLSID) GUIDs can be mapped to text strings GUIDs can be mapped to text strings

11 Fundamentals of COM Slide 11 Interfaces An interface is a group of related functions that specifies a contract An interface is a group of related functions that specifies a contract  once published, can never change  establishs a protocol for object communications Each interface is identified via an Interface Identifier or IID Each interface is identified via an Interface Identifier or IID /* IID 69B4985B-312D-11D1-835C-00C04FB957D8 */ interface IWordCount : public IDispatch { HRESULT CountWords(BSTR sentence, HRESULT CountWords(BSTR sentence, LPLONG words); LPLONG words); };

12 Fundamentals of COM Slide 12 IUnknown Every COM component must implement IUnknown Every COM component must implement IUnknown  all COM interfaces derive from IUnknown Provides... Provides...  object lifetime (AddRef, Release)  feature discovery (QueryInterface) interface IUnknown { HRESULT QueryInterface([in] REFIID riid, HRESULT QueryInterface([in] REFIID riid, [out, iid_is(riid)] void **ppv); [out, iid_is(riid)] void **ppv); ULONG AddRef(void); ULONG AddRef(void); ULONG Release(void); ULONG Release(void);};

13 Fundamentals of COM Slide 13 QueryInterface essential for multiple independent interfaces essential for multiple independent interfaces enables run-time discovery of features enables run-time discovery of features  component and client communicate in the richest way they share in common  New functionality can be added with full backwards compatibility

14 Fundamentals of COM Slide 14 QueryInterface (2) ObjectIUnknownISpeakMandarin ISpeakFrench Client A QI(ISpeakSpanish) QI(ISpeakFrench) Client B QI(ISpeakMandarin) Client C GetInterfaceListISpeakEnglishQI(ISpeakEnglish)

15 Fundamentals of COM Slide 15 Reference Counting Determines object’s lifetime Determines object’s lifetime All objects keep track of a ‘reference count’ All objects keep track of a ‘reference count’  AddRef increments by one  Release decrements by one  When the implementation of Release sees a reference count of zero it frees the object from memory

16 Fundamentals of COM Slide 16 COM Classes named, concrete implementation of one or more interfaces named, concrete implementation of one or more interfaces named by a Class Identifier, or CLSID named by a Class Identifier, or CLSID associate a class factory with every class associate a class factory with every class  implements IClassFactory  entrypoint to the class

17 Fundamentals of COM Slide 17 Creating Objects create a class factory and call IClassFactory::CreateInstance create a class factory and call IClassFactory::CreateInstance  each class factory creates one type of object COM APIs hide the details COM APIs hide the details  CoGetClassObject  CoCreateInstance, CoCreateInstanceEx

18 Fundamentals of COM Slide 18 Component COM Programming Model Client ClassFactory IClassFactory IUnknown RegistrationPackaging Object

19 Fundamentals of COM Slide 19 Where can a component live? Client In-Process Component (DLL) LocalComponent(EXE) RPC Direct function Calls “Marshaling” across process boundary via RPC “Marshaling” across machine boundary via networked RPC Remote Component on another machine RPC RPCRPC

20 Fundamentals of COM Slide 20 COM Runtime The COM Runtime [D]COM Registry Pluggable Security (SSPI) NTLM Kerberos Pluggable Transports DCE MS-RPC TCPUDPIPXTunneled TCPETC... Core Services (Monikers, Storage, Data Transfer,...) Components and Applications

21 Fundamentals of COM Slide 21 COM Runtime COM library exposes the COM API to applications and provides several default implementations COM library exposes the COM API to applications and provides several default implementations  Implemented as OLE32.DLL Service Control Manager (SCM) starts server processes/loads server DLLs at activation-time Service Control Manager (SCM) starts server processes/loads server DLLs at activation-time  Implemented in OLE32.DLL/RPCSS.EXE

22 Fundamentals of COM Slide 22 The SCM starts server processes and loads DLL implementations at activation-time starts server processes and loads DLL implementations at activation-time finds desired object and gets out of the way finds desired object and gets out of the way For inprocess objects, no third-party is involved in client->object communications For inprocess objects, no third-party is involved in client->object communications For out-of-process objects, a client-side proxy sends packets to a server-side stub For out-of-process objects, a client-side proxy sends packets to a server-side stub

23 Fundamentals of COM Slide 23 Sample Code “Island Hopper” util_WordCount (ATL, C++) util_TakeANumber (VB)

24 CustomersInvoicesAdsCategoriesTakeaNumber Island Hopper MTS Classifieds bus_Ad db_Ad db_Category Accounting bus_Customer db_Customer bus_Invoice db_Invoice App. Utilities Util_Takeanumber Util_TNUpdate Util_Wordcount

25 Fundamentals of COM Slide 25 Next Steps Automation Automation  IDispatch  Type Libraries Monikers Monikers Persistence Persistence  IStorage, IStream Remoting Remoting  DCOM  Security  Threading

26 Fundamentals of COM Slide 26 Call To Action Use COM to build component-based applications today Use COM to build component-based applications today Understand the programming model and what your tools do for you Understand the programming model and what your tools do for you Use resources to learn more about COM Use resources to learn more about COM

27 Fundamentals of COM Slide 27 Resources On the web… On the web…  http://www.microsoft.com/com/  http://www.microsoft.com/msdn/ In print… In print…  “Understanding ActiveX and OLE” (David Chappell, MSPress)  “Inside COM” (Dale Rogerson, MSPress)  “The Component Object Model” (Don Box, Addison-Wesley)  “Professional DCOM” (Richard Grimes, WROX)

28 ™ http://www.microsoft.com/msdn/pdc


Download ppt "Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation."

Similar presentations


Ads by Google