A Quick Tour of COM

 
Chapter 17 - COM Interoperability
bySimon Robinsonet al.
Wrox Press 2002
  

COM stands for Component Object Model. For newcomers to the Windows platform, understanding how COM works can be somewhat inscrutable, even if you're a devotee of CORBA. The advent of .NET and .NET components may allow you to avoid the intricacies of COM programming.

COM provides a modular, object-oriented approach to code reuse. It defines standard ways of locating and identifying the functionality of other components, and the components can be written in and used from a variety of languages.

However, COM components are not particularly easy to code, with the functionality offered by the component dependent on the language used to code it. Another particular problem with COM components is that they can be difficult to deploy. Developers of COM server components are supposed to ensure that new versions of their components are compatible with older versions, but they sometimes fail at this, and the installation of a new application that references a new version of a COM component can suddenly cause existing applications to fail. Problems of this variety are known as DLL Hell, and are the cause of a lot of head-scratching and wasted time. As we discussed in Chapter 8, .NET assemblies are a solution to this problem, making componentized architecture more accessible to everyday programmers.

How COM Works

To understand why COM components and .NET components aren't innately compatible, it helps to have a general understanding of how COM works. A grossly simplified explanation follows . For more detailed information of how COM works, see Professional ATL COM Programming from Wrox Press (ISBN 1-861001-40-1).

COM imposes a standard for the interfaces through which client code talks to component classes. Because client code communicates with component classes only through these standardized interfaces, it can remain blissfully ignorant of the language-specific details of how those component classes are implemented.

The component's IUnknown interface helps maintain a reference count of the number of clients using the component. When this reference count drops down to zero, the component can unload itself. All COM objects must implement the IUnknown interface. Reference counting is handled by the AddRef() and Release() methods of IUnknown , and interface discovery is handled by its QueryInterface() method. Furthermore, by implementing interfaces recognized by COM+ Services, a COM class can make use of prewritten functionality for security, object pooling, and resource conservation.

A component's class and its interfaces can be uniquely identified by a GUID. When a component is registered, these GUID values are written to the Registry and contain mappings to corresponding information on the location of the component and other attributes such as its threading model, for example. When a client creates a component, COM uses these GUIDs in the Registry to locate and bind to the components.

  


Professional C#. 2nd Edition
Performance Consulting: A Practical Guide for HR and Learning Professionals
ISBN: 1576754359
EAN: 2147483647
Year: 2002
Pages: 244

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net