What registry entries are needed to register a COM object.

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:

  1. You can marshal your interface by using a proxy DLL.
  2. 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.

Comments (4)

  1. rodrigostrauss says:

    Congratulations for good material and, please, keep writing about COM. Doing this .NET wave, most people forget that a big part of Windows is still COM based…

  2. Anonymous says:

    Hey Larry,

    This is quite OT, but I’ve just wanted to tell you how much your blog is a pleasure to read.

    If one would start reading your blog from the earliest entries, there’s quite a lot to be learned from best programming practices to security.

    Thanks! 🙂

  3. Dave says:

    I learned a lot from this mini-series, thanks. I’m building both a BHO and an ActiveX control to be used only with IE, and I think that it;s possible to simplify what ATL is stuffing in the registry on my behalf. But I have this nagging fear…maybe things are happening with COM behind my back.

    Looking back through the posts, it would be great if these were encapsulated into an expert system. For example, I think you *must* have a PROGID to have your object usable by Windows Scripting host, at least I have never seen a WSH example that created an object by CLSID. If a program did an interview and asked me 20 questions it could figure out which registry entries I needed.

    Heck, while I’m dreaming: it would be nice if this expert system could ask about 20 more questions and write the code for me too.

  4. Anonymous says:

    Great series. Thanks!

Skip to main content