Notes about Microsoft COM

Gene Michael Stover

created Sunday, 20 July 2003
updated Sunday, 20 July 2003

Copyright © 2003 by Gene Michael Stover. All rights reserved. Permission to copy, store, & view this document unmodified & in its entirety is granted.


Contents

1. Introduction

For some reason I don't fully understand, I, Gene Michael Stover, effectively a Microsoft-hater, have become interested in Microsoft COM. Some irrational part of my brain motivates me to consider implementing COM for Lisp on non-Windows operating systems. So herein are notes I have gathered about COM.

These notes might be useful to other experienced programmers who know they could understand COM fully, inside & out, in just a few hours if only they could find a source of documentation that cut through the crap, hype, & tutorials, & spewed the important parts.

2. The Vision

I'm thinking about implementing Microsoft COM for Lisp. Out-of-proc only, so I guess it is a DCOM system. Anyway, I'm thinking of doing it. I'm not sure why; maybe just because I can't figure out why no one has implemented COM for non-Microsoft platforms. I am also aware that Microsoft is phasing-out COM. Yet I still think of writing DCOM for Lisp.

I picture something like this on the Lisp client side. Let's say there is a service on your computer that I can access with DCOM. I might need the DLL to get type information, which is somewhat silly because it is out-of-proc only, but wouldn't a Windows programmer need the DLL, too?

So I, Lisp programmer, might do this:

;; I want a client to connect to the "WizBang" COM
;; service on your.computer.com.  I already have
;;  the DLL (or typelib) for WizBang on my computer.

