Home > Store

Effective COM: 50 Ways to Improve Your COM and MTS-based Applications

Register your product to gain access to bonus material or receive a coupon.

Effective COM: 50 Ways to Improve Your COM and MTS-based Applications


  • Sorry, this book is no longer in print.
Not for Sale



  • Readers will benefit from such insight and wisdom as: © Define your interfaces before you define your classes (and do it in IDL) © Design with distribution in mind © Dual interfaces are a hack. Don't require people to implement them © Don't access raw interface pointers across apartment boundaries © Avoid creating threads from an in-process server © Smart Interface Pointers add at least as much complexity as they remove © CoInitializeSecurity is your friend. Learn it, love it, call it © Use fine-grained authentication © Beware exposing object references from the middle of a transaction hierarchy © Don't rely on JIT activation for scalability


  • Copyright 1999
  • Dimensions: 7-3/8" x 9-1/4"
  • Edition: 1st
  • Book
  • ISBN-10: 0-201-37968-6
  • ISBN-13: 978-0-201-37968-6

In Effective COM, the authors, Don Box, Keith Brown, Tim Ewald, and Chris Sells, offer 50 concrete guidelines for creating COM based applications that are more efficient, robust, and maintainable. Drawn from the authors' extensive practical experience working with and teaching COM, these rules of thumb, pitfalls to avoid, and experience-based pointers will enable you to become a more productive and successful COM programmer.

These guidelines appear under six major headings: the transition from C++ to COM; interfaces, the fundamental element of COM development; implementation issues; the unique concept of apartments; security; and transactions. Throughout this book, the issues unique to the MTS programming model are addressed in detail. Developers will benefit from such insight and wisdom as:

  • Define your interfaces before you define your classes (and do it in IDL)
  • Design with distribution in mind
  • Dual interfaces are a hack. Don't require people to implement them
  • Don't access raw interface pointers across apartment boundaries
  • Avoid creating threads from an in-process server
  • Smart Interface Pointers add at least as much complexity as they remove
  • CoInitializeSecurity is your friend. Learn it, love it, call it
  • Use fine-grained authentication
  • Beware exposing object references from the middle of a transaction hierarchy
  • Don't rely on JIT activation for scalability

and much more invaluable advice.

For each guideline, the authors present a succinct summary of the challenge at hand, extensive discussion of their rationale for the advice, and many compilable code examples. Readers will gain a deeper understanding of COM concepts, capabilities, and drawbacks, and the know-how to employ COM effectively for high quality distributed application development. A supporting Web site, including source code, can be found at http://www.develop.com/effectivecom.



Source Code

Despite what your copy of Effective COM might claim, no source code is available for this book.

Addison-Wesley apologizes for this mistake.


Web Resources

Click below for Web Resources related to this title:

Sample Content

Table of Contents


Shifting from C++ to COM.







About the Authors.



The evolution of the Component Object Model (COM) has in many ways paralleled the evolution of C++. Both movements shared a common goal of achieving better reuse and modularity through refinements to an existing programming model. In the case of C++, the preceding model was procedural programming in C, and C++'s added value was its support for class-based object-oriented programming. In the case of COM, the preceding model was class-based programming in C++, and COM's added value is its support for interface-based object-oriented programming.

As C++ evolved, its canon evolved as well. One notable work in this canon was Scott Meyers' Effective C++. This text was perhaps the first text that did not try to teach the reader the basic mechanics and syntax of C++. Rather, Effective C++ was targeted at the working C++ practitioner and offered 50 concrete rules that all C++ developers should follow to craft reasonable C++-based systems. The success of Effective C++ required a critical mass of practitioners in the field working with the technology. Additionally, Effective C++ relied on a critical mass of supporting texts in the canon. At the time of its initial publication, the supporting texts were primarily The C++ Programming Language by Stroustrup and The C++ Primer by Lippman, although a variety of other introductory texts were also available.

