So I'm finally done with the "COM activation" posts. One question that was asked during the series was (paraphrased) "Why on earth are you doing this". The simple answer is: The registry keys used for COM are a great example of Cargo cult programming. Everyone uses a template that they found in a previous COM object without really understanding what they need. The thing is, for the vast majority of COM objects, there are only about a half a dozen things that they'd ever have to worry about. This is further complicated by the fact that Visual Studio's templates add a lot of stuff that isn't always required (because VS can't know what the right behavior is).
A large part of the "cargo cult" nature of this is the fact that there are a bewildering set of registry settings that can be set for COM objects, and it's not clear which, if any apply. So I'm attempting to lay out a series of articles that can help people determine what they need to set.
So we start at the beginning. You've decided that you are going to author a COM object. The reasons for it aren't important, you're writing a COM object.
Well, before you even get started, you need the minimal COM object registration.
Next, you need to determine if you need an APPID. If you do, you need to add an APPID registry key to your COM object's registration.
After thinking about the APPID, you need to determine if the interfaces supported by your object need to be marshaled. You have two choices when marshaling interfaces:
- You can marshal your interface by using a proxy DLL.
- You can marshal your interfaces by using a typelib.
In general, marshaling by a proxy DLL will be somewhat faster (because it doesn't have to parse the typelib to determine the marshaling semantics), and will more accurately match the exact interface semantics.
On the other hand, marshaling by typelib allows you to easily implement automation and interoperate with VB6 and .Net languages.
There's no right answer that fits everyone, you need to make the choice that's right for your object. Once you've made that choice, you can either look at the registry changes needed to register a proxy DLL, or the registry changes needed to register a typelib.
And finally, you need to decide if you need a progid for your COM object. If you do, then you need to apply the registry changes for a PROGID.
Now this article doesn't even come close to covering all the myriad of options available for COM objects. But it covers all the cases I've hit over the past few years of (admittedly unsophisticated) COM use.
Btw, one of the things I noticed while writing this series is that the MSDN samples for ActiveX controls, especially the Hello sample do a great job of of showing all the COM registrations needed for ActiveX controls, including all the registry changes needed for each of the pieces above.