html5-img
1 / 28

Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation

Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation. Agenda. “Fundamentals of COM” components “Fundamentals of MTS” distributed, component-based applications “COM+ Architecture” future directions for COM, MTS. Agenda. Why COM? Programming Model Sample Code

havard
Download Presentation

Fundamentals of COM Mary Kirtland Program Manager COM Team Microsoft Corporation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fundamentals of COMMary KirtlandProgram ManagerCOM TeamMicrosoft Corporation

  2. Agenda • “Fundamentals of COM” • components • “Fundamentals of MTS” • distributed, component-based applications • “COM+ Architecture” • future directions for COM, MTS

  3. Agenda • Why COM? • Programming Model • Sample Code • Next Steps

  4. Why COM? • 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 • User-Interface Controls • Line-of-business applications • Manufacturing process control • etc...

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

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

  7. 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

  8. Object 2 COM Programming Model Object 1 Client

  9. COM Identifiers • text strings not unique, slow • 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

  10. Interfaces • 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 /* IID 69B4985B-312D-11D1-835C-00C04FB957D8 */ interface IWordCount : public IDispatch { HRESULT CountWords(BSTR sentence, LPLONG words); };

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

  12. QueryInterface • essential for multiple independent interfaces • 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

  13. IUnknown ISpeakMandarin Object ISpeakFrench ISpeakEnglish QueryInterface (2) Client A QI(ISpeakSpanish) QI(ISpeakFrench) Client B QI(ISpeakMandarin) Client C GetInterfaceList QI(ISpeakEnglish)

  14. Reference Counting • Determines object’s lifetime • 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

  15. COM Classes • named, concrete implementation of one or more interfaces • named by a Class Identifier, or CLSID • associate a class factory with every class • implements IClassFactory • entrypoint to the class

  16. Creating Objects • create a class factory and call IClassFactory::CreateInstance • each class factory creates one type of object • COM APIs hide the details • CoGetClassObject • CoCreateInstance, CoCreateInstanceEx

  17. Object COM Programming Model Component IUnknown Class Factory Client IClassFactory Registration Packaging

  18. Where can a component live? “Marshaling” across process boundary via RPC Client Local Component (EXE) RPC RPC RemoteComponent on another machine Direct function Calls In-ProcessComponent (DLL) RPC RPC “Marshaling” across machine boundary via networked RPC

  19. COM Runtime Components and Applications The COM Runtime Core Services(Monikers, Storage, Data Transfer,...) [D]COM Registry Pluggable Security(SSPI) MS-RPC Pluggable Transports NTLM DCE Kerberos ETC... TCP UDP IPX Tunneled TCP ETC...

  20. COM Runtime • 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 • Implemented in OLE32.DLL/RPCSS.EXE

  21. The SCM • starts server processes and loads DLL implementations at activation-time • finds desired object and gets out of the way • 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

  22. Sample Code “Island Hopper” util_WordCount (ATL, C++) util_TakeANumber (VB)

  23. Util_Takeanumber bus_Ad db_Ad db_Invoice bus_Invoice db_Customer bus_Customer db_Category Util_TNUpdate Util_Wordcount MTS TakeaNumber Categories Customers Ads Invoices Island Hopper App. Utilities Accounting Classifieds

  24. Automation IDispatch Type Libraries Monikers Persistence IStorage, IStream Remoting DCOM Security Threading Next Steps

  25. Call To Action • Use COM to build component-based applications today • Understand the programming model and what your tools do for you • Use resources to learn more about COM

  26. Resources • On the web… • http://www.microsoft.com/com/ • http://www.microsoft.com/msdn/ • 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)

  27. http://www.microsoft.com/msdn/pdc

More Related