What the #$%& is COM!?

One of the most important concepts in VBA is also one of the least understood. Let's shine a light on the Component Object Model.

What the #$%& is COM!?

If you spend enough time programming in VBA, you will inevitably come across references to COM.  But what the heck is it, exactly?  It's actually quite simple:

COM is the component object model.

Wikipedia: Unofficial Explanation

You probably want more than just what the acronym stands for, don't you?  Fine, let's see what Wikipedia has to say about COM:

Component Object Model (COM) is a binary-interface standard for software components introduced by Microsoft in 1993.

What?  You're still not satisfied with that explanation?  Read the whole article, then.  I'll wait.

....

While you're reading that, I'm just gonna watch this random clip from The Office:

[Michael Scott]: Wikipedia is the best thing ever.  Anyone in the world can write anything they want about any subject.  So you know you are getting the best possible information.

...

Hey!  Are you watching YouTube?!  You're like one of my kids.  Go do your homework!  Read the WHOLE article (or as much as possible before your head starts to hurt).

...

...

OK, finished?  Now do you understand what COM is?  

What do you mean you're even more confused?  

Did you read the part about how "different allocation semantics of languages are accommodated by making objects responsible for their own creation and destruction through reference-counting?"  Surely you now know that "[i]t is through the effective use of type libraries that COM achieves its capabilities as a dynamic framework for the interaction of objects."

Microsoft: Official Explanation

Still not getting it?  Let's try the official documentation from Microsoft this time:

The Microsoft Component Object Model (COM) is a platform-independent, distributed, object-oriented system for creating binary software components that can interact. COM is the foundation technology for Microsoft's OLE (compound documents), ActiveX (Internet-enabled components), as well as others.

You should probably read that whole article (plus all the related topics).  When you do, you'll learn that "[t]he only language requirement for COM is that code is generated in a language that can create structures of pointers and, either explicitly or implicitly, call functions through pointers."  And, of course, "COM requires that the only way to gain access to the methods of an interface is through a pointer to the interface."

NoLongerSet: Understandable Explanation

If you're overwhelmed by all the dense technical discussions surrounding COM, don't feel bad.  I've got a degree in computer science, I've been writing VBA professionally for nearly 15 years, I'm an Access MVP, and I'm just now getting to the point that this stuff is finally starting to make some sense.

I've always felt bad that I didn't understand COM very well.  

Every time I tried to research it in the past, I ran into one or more of the following problems:

  • I got lost in the articles because they were too technical
  • I couldn't figure out which topics applied to VBA and which did not
  • The articles didn't go in-depth enough to be useful
  • I never found a good source of articles on COM from a VBA perspective

I want to address this issue for other VBA developers.  I will be writing a series of articles on COM, exploring a variety of topics:

Why me?

In the past year and a half, I've learned a lot about COM.  I've gained a much better understanding about how it works (though I'm still no expert).  Writing a technial article every day forces you to do a lot of research if you want to avoid sounding like an idiot, though.  

I've also learned a TON about the inner workings of COM just by following the discussions of all the smart people providing feedback to the twinBASIC project.  Plus, I have a bunch of readers with more knowledge than I do on this topic who won't be afraid to set me straight in the comments if I post any inaccuracies.

Finally, I've got two young developers at Grandjean & Braverman to help remind me of where I was at fifteen years ago.  This may be the most important factor, as the curse of knowledge plagues most of the articles written about COM over the past several decades:

The curse of knowledge is a cognitive bias that occurs when an individual, communicating with other individuals, unknowingly assumes that the others have the background to understand.

So what can you expect?

There will be analogies.  There will be metaphors.  There will be references to 90's pop culture.  And, with a little luck, you'll also learn something about COM along the way.  I'm sure I will.


External references

Component Object Model - Wikipedia
The Component Object Model - Win32 apps
The Component Object Model
Issues · WaynePhillipsEA/twinbasic
Contribute to WaynePhillipsEA/twinbasic development by creating an account on GitHub.
twinBASIC Welcome
The Curse of Knowledge: How It Impacts You, and What to Do About It | UserTesting Blog
If you’re responsible for introducing customers to a company or a product for the first time, there’s something you need to watch out for. It’s called the curse of knowledge, and it can affect anyone who creates brand messaging, website copy, tutorials, or onboarding processes. The curse of knowledg…

Referenced articles

High Level Overview of COM
This whirlwind tour of the Component Object Model technology will jump start your journey of automating Excel from VBA in Access.

UPDATE [2021-12-27]: Added "COM Server Types" entry to topic list along with link to related article.

Image by Sasin Tipchai from Pixabay

All original code samples by Mike Wolfe are licensed under CC BY 4.0