Introduction to COM and DCOM Organizational Communications and Technologies Prithvi N. Rao H. John Heinz III School of Public Policy and Management Carnegie Mellon University Readings Posting on the Class Web Site Objectives Present the basic features of COM and DCOM What is COM? Binary protocol by which software components can connect and communicate Language independent Platform independent Philosophy for architecting software components Programming discipline for component development Microsoft’s object technology Originally referred to as OLE What is COM? COM is a specification COM is a set of services COM supports modular programming COM is object-oriented (?) COM enables easy customization and upgrades to your application (?) COM supports distributed applications COM components can be written in a variety of languages Activex, OLE and COM OLE Embedding Linking Drag-and-drop Compound documents ActiveX Documents Controls Scripting Uniform data transfer Persistent storage monikers Automation COM Role of COM in the Model COM services provide foundations UDT is language and program independent data transfer Persistence provides for machine-independent standardized object persistence Monikers facilitate file namespace object identification across machines Automation facilitates COM object access from scripting clients The Role of COM in the Model Uniform Data Transfer COM Monikers Persistent Storage Automation Component Object Model Object-Linking-and-Embedding OLE services allow off-the-shelf app data interoperability Host (client/container) can edit/store foreign application (server) data via pre-defined set of COM interfaces Can be user initiated End-user-drag-drop of data between applications Object-Linking-and-Embedding In Place Activation (visual editing) Linking Embedding Drag and Drop ActiveX Services Binary packaging of in-proc components Deployed in windows/dialogs or in web pages Dynamically downloaded with page Web-based distribution pf documents IIS-aware Automation-aware pages (ASP) Component Object Model Interface Server Client (Container) Object Interface Pointer Distributed COM Process Boundary Network Boundary In-Proc Object (DLL) Client (DLL or EXE) Local Object (EXE) Remote Object (EXE) COM and DCOM DCOM is now a standard part of 32-bit Windows DCOM being propagated to other platforms as well NT 4.0+, Win98, Win95 with IE4 Solaris HPUX Digital’s VMS (in beta) Provides transparency for remote interfaces, parameters and return values COM and DCOM Reusable code is difficult to create even in C++ Traditional static link libraries have dependency deficiencies Windows dlls have their own set of limitations Need for a vendor independent strata for building reusable components Lack of Reusability Static Libraries Duplicated code on disk Duplicated code in memory No way to replace library without relinking and/or recompiling Dynamic Link Libraries (a better solution) Code resides only on one system Code only needs to be loaded once in memory Field replacement of implementation is possible COM Benefits Component based suggests more code re-use Smaller distributable components Replaceable components Binary compatibility and encapsulation Thin layers of abstraction Decoupling interface from implementation Decoupling object identity from implementation Dependency reduction in large projects COM Fundamentals COM defines What constitutes a COM object How com objects expose features for other components to use How this works across processes and across networks When objects are destroyed No specification about implementation Only describes behavior/characteristics pertinent to connecting/communicating with other objects Allows flexibility Permits implementation stay lightweight and languageindependent COM Principles Object services are accessed via interfaces Interfaces have identity Objects consist of interface implementation Objects have identity Objects must be registered COM Principles Objects have location independence Objects have implementation transparency Object services can be published via a type library Key COM Concepts Interfaces Objects Identity Registration Type Libraries What’s an Interface? An abstract data type containing pointers to a group of related function Contract between client and object Once published never changes Features/functionality only available via interfaces Object’s features expressed by the interface it implements Existing interfaces may be extended Contract between COM and object author Object implements all methods in interface What’s an Interface? A pointer to a table of pointers to methods No limit to the number of methods in an interface Strongly typed Transparency for DCOM implementation COM Identity COM components are associated with a unique ID Interface (IID) Objects (CLSID) Type libraries (TLID) Features/service groups of categories (CATID) Components defined by COM have pre-assigned Ids Each ID distinguishes a component from another Prevents collisions Supports versioning Accessed via ID Component IDs Generated by component author via development tools Guaranteed to be unique Uses machine ID, NIC date and time information to create 128 bit long integer id Referred to as GUID Guaranteed to be unique on all systems on the planet Can be created in multiple ways ::CoCreateGuid from COM API function GUIDGEN command line tool Development tools do this automatically Registration System registry Each COM object registry entry must specify Database of information about available objects in system May contain configuration information Updated when object is installed Entries organized by IDs Object’s CLSID Path to object’s server Object registry entries may also specify Human readable name Type Libraries Binary language-independent file Describes COM objects, interfaces, methods, data types and Ids of components in a server Created by component author during development Used by client authors during client development Compiled form a script written in DCE Interface Definition Language (IDL) TLB provide all essential details required for clients to invoke objects described COM Principles Objects accessed via Interfaces Interfaces have identity Objects composed of interface implementations Objects have identity Objects have location independence COM Principles Objects have implementation transparency Object services can be published via a type library COM Interface Rules Interface methods are abstract Interfaces never expose data All methods in an interface must be implemented Interface methods must return HRESULT Instantiating a COM Object Client calls a COM API function with object CLSID CoCreateInstance CoGetClassObject COM looks up object’s CLSID in registry COM finds the server pathname in the registry COM invokes the object’s server Server requests an object instance from the object’s class factory Server instantiates object Instantiating a COM Object Server returns pointer to object’s default interface to COM COM returns interface pointer to client Interoperability Issues CORBA/RMI? CORBA/DCOM? RMI/DCOM? Multiple Inheritance (CORBA) maps to Multiple Interfaces in DCOM Summary Examined relationship between COM, OLE and ActiveX Examined the features of COM Examined the principles of COM Presented the activation of COM objects Presented issues in interoperability