;; Tell my Lisp DCOM client library to produce a
;; client library for WizBang.  Because Lisp is
;; dynamic & "self-programming", this function call
;; can create classes, messages, & methods.
;;
;; The first argument is the name I want the library
;; to have in my Lisp program (to avoid name collisions
;; with other libraries).  The second argument is the
;; DLL or TLB file with type information.
(create-client-library 'WizBang "wizbang.dll")

;; CREATE-CLIENT-LIBRARY probably created functions &
;; a type for WizBang.  I probably need to program my
;; own wrapper functions function calls on WizBang
;; objects aren't eye-sores, but let's pretend that I
;; don't need to do that.  So let's pretend that
;; CREATE-CLIENT-LIBRARY created functions that look
;; just fine when I call them.

;; Create an instance of WizBang on Pavel's server.
;; (I think the actual COM term for this is
;; "activation", but I am not certain.)  Notice that
;; I must specify the server name & maybe some other
;; connection information.  So this is dynamic, with
;; little or no type-checking.  I _think_ I could make
;; Lisp do some dynamic type-checking, but that doesn't
;; matter now.
;; Also, it's possible that I'd need to translate the
;; WizBang class name to a GUID or whatever.  Those are
;; details that I think I can ignore for now.
(setq wb (com:cocreate "WizBang" "your.computer.com"))

;; Let's pretend that a WizBang can give me a list of
;; uh, strings or whatever.
(format t "~&The strings in the WizBang are ~A"
          (wizbang:get-strings wb))

;; Though Lisp has garbage collection, I need to tell
;; COM when I have finished using the WizBang.  I'll
;; call that "release" now.  I know there is a COM word
;; for it; can't remember if it's "release" or something
;; else.
(com:release wb)

All the magic happens in that CREATE-CLIENT-LIBRARY function. It reads the interface description from the DLL or type lib & creates a class, interface, & stub methods. It probably should re-use the generic functions that are defined elsewhere, maybe by another CREATE-CLIENT-LIBRARY that read a superclass's type lib. So it's not exactly as simple as I've shown, but I'll betcha it can be close to this.

Initially, I'll need to write some Lisp functions that read the type information from DLLs & type libraries. So I can see what is in those libraries.

3. Definitions

COM
Depending on how you look at it, COM contains all the other protocols, libraries, conventions, & techniques in this list, or it is the shared-library, ``in-proc'', implementation of Microsoft components. Because COM et al grew & evolved in good hacking style, as opposed to being defined from the start, it is difficult to be sure.

COM+
In spite of much confusion, COM+ appears to be a server-side environment for holding COM services & making them available to clients (presumably through DCOM), like ``containers''(?) for Java web services, but COM+ is not for web services. (Maybe dot-Nyet's CRL extends COM+ to use HTTP, SOAP, or other web-related protocols for transport.) COM+ offers many services to the COM services it contains, & it requires much from them. For example, it has a flexible but complex threading & transaction model. You could implement networked COM services without COM+, & I suspect that most COM clients need not be aware of the presence or absense of COM+ on the server side.

DCOM
The over-the-wire protocol for networked, ``out-of-proc'', components.

OLE
Object Linking & Embedding. Depending on whom you believe, either an early name for an early implementation of COM, or the feature of some Microsoft applications which motivated the creation of COM.

RPC
Remote Procedure Call. Was not first implemented by Microsoft.

4. What COM Is

Software can be re-used at compile-time (source code re-use), link time (compiler-specific binary code re-use), or run-time (compiler-independant, language-independant binary code re-use). (There are probably other ways, including cut-&-paste re-use at the source code level.) Software components allow re-use at run-time on the binary level.

Microsoft COM is Microsoft's implementation of components. It provides binary re-use at run-time that is mostly independant of the compiler. From some experienced Windows programmers I know, I hear it is almost transparently integrated into Visual Basic; it probably is one of the two or three features which make VB popular. It is more cumbersome to use in C++, but still works well.

Microsoft says that COM is, or soon will be, deprecated. It will be replaced by the dot-Nyet Common Language Runtime. That could mean a lot of things, though, because COM means a lot of things to different people & because dot-Nyet will remain backwardly compatible with COM.

COM can link components into the client's process. These are ``in-proc'' components & are effectively shared libraries with an object-oriented interface. (That's if COM means Microsoft software components. An alternative definition is that Microsoft software components can link components into the client's process via a component implementation called COM.) It requires the component to run on the same operating system that the client is running on.

5. DCOM

From the point of view of implementing Microsoft-style software components on a non-Windows operating system, where binary compatibility is impractical, DCOM is more interesting than in-proc COM. DCOM is the over-the-wire protocol for ``out-of-proc'', remote Microsoft component object messages.

I would think that DCOM, plus some explanation of semantics, is all that a programmer would need to implement COM on non-Windows operating systems.

The official DCOM protocol documentation is []. Though Microsoft congratulated itself in 1996 for opening that protocol to the world, & though there are references to it on Microsoft's web site, the DCOM protocol document is not on the World Wide Web, & I have looked for it in a recent (circa 2003) issue of Microsoft Developer's Network (MSDN) without success.5.1

5.1 DCOM Documentation Online

  1. http://www.globecom.net/ietf/draft/draft-brown-dcom-v1-spec-03.html. A friend was able to find a draft of the DCOM protocol specification online. It is at http://www.globecom.net/ietf/draft/draft-brown-dcom-v1-spec-03.html, & I have saved a local copy in case that link dies. According to the distribution statement in the document, I'm pretty sure it is legal for me to keep a local copy of the document & make it available to anyone.

  2. http://www.microsoft.com/com/tech/DCOM.asp. The entry point to DCOM documentation in Microsoft's documentation on the web.

  3. ``DCOM Architecture'', http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndcom/html/msdn_dcomarch.asp. Some useful information, though no information about the binary protocol that is DCOM.

I read somewhere online (probably in one of the DCOM documents at Microsoft), that DCOM is derived from DCE RPC. Maybe I can figure out enough of the DCOM protocol if armed with knowledge of DCE RPC.

  1. ``What Is DCE RPC?'', http://rsusu1.rnd.runnet.ru/alpha/progtool/dce31unx/overview/Dceint63.htm. Sounds like DCE RPC is Sun RPC with some extra security bits & a UUID feature.

  2. The Open Group Portal to the World of DCE, http://www.opengroup.org/tech/dce/. Aha, so DCE RPC is part of a much larger distributed computing ``environment'', claimed to be open & therefore shrouded in much obfuscation.

  3. DCE 1.1: Remote Procedure Call, http://www.opengroup.org/pubs/catalog/c706.htm. So the specification is available. The HTML version is online & free, though you must register to see it: http://www.opengroup.org/online-pubs?DOC=009629399&FORM=HTML. Looks like a decent document, but they sure made it big. Sun RPC is a short, fun paper, for god's sake. Can't people re-learn terseness?

  4. There is an implementation of DCE RPC for Linux. http://www.netwaysglobal.com/DCE/.

If I could get the damned DCOM protocol document, implementing it for Lisp would be easy. As it is, I'd have to read the DCE RPC document5.2, then apply that knowledge while I use a protocol analyzer to watch DCOM messages on my network. Hell, I'd have to borrow a Windows computer from a friend, too5.3. Sadly, it's one of those projects that would be fun but is made nearly infeasible due to lack of good documentation. I'll keep looking, but I'm not hopeful.

6. So Maybe dot-Nyet Instead?

I suppose I could write the same kind of library I want but for SOAP & other more modern, ``web service'' types of components. dot-Nyet is similar to that, or uses one of those, or is one of those, so I could get a non-Windows dot-Nyet-style components library that way, maybe. And aren't the internal protocols of dot-Nyet open? Might be worth a try. Might be useful to have, too, whereas a COM implementation for non-Windws platforms (& in Lisp, yet) would be ``kinda cool, but why not ten years ago?''.6.1

I searched Microsoft's web site for ``.net component protocol'' & some variations of that. I don't see anything that looks like the dot-Nyet equivalent of the DCOM protocol specification. If not, then Microsoft intends to keep their protocol closed. There are plenty of documents about security & some higher-level protocols, but how about the packet format for an RPC message?

Here are the documents that search revealed which might be useful. (So this is my reading list for 20 July 2003.)

  1. Core Protocol Stack Components (Windows CE .NET Application Development), http://msdn.microsoft.com/library/en-us/wcetcpip/html/cmconcoreprotocolstackcomponents.asp. Might be useful, but might also be specific to Windows CE.

  2. ``Advanced Basics: COM+ and MTS, DCOM and MSMQ, Serialization in .NET'', MSDN Magazine, February 2002, http://msdn.microsoft.com/msdnmag/issues/02/02/basics/default.aspx. The ``DCOM'' & ``serialization'' suggest promise, but the article has no information about protocols.

Using Google to search for permutations of ``binary protocol .net component'' revealed nothing useful. Everyone wants to explain the cleverness of proxies, & some talk about the APIs of the COM, DCOM, or whatever libraries, but nobody talks about the over-the-wire protocol. What gets me is that what they talk about is the complex stuff; interpretation of a package is easy stuff (for a programmer), but they don't even gloss over it. They treat it like it's magic, too complex for people to understand.

It's again appearing to me as though this would be a good, fairly simple project if I could get the documentation for the protocol, but someone is keeping it a secret (though Microsoft did congratulate itself in 1996 for opening the DCOM protocol to the public). Because of this shitty proprietary secrecy, a more feasible project would be a web services library for Lisp. It could do the same things conceptually: obtain a service description then create client (proxy) classes & methods for it.

Bibliography

Gene Michael Stover 2008-04-20