Some time ago I started learning COM server programming by creating a COM server from scratch, using only the raw Win32 API functions.
I started out with a very basic server, and then added new functionality with each new ‘release’. Since there aren’t that many up-to-date articles about writing a COM server, I intended to write an article for each release, explaining the extra functionality that got added with that release.
Of course, that was with the assumption that I actually would have time to write those articles. But that does not seem to be the case anymore, so I decided to change plans.
When I was writing the code, I took the time to put in extensive code documentation because that’s an ingrained habit. So Everything I would have written in the article is written down in the code as well. Because of this I have decided to release the different versions of my code together, with all the code comments in place.
Combined with Don’s book ‘Essential COM’, these articles should be enough to get anyone started with practical COM server programming. Note that I don’t use any ATL code, so this is not how you would create a COM server in real life. Still, this code explains exactly what happens. This is something that is harder to do with ATL code.
- V1: A very basic client server setup in which the (out of proc) server mimics a computer that exports a very simple ICalculator interface.
- V2: The same client server solution, but the server creates instances through an IClassFactory.
- V3: The same as V2, but with a correct implementation of server lifecycle management. The server is now completely thread safe.
- V4: The same as V3, but now the server is available as In-Proc server and Out of proc server.
- V5: the same as V4, but now the server uses implements IOleItemContainer to allow the client to retrieve named instances instead of creating new instances. The client could then retrieve the named object by supplying a simple string to the GetObject function call. This adds a lot of flexibility to the client code since it doesn’t explicitly have to supply a guid or activation settings.
V6 is the special one where I spent days hacking my way through obscure documentation. Since there are NO public articles about that technology at all, I will write an article about that one. But releasing my other version here with a bit of explanation saves me the hassle of writing the 5 articles that should go before V6.