This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.


October 1998

Microsoft Systems Journal Homepage

Don Box is a co-founder of DevelopMentor where he manages the COM curriculum. Don is currently breathing deep sighs of relief as his new book, Essential COM (Addison-Wesley), is finally complete. Don can be reached at http://www.develop.com/dbox/default.asp.

People often approach me at conferences and seminars asking for book recommendations. So this month, I'll examine the 20 most useful resources I know of for the working COM and Microsoft Transaction Server (MTS) developer. Oddly enough, there are no COM or MTS programming books on this list. I tend to think that the books I have listed here are far more useful for learning to think like a COM/MTS developer than any COM or MTS programming book around (including my own).
      One category that is conspicuously absent from this list is object-oriented design books. If your goal is to build distributed object systems, you need to put at least as much emphasis on the "distributed" aspects of your system as you do the "object" aspects, as the former are what will ultimately determine the performance, reliability, and correctness of your system. This is not to say that encapsulation, polymorphism, and inheritance are not applicable to COM. In fact, COM design is based on these concepts. But naïvely applying the techniques and "patterns" touted in popular OO design books to distributed systems will inevitably lead to poor performance at best and incorrect software at worst.
      I can't recommend these books highly enough (and no, I receive no kickbacks for any purchases this column may inspire).

Inside the C++ Object Model
Stanley B. Lippman
1996, Addison Wesley Longman
ISBN 0-201-83454-5
      COM programmers who use C++ have a difficult lot in life: C++ is daunting enough without COM. When COM is added to the mix, you're forced to become much more conscious of the semantics of the language, as COM is well-known for exploiting many of the more esoteric and underdocumented aspects of C++. This somewhat hard-to-find book does a fantastic job explaining the semantics of the programming language as well as the runtime behavior of language features that COM programmers use every day.
      Inside the C++ Object Model was written by one of the implementors of CFRONT, the original C++ translator from AT&T. Because of this, the book is packed with explanations of how compilers transform C++ code into executable statements. Especially useful is the discussion of construction and object layout, which has special significance for readers wishing to understand why the __declspec(novtable) (also known as _ATL_NO_ VTABLE) in Visual C++® is an important but somewhat dangerous optimization.
      Lippman offers a great treatment of virtual functions and multiple inheritance, exposing the techniques used to recover the this pointer prior to jumping to the object's actual method code. In particular, his treatment of adjustor thunks makes it clear why the following code

 class DogCat : public IDog, public ICat {
      STDMETHODIMP 
      QueryInterface(REFIID riid, void**ppv) {
             if (riid == IID_IUnknown)
                     *ppv = static_cast<IDog*>(this);
 .
 .
 .
yields faster results than this semantically equivalent code:

 class DogCat : public IDog, public ICat {
      STDMETHODIMP 
      QueryInterface(REFIID riid, void**ppv) {
             if (riid == IID_IUnknown)
             *ppv = static_cast<ICat*>(this);
 .
 .
 .
      This book is difficult to find in bookstores, but well worth the time and money.

Advanced C++: Programming Styles and Idioms
James O. Coplien
1991, Addison Wesley Longman
ISBN 0-201-54855-0
      Scott Meyers calls this the LSD book: it's purple and your mind expands every time you use it. This book was very influential on my generation of C++ programmers and challenges me every time I read it. Most notable to COM developers is Coplien's discussion of handle classes (which in many ways resemble interface pointers) and exemplars.

Effective C++, Second Edition
Scott Meyers
1997, Addison Wesley Longman
ISBN 0-201-92488-9
      Scott Meyers is one of the most readable authors around, and this book exemplifies Scott's natural, non-intimidating style. Effective C++ contains fifty rules of thumb that, once read, seem completely obvious. That's because Meyers does a great job of making something as complex as C++ seem fairly basic and understandable.
      Of particular note to COM folks is rule 14, which warns developers to make the destructor of a class virtual if that class has at least one virtual function. This ensures that the most-derived destructor will be invoked when a call to the delete operator is made on a base reference or pointer type. Knowledge of this rule (and where COM does not adhere to it) keeps developers from making the following mistake:

 HRESULT MakeOne(REFIID riid, void **ppv) {
     IUnknown *pUnk = new MyClass();
     if (pUnk == 0)
           return (*ppv = 0), E_OUTOFMEMORY;
     HRESULT hr = pUnk->QueryInterface(riid, ppv);
     if (FAILED(hr))
           delete pUnk; // hmmmm...
     return hr;
 }
Note that the delete call is issued through an IUnknown *, which means that no destructors will be called (since IUnknown doesn't have a virtual destructor). This is by no means the only relevant item, but it is a great example of the importance of C++ correctness to even the simplest of COM programs.
      If you are ever feeling overly enthusiastic about the C++ programming language (which may happen after you read this book), I encourage you to pick up Meyers' sequel, More Effective C++, which portrays a much darker picture of the language than this rather happy first volume.

Large Scale C++ Software Design
John S. Lakos
1996, Addison Wesley Longman
ISBN 0-201-63362-0
      Every COM programmer should read the middle section of this book. It does a better job of describing the problems with the C++ compilation and linkage model than any other text I have found. Lakos introduces the notion of protocol classes (which are stylized abstract base classes) to reduce coupling between modules in a large code base. While this technique will seem extremely familiar and obvious to any C++ developer currently using COM, this book makes a great case for the interface-based programming style that is at the core of the COM programming model.

The Design and Evolution of C++
Bjarne Stroustrup
1994, Addison Wesley Longman
ISBN 0-201-54330-3
      Known as the "D and E," this book is a fascinating read that chronicles the history and culture of C++. While it is hard to imagine a professional C++ programmer not owning all three Stroustrup books (The C++ Programming Language and The Annotated C++ Reference Manual being the other two), I find myself constantly recommending this book in particular, as it is great even for novice programmers.
      Particularly interesting to COM developers is Stroustrup's discussion of dynamic_cast and why there is no IsKindOf operation in the language. Of tangential interest to any Windows®-based developer is the discussion of why and how resumptive exception handling was rejected by the ISO/ANSI committee.
      One can only hope that someday a former COM program manager or architect will tell the story of COM's development and evolution. Friendship and loyalty prevent me from publishing the name or email address of the most likely candidate, but I am hopeful that he will someday step up to the plate and commit to paper the rich history of COM.

The Java Virtual Machine Specification
Tim Lindholm and Frank Yellin
1996, Addison Wesley Longman
ISBN 0-201-63452-X
      The COM+ runtime model will probably assimilate many aspects of the Java virtual machine (JVM). Given this likelihood, now is a great time to familiarize yourself with how JVMs actually work. (Even if COM+ turns out completely different, it is still useful to see how the other half lives.) This book gave me a new appreciation for how the COM programming model hangs together. I learned how much the Service Control Manager resembles a Java class loader, at least from the outside looking in. In many ways, this book parallels Lipmann's Inside the C++ Object Model, as it leaves no stone unturned as to the runtime behavior of even the simplest of programs.

Essential JNI
Rob Gordon
1998, Prentice Hall
ISBN 0-13-679895-0
      Yes, I know, the Microsoft® JVM doesn't use Java Native Interface and perhaps never will. Nonetheless, this book offers a perspective on how JVMs work that is complementary to the JVM specification. Unlike Microsoft J/Direct, which allows Java programmers to simply annotate their Java source files to indicate which DLLs export which native methods (much like an intrinsic import library), JNI is a COM-like interface into Sun's JVM that allows native code implementors to reach into the virtual machine and more tightly integrate into the Java runtime model. COM programmers will recognize Sun's homage to COM, as the Sun JVM exposes its functionality to JNI DLLs via a very COM-like interface. (OK, so they forgot QueryInterface this time around.) JNI's assumption of "one vtable format per platform" parallels that of COM and validates the basic binary format of a COM interface.

Computer Networks, Second Edition
Andrew Tannenbaum
1988, Prentice Hall
ISBN 0-13-162959-X
      The newer third edition of this classic text on networking is out, but I think that the second edition is more valuable to a developer working with any distributed object system, be it COM, CORBA, or RMI. The second edition was organized around the infamous OSI seven-layer stack, with each layer getting its own chapter (OK, layer 2 got two chapters). When the second edition was published in 1988, it looked as if the OSI protocol suite would sweep the world and become the lingua franca of computer communications. Unfortunately, while the OSI standards committees were traveling to exotic locations to argue about how to draw state diagrams, a bunch of neck-bearded researchers and hackers in the U.S. crafted a protocol suite called TCP/IP, and the rest is history. (Funny how you are not using OSI TP-4 when you surf the Web.)
      Despite the fact that many of the protocols discussed in the second edition are now dinosaurs, this book is still useful because it explains networking in terms of the basic OSI model. The OSI model has long outlived the underlying protocols and can be readily observed in both COM and in CORBA. This book provides a breadth of coverage not present in the other networking books I am recommending here.

Internetworking with TCP/IP Volume I
Principles, Protocols, and Architecture, Third Edition

Douglas E. Comer
1995, Prentice Hall
ISBN 0-13-2169878
      This is the book that introduced me (and many people) to the TCP/IP protocol suite. It's an extremely easy read and is the uncontested best tutorial on the protocols of the Internet. This is not a book about socket programming. Rather, the wire protocol and semantics of TCP, UDP, IP and their supporting cohorts are explained in a clear and concise manner. It is especially useful for COM developers to note how TCP connections are managed and how many packets must be exchanged to establish a single connection. Comer's discussion of TCP's three-way handshake goes a long way toward explaining why COM prefers UDP over TCP as its default transport.

TCP/IP Illustrated Volumes I, II, and III
W. Richard Stevens (and Gary R. Wright for Vol. II)
1994, 1995, 1996, Addison Wesley Longman
ISBN 0-201-63346-9/0-201-63354-X/0-201-63495-3
      If after reading the Comer book, you find yourself wanting more, this is the place to go. Volume I covers much the same ground as Comer, but from a much more detailed and performance-oriented viewpoint. Volume II discusses the Berkeley Unix implementation of TCP/IP. I was first exposed to this code base while in grad school; stepping though BSD internals forever influenced the way I think about writing networking code. Volume III is interesting (albeit less important) as it covers TCP for Transactions (a version of TCP that is optimized for fast connection management) and HTTP.

UNIX Network Programming
W. Richard Stevens
1997, Prentice Hall
ISBN 0-13-490012-X
      Don't let the title scare you. This is the definitive sockets programming book, even for developers using Windows (granted, those writing for Windows NT® shouldn't be using select, but that's a minor part of the book). Most developers currently building networked applications cut their teeth on the first edition of this book. Even though COM programmers can live rich and productive lives without ever calling socket, bind, listen, or accept, this book is useful for gaining an appreciation for how the basic communication primitives are exposed from the operating system. This book also has the honor of appearing in the movie "Wayne's World," which makes it an instant classic.

Microsoft RPC Programming
John Shirley and Ward Rosenberry
O'Reilly and Associates
ISBN 1-56592-070-8
      Several years ago, O'Reilly published several DCE RPC books. This was the last one to be released, and it is probably the best MS-RPC book around. Unfortunately, it is out of print, so you will probably have a hard time getting your hands on a copy. Many of the concepts in this book are applicable to COM programmers, but be aware that there are some minor differences between MS-RPC and COM (most notably the memory allocation rules for embedded pointers). If you can find a copy, snap it up.

DCE Security Programming
Wei Hu
1995, O'Reilly and Associates
ISBN 1-56592-134-8
      Here's yet another great O'Reilly book that is no longer in print. When I was trying to figure out how COM security worked, this book was an invaluable resource. More than half of DCE Security Programming is completely irrelevant to a COM programmer, but it was the only resource I could find that explained the DCE RPC security model and what each API function really meant. Armed with this knowledge, it was pretty easy to figure out exactly what CoInitializeSecurity was doing. Remember when you are reading this book that RpcBindingSetAuthInfo is the moral equivalent of CoSetProxyBlanket, and you will instantly see its relevance.

Principles of Transaction Processing
Philip A. Bernstein and Eric Newcomer
1997, Morgan Kaufman
ISBN 1-55860-415-4
      If you can only read one book on this list, make it this one. This book provides a high-level overview of the transactional programming model used by various systems, including MTS, part of Windows NT Server. The level of detail is somewhere between David Chappell's book and my book (which means it's exactly correct for most readers), and it gave me a great start in transactional programming. The chapter on locking made me wonder how developers can use only OS locking primitives and still write correct code. This chapter alone is worth the cover price.

Transaction Processing: Concepts and Techniques
Jim Gray and Andreas Reuter
1992, Morgan Kaufman
ISBN 1-55860-190-2
      I can't imagine not owning this book. That said, the Bernstein and Newcomer book is really a prerequisite for reading Transaction Processing. When I first fell into the world of MTS, I found both this book and Principles of Transaction Processing in a bookstore and mistakenly bought this one first. Perhaps if I had more of a background in databases and transaction processing, this would have worked out. Unfortunately, this book humbled me like none I have read in recent memory. Fortunately, after putting this book on the shelf for six months, I was able to come back and digest the relevant chapters. I find that this book makes a great complement to Bernstein and Newcomer, partially because the level of detail is considerably different, but also because Gray and Reuter's emphasis on the transaction really makes clear how the MTS programming model was intended to be used.

Inside Microsoft SQL Server 6.5
Ron Soukup
1997, Microsoft Press
ISBN 1-57231-331-5
      This title shows that Microsoft Press can still turn out books with the quality of Petzold, Richter, and Prosise. Yes, it is likely that future versions of SQL Server will render this book obsolete and inaccurate. Nonetheless, this book does an amazing job of documenting the internal architecture of a fairly complex piece of software. As I spend more time doing transactional programming, I find that I am constantly referring to the chapters on transactions and locking, which are to-the-point and extremely useful.

Joe Celko's SQL for Smarties:
Advanced SQL Programming

Joe Celko
1995, Morgan Kaufman
ISBN 1-55860-323-9
      Two years ago I had to teach myself SQL. I have a considerable stack of SQL books in my office. Had this been the first book I had found, I would have saved myself a considerable amount of time and money. This book is written in a way that doesn't insult the average programmer and immediately answered the questions that other books had left unanswered. After reading it, I felt as if I could actually write useful SQL-based applications. That feeling wore off rather quickly when I bought Celko's other book, Joe Celko's SQL Puzzles and Answers, which quickly put me back in my place as a SQL novice. Nonetheless, I still found SQL for Smarties spoke to me in my language, and I recommend it.

Understanding ActiveX® and OLE
David Chappell
1996, Microsoft Press
ISBN 1-57231-216-5
      This book is a great complement to the COM specification. It provides developers and managers alike with a clear, lucid explanation of all things COM (at least, all things COM in 1996 when the book was published). Chappell's description of the remoting architecture is perhaps the strongest part of this book. Because each paragraph is summarized in the margins, this book is uniquely suited to programmers as well as those who have been relegated to managerial duties. My only criticism of this book is that Chappell's discussion of reuse is centered on COM aggregation and containment. I hope that in a second edition, he takes the opportunity to recast aggregation and containment as identity hacks, which is the role they ultimately serve. This one minor flaw in an otherwise fantastic book doesn't diminish my opinion of either the book or the author.

The COM Specification
The DCOM Wire Protocol Specification
The DCE RPC Application Engineering Specification (AES)
COM Spec: http://www.microsoft.com/com
DCOM Wire Protocol Spec: http://www.microsoft.com/com
DCE RPC AES: http://www.opengroup.org
      To me, these three documents comprise a single story: the design and semantics of COM. To this day, no book has come close to matching the COM specification's conciseness and clarity. Granted, the COM spec is woefully out-of-date. However, the first set of chapters does an amazing job of laying out the motivation for COM as well as documenting the basics of the programming model.
      The last chapter of the COM specification documents the expected wire protocol for remote method invocation. This chapter has been replaced by the DCOM Wire Protocol specification. The DCOM Wire Protocol spec thoroughly explains the details of the Object RPC (ORPC) protocol used in today's DCOM.
      The DCE RPC AES is listed here as a companion piece, as it answers implementation questions that most RPC developers have, such as how does endpoint management work. I could imagine surviving without reading this one, but the COM spec (with the updated DCOM wire protocol spec) should be mandatory reading for all COM programmers irrespective of the language or tool they choose to work in.

Mr. Bunny's Guide to ActiveX
Carlton Egremont III
1998, Addison Wesley
ISBN 0-201-48536-2
      COM isn't just a technology. It's a programming model. It's a programming movement. It's a community and culture. This book is a vital part of COM culture. Presented as a dialog between Mr. Bunny (the expert) and Farmer Jake (the student), this refreshing book explains all things COM in a way that even my five-year-old son can appreciate.

Have a question about programming with ActiveX or COM? Send your questions via email to Don Box: dbox@develop.com or http://www.develop.com/dbox/default.asp.

From the October 1998 issue of Microsoft Systems Journal.