The COM programming movement has reached a similar state of critical mass. Given the mass adoption of COM by Microsoft as well as many other development organizations, the number of COM developers is slowly but surely approaching the number of Windows developers. Also, five years after its first public release, there is finally a sufficiently large canon to lay the tutorial groundwork for a more advanced text. To this end, Effective COM represents a homage to Scott Meyers' seminal work and attempts to provide a book that is sufficiently approachable that most working developers can easily find solutions to common design and coding problems.

Virtually all existing COM texts assume that the reader has no COM knowledge and focus most of their attention on teaching the basics. Effective COM attempts to fill a hole in the current COM canon by providing guidelines that transcend basic tutorial explanations of the mechanics or theory of COM. These concrete guidelines are based on the authors' experiences working with and training literally thousands of COM developers over the last four years as well as on the communal body of knowledge that has emerged from various Internet-based forums, the most important of which is the DCOM mailing list hosted at DCOM-request@discuss.microsoft.com.

This book owes a lot to the various reviewers who offered feedback during the book's development. These reviewers included Saji Abraham, David Chappell, Steve DeLassus, Richard Grimes, Martin Gudgin, Ted Neff, Mike Nelson, Peter Partch, Wilf Russell, Ranjiv Sharma, George Shepherd, and James Sievert. Special thanks go to George Reilly, whose extensive copyediting showed the authors just how horrible their grammar really is. Any errors that remain are the responsibility of the authors. You can let us know about these errors by sending mail to effectiveerrata@develop.com. Any errata or updates to the book will be posted to the book's Web page, http://www.develop.com/effectivecom.

The fact that some of the guidelines presented in this book fly in the face of popular opinion and/or "official" documentation from Microsoft may at first be confusing to the reader. We encourage you to test our assertions against your current beliefs and let us know what you find. The four authors can be reached en masse by sending electronic mail to effectivecom@develop.com.

Intended Audience

This book is targeted at developers currently using the Component Object Model and Microsoft Transaction Server (MTS) to develop software. Effective COM is not a tutorial or primer; rather, it assumes that the reader has already tackled at least one pilot project in COM and has been humbled by the complexity and breadth of distributed object computing. This book also assumes that the reader is at least somewhat familiar with the working vocabulary of COM as it is described in Essential COM. The book is targeted primarily at developers who work in C++; however, many of the topics (e.g., interface design, security, transactions) are approachable by developers who work in Visual Basic, Java, or Object Pascal.

What to Expect

The book is arranged in six chapters. Except for the first chapter, which addresses the cultural differences between "100% pure" C++ and COM, each chapter addresses one of the core atoms of COM.

Shifting from C++ to COM

Developers who work in C++ have the most flexibility when working in COM. However, it is these developers who must make the most adjustments to accommodate COM-based development. This chapter offers five concrete guidelines that make the transition from pure C++ to COM-based development possible. Aspects of COM/C++ discussed include exception handling, singletons, and interface-based programming.


The most fundamental atom of COM development is the interface. A well-designed interface will help increase system efficiency and usability. A poorly designed interface will make a system brittle and difficult to use. This chapter offers 12 concrete guidelines that help COM developers design interfaces that are efficient, correct, and approachable. Aspects of interface design discussed include round-trip optimization, semantic correctness, and common design flaws.


Writing COM code in C++ requires a raised awareness of details, irrespective of the framework or class library used to develop COM components. This chapter offers 11 concrete guidelines that help developers write code that is efficient, correct, and maintainable. Aspects of COM implementation discussed include reference counting, memory optimization, and type-system errors.


Perhaps one of the most perplexing aspects of COM is its concept of an apartment. Apartments are used to model concurrency in COM and do not have analogues in most operating systems or languages. This chapter offers nine concrete guidelines that help developers ensure that their objects operate properly in a multithreaded environment. Aspects of apartments discussed include real-world lock management, common marshaling errors, and life-cycle management.


One of the few areas of COM that is more daunting than apartments is security. Part of this is due to the aversion to security that is inherent in most developers, and part is due to the fairly arcane and incomplete documentation that has plagued the security interfaces of COM. This chapter offers five concrete guidelines that distill the security solution space of COM. Aspects of security discussed include access control, authentication, and authorization.


