Behind the Scenes at the COM Factory


In order to fully understand what COM does behind the scenes, let’s create an imaginary language called B--. This language looks a lot like Visual Basic, with one minor difference. It doesn’t know COM from calm. In other words, it’s a lot like C or C++. We’re still going to create and use COM objects, but we’ll have to manage them ourselves.


To make this exercise work, we’re going to have to take some poetic license. Some steps will be skipped. Some impossible leaps will be taken. Some white lies will be told. If you’ve programmed COM objects in C++, you might be amused, or perhaps outraged. Never mind. There’s no B-- compiler, so you can’t prove me wrong when I say that the following interface is behind all the other things in COM:

‘ IUnknown interface
Function QueryInterface(iid As GUID) As Object
End Sub

Sub AddRef()
End Sub

Sub Release()
End Sub

Those of you who know COM in a language other than B-- might laugh to see that I’ve changed QueryInterface into a Function and changed AddRef and Release into Subs. Bear with me. It will all work out in the end.