December 13th, 2004

Why do I get E_NOINTERFACE when creating an object that supports that interface?

I’ve seen a few questions from people who call the CoCreateInstance function, asking for an interface that they know the object supports, yet receiving error E_NOINTERFACE. What’s going on?

You’re seeing the same problem as the missing IMarshal, just from the other side.

If your threading model is incompatible with the threading model of the object you’re creating, then COM marshalling kicks in. And if the marshalling stuff isn’t there, the error that comes out is E_NOINTERFACE, because the marshalling interface is missing.

A common source of this is attempting to use COM objects provided by the shell from a multi-threaded apartment. Remember that shell COM objects are, for the most part, apartment-threaded, not free-threaded. If you want to use shell objects, you should do so from single-threaded apartments.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.