Many pages of print have been dedicated to Microsoft Transaction Server, but precious few of them address the serious issues related to the new transactional programming model implied by MTS. This chapter offers eight concrete pieces of advice that will help make your MTS-based systems more efficient, scalable, and correct. Topics discussed include the importance of interception, activity-based concurrency management, and the dangers of relying on just-in-time activation as a primary mechanism for enhancing scalability.


First and foremost, Chris would like to thank his wife, Melissa, for supporting him in his various extra-circular activities, including this book.

Thanks to J. Carter Shanklin and the Addison Wesley staff for providing the ideal writing environment. I couldn't imagine writing for another publisher.

Thanks to all of the reviewers for their thoughtful (and thorough) feedback.

Thanks to all my students as well as the contributing members of the DCOM and ATL mailing lists. Whatever insight this book provides comes from discussing our mutual problems with COM.

Last but not least, thanks to my fellow authors for their hard work and diligence in seeing this project through to the end. It is truly a pleasure and an honor to be included as an author with professionals of such caliber.

Don would like to thank the three other Boxes that fill up his non-COM lifestyle.

Thanks to my coauthors for sharing the load and waiting patiently for me to finish my bits and pieces (the hunger strike worked, guys).

A tremendous thanks to Scott Meyers for giving us his blessing to leverage his wildly successful format and apply it to a technology that completely butchers his life's work.

Thanks to all of my cohorts at DevelopMentor for tolerating another six months of darkness while I delayed yet another book project.

Thanks to J. Carter Shanklin at Addison-Wesley for creating a great and supportive environment.

Thanks to the various DCOM listers who have participated in a long but fun conversation. This book in many ways represents an executive summary of the megabytes of security bugs, MTS mysteries, and challenging IDL puzzles that have been posted by hundreds of folks on the COM front lines.

A special thanks goes to the Microsoft folks who work on COM and Visual C++, for all of the support over the years.

Keith would like to thank his family for putting up with all the late nights. The joy they bring to my life is immeasurable.

Thanks to Don, Tim, and Chris, for thinking enough of me to extend an invitation to participate in this important project.

Thanks to Mike Abercrombie and Don Box at DevelopMentor for fostering a home where independent thought is nourished and the business model is based on honesty and genuine concern for the community.

Thanks to everyone who participates in the often lengthy threads on the DCOM list. That mail reflector has been incredibly useful in establishing a culture among COM developers, and from that culture has sprung forth a wealth of ideas, many of which are captured in this book.

Thanks to Saji Abraham and Mike Nelson for their dedication to the COM community.

Thanks, Carter, this book is so much better than it possibly could have been if you had pressed us for a deadline.

And finally, thanks to all the students who have participated in my COM and security classes. Your comments, questions, and challenges never cease to drive me toward a deeper understanding of the truth.

First and foremost, Tim would like to thank his coauthors for undertaking this project and seeing it through to completion. As always, gentlemen, it's been a pleasure.

Also, thanks to friends and colleagues Alan Ewald, Owen Tallman, Fred Tibbitts, Paul Rielly, everyone at DevelopMentor, students, and the participants on the DCOM mailing list for listening to me go on and on about COM--nodding sagely, laughing giddily, or screaming angrily as necessary.

A special thanks to Mike, Don, and Lorrie for suffering through the earliest days of DM to produce an extraordinary environment for thinking.

And, of course, thanks to my family: Sarah for letting me wear a COM ring too, Steve and Kristin for reminding me about the true definition of success, Alan and Chris for allowing me to interrupt endlessly to ask geeky questions, and Nikke and Stephen Downes-Martin for accepting phone calls from any airport I happen to be in.

Finally, thank you J. Carter Shanklin and Addison-Wesley for letting us do our own thing.

Chris Sells
Portland, OR
August 1998
Don Box
Redondo Beach, CA
August 1998
Keith Brown
Rolling Hills Estates, CA
August 1998
Tim Ewald
Nashua, NH
August 1998



Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership