Nancy Winnick Cluts
Developer Technology Engineer
Microsoft Corporation
February 27, 1997
I learned COM when I needed to create shell extensions for my book, Programming the Windows 95 User Interface . (Get that shameless plug in early, I always say). The current crop of tools for creating COM objects wasn't available, so I had to do most of the hard work myself. Today, I just use Microsoft® Visual C++® and create ActiveX controls using the OLE Control Wizard. This tool creates the basic framework (code) and registry requirements for a stub ActiveX control.
COM objects are either implemented within executables (EXEs) or within Dynamic Link Libraries (DLLs). COM objects implemented in EXEs are called local servers, while those implemented in DLLs are called in-process servers. An in-process COM server exposes its functions so that outside applications can use the functionality of its DLL.
The COM library uses a class identifier (a CLSID value) to uniquely identify each COM object. An application then uses this identifier to determine which object the application wants to use. For example, if you create and register a COM object that provides functionality akin to the Microsoft Windows® 95 tree-view control--showing, let's say, a Web-site hierarchy, once you registered this object, other applications can call the functions you expose in it.
Because ActiveX controls are COM objects, you can provide this control (with all the appropriate documentation, of course) as an ActiveX control, and Web developers can place it on their pages and use scripting to activate it. Now wouldn't it be loverly if some smart cookie wrote something like that?
ActiveX is a broad set of Internet technologies based on the COM object model. COM is what allows ActiveX objects to interoperate across networks (intranets and the Internet). When COM is working across networks, it is called Distributed COM (DCOM). COM provides the aggregation (the way in which one object can make use of another object) for ActiveX. COM also provides the mechanism for packaging the parameters to functions (known as marshalling) so that those parameters can be passed across processes (and machines!).
ActiveX relies on an open industry protocol as the basis for its cross-machine infrastructure standards, and it is language- and tool-independent. For example, COM uses the Open Software Foundation's (OSF) DCE Remote Procedure Call (RPC), so tool vendors other than Microsoft can use this technology. You don't have to use Microsoft tools to create ActiveX objects (of course, I wouldn't object if you did). You aren't limited to Windows as your operating system, either: ActiveX is a cross-platform solution that will work on many of the popular systems including Unix, your Macintosh, Windows 95 and Windows NT 4.0, and even on Windows NT 3.51 and Windows 3.1. You aren't limited to C as your language of choice; COM objects are supported in a variety of languages, including Java, Visual C, Visual Basic®, PASCAL, and (gasp!) COBOL !
COM objects are reusable as binary components. Once you write an application that uses the object, it won't have to recompile the object to use it. Someone can install your ActiveX control and immediately start scripting to use it.
COM provides reference-counting for objects. One copy of the object is loaded and a count is kept on the object each time the object is used (referred to). When the reference count for an object goes to zero, the object knows that it is no longer in use, and the object can be deleted and the resources it is using can be freed.
The Java virtual machine (VM) for Microsoft Internet Explorer is an ActiveX control. ActiveX automatically exposes Java classes as ActiveX controls, which integrates the Java language with scripting and other languages. COM does the hard work by wrapping the Java VM.
Nancy Winnick Cluts recently turned down the Nobel Prize in literature because the press tour might have cost her a shot at Mother of the Year honors. She next plans to raise kangaroos on her ranch.
Want someone to walk you through creation of COM objects? A good place to start is the ActiveX Tutorial Samples in the MSDN Online Web Workshop. These samples (and associated white papers) will help you create basic COM objects. The tutorial builds on itself--which means that you keep adding functionality and building on your knowledge base. Other technical articles and resources available that might help you understand COM are:
ActiveX Software Developer's Kit
The Component Object Model Specification
Inside COM by Dale Rogerson (MS Press, ISBN 1-57231-349-8)
For technical how-to questions, check in with the Web Men Talking, the MSDN Online Web Workshop's answer pair.