Why do I get the error REGDB_E_IIDNOTREG when I call a method that returns an interface?

This is another manifestation of the missing marshaller problem.

IContextMenu *pcm;
HRESULT hr = psf->GetUIObjectOf(hwnd, 1, &pidl,
               IID_IContextMenu, NULL, &pcm);
// fails with REGDB_E_IIDNOTREG

The IContextMenu interface does not have a proxy/stub factory (as of this writing). Recall that shell objects, as a rule, are apartment model. If you create the object from a multi-threaded apartment, COM needs to build a wrapper object which can marshal calls from off-thread back onto the original thread, in order to adhere to the threading rules for apartment-model objects.

And if the COM standard marshaler can't find a proxy/stub factory for an interface, it returns the error REGDB_E_IIDNOTREG.

Comments (5)
  1. John says:

    So are there rules for deciding which shell interfaces get a proxy/stub factory, or did they just kind of slip in there during the build process?

  2. Dave says:

    What John said. Is it okay to use CreateProxyFromTypeInfo and CreateStubFromTypeInfo to roll your own?

  3. Dean Harding says:

    Dave: I’m pretty sure the standard COM marshaler will try to use the typelib if it can’t find the proxy/stub factory. But in the case of IContextMenu, it’s got some funny pointers and stuff that I doubt would work with standard marshelling. Besides, it might not even have a typelib registered, I’m not sure.

  4. Ken Hagan says:

    For IContext menu, you’d have to consider the way the interface is used. It’s very tied up with the processing of window messages, which are thread-bound, so if you did throw together some marshaling support of your own you might still have problems in practice.

    I don’t actually know in this case, since I’ve never tried, but the short answer to the "are there rules" question is "Yes, proxies are not provided if the original designer of the interface had some reason for wanting to restrict implementations to a single STA.".

  5. Eric says:

    If I’m not mistaken, the standard COM marshaller will automatically create a proxy/stub if there’s a typeinfo chunk associated with the interface GUID.  Not all interfaces have typeinfo chunks, particularly those interfaces that are internal to an application.  (I have a project with a half-dozen COM interfaces that aren’t even registered, much less with typeinfo.)  Most COM registration goo isn’t needed – start here: http://blogs.msdn.com/larryosterman/archive/2006/01/05/509731.aspx

Comments are closed.

Skip to main content