Read an Excerpt
On the Teaching and Learning of COM
WHY I WROTE THIS BOOK
COM has a reputation for being hard to learn. A client once told me that he knew of only two programmers in the entire world who understood it, both of whom worked for Microsoft and spent their days writing puzzles for each other. But really, nothing could be further from the truth. COM has an elegant simplicity to its architecture and an internal self-consistency that the Windows API lacks. It's just a different way of looking at the world. This book is an attempt to clear things up, to present in a simple and easily digested fashion the stuff I had to learn the hard way.
As I hope to demonstrate in this book, learning COM isn't that hard. It may take you a little while to get the basic concepts, though I've done my best to build easily accessible ramps into it. But once the light bulb goes off, probably after about two weeks of head banging, you will have the keys to all of COM. Learning the Windows API was largely a matter of memorizing arbitrary function calls without any central organizing principle, sort of like memorizing all those boring equations in college organic chemistry. Learning COM as presented in this book is more like learning the basic principles that cause the entire universe to operate. Remember college physics? The simplest equations, such as F = MA, describe all macroscopic motion, from the falling of a feather to the collision of galaxies.
MARCH OF THE YEARS
I sent the first edition of this book to press at the end of August 1996, going on four years ago. That's an awfully long time in the software business. I did a secondedition about a year later, Christmas of 1997. This edition is headed to press in the spring of 2000. The changes reflect not so much the changes in COM, although God knows there are plenty of those (DCOM, threading, and asynchronous operation, to name just a few), but the changes in my understanding. I remember reading a certain part of the first edition and thinking, "I can't believe I actually looked at the world that way then." As I changed my mind about my 1972 George McGovern ideals when I started having to write my own checks to the IRS, so I changed my mind about many things in COM once I actually started using them on projects.
I occasionally envy my Harvard colleagues in the Department of Classics, whose material hasn't changed in 2000 years. This area of software is really snowballing. COM is everywhere, at the foundation of everything. This book is my attempt to keep up with it, and keep you up with it as well.
IT GOT SMALLER
Anyone who has seen the second edition of this book, the one with the airplane on the cover, will notice that this book is about 60% the size of that one. It's not just that I got shoulder pain hauling around a backpack with that book in it, and it's not just that I almost killed my cat when I accidentally dropped it on her. You know the old cliché that inside every large program, there's a small program struggling to get out. The prime goal of writing this book from the first day was succinctness: to get the basic ideas out so people could understand them easily. I wanted to hack a narrow path through the jungle from end to end. The second edition just had too much stuff in it; the signal-to-noise ratio was too low. So in this book, I thought about what I really used in COM and tried to slim it down. I took out everything having to do with the MFC. Jeff Prosise would probably disagree, but I think the MFC has reached its evolutionary dead-end point. I took out a lot of the user interface stuff that I don't use any more, except for the Clipboard and drag-and-drop samples that I've found so useful as a visual demonstration of the first principles of COM. The result was about a 40% reduction. Too bad the government can't do a similar job.
SAMPLE CODE AND FREE QUARTERLY COM/COM+ DEVELOPMENT NEWSLETTER ONLINE
Instead of putting this book's sample code on CD-ROM, I've decided to put it on my Web site, www.rollthunder.com. It's easier for me to update and add to. You don't have to remember where you put that disk. And it's free to anyone, even if you didn't buy the book. Tell your friends. While you're on my Web site, why don't you check out my free quarterly e-mail newsletter, entitled ThunderClap. Each issue contains a technical article on timely COM or COM+ development topics. Recent issues have covered automatic synchronization of objects in COM+, COM+ compensating resource managers, and a COM+ event system spy program. It is also free to anyone, so please come help yourselves.
HOW TO USE THIS BOOK
If you are new to COM, READ CHAPTERS 1 AND 2 FIRST!! Do not attempt to jump to other chapters until you feel comfortable with these. In these chapters I introduce the new programming model and vocabulary of COM without which subsequent chapters will make no sense. I hate the term "paradigm shift"; it's been so badly overused as to have lost all meaning, but COM does turn your head around.
You don't really own your knowledge of software until you've written some yourself. The end of each chapter contains self-study programming exercises with detailed instructions. The prepackaged labs pretty much follow the text, so they aren't hard. The extra credit sections at the end of some labs are designed to stretch your mind a bit more.
When you are actually writing your programs, keep this book handy on your desk. My students tell me that it is the first source they refer to, because it's easy to find what they want and easy to absorb when they do find it. They only go off to a thicker book when they can't find what they want in this book. One student even has two copies, one at home and one at work.
WHY ALL THE EMPTY PAGES?
The reason I have them is to align the two-page sound bites over a spread of two facing pages. When a topic doesn't fit on a single page, my experience has shown that students find the material much easier to absorb if it is spread across two facing pages. I can't stand pages that say "This page intentionally left blank." Does it never occur to anybody that this statement is self-negating? THE %$#^$@ PAGE ISN'T BLANK, IT CONTAINS THAT ONE LYING SENTENCE!! If the author can't even get that dinky little piece right, how can I believe anything else he says? Instead, my empty pages truthfully say, "This page intentionally contains no text other than this sentence." Call me a curmudgeon.
SEND ME FEEDBACK
I love to hear from my readers, to find out which parts of the book were most useful. Also, I guarantee that, despite my best efforts and those of my reviewers, some errors remain in this book, and I'd sure appreciate it if you'd tell me about them so they can be fixed in the next edition. My e-mail address is email@example.com. My web site, www.rollthunder.com, will contain updates and corrections to the book.
PROGRAMMING CLASSES AVAILABLE
A self-study guide like this one is great (I hope), but the fastest way to get going in programming is to have an in-house hands-on class. I'll come to your company and teach exactly the parts of COM and COM+ that you care about. Contact me by e-mail at the address in the preceding paragraph.
David S. Platt
Ipswich, MA, January 2000