September 25th, 2009

The ways people mess up IUnknown::QueryInterface, episode 2

Sadly, I get to add another entry to The ways people mess up IUnknown::QueryInterface:

Blindly responding to everything.

Some people are just too eager to please.

HRESULT CSomething::QueryInterface(REFIID riid, void **ppvObj)
{
  *ppvObj = this;
  this->AddRef();
  return S_OK;
}

No matter what the interface is, they say, “Sure, we do that!”

Furthermore, no matter what you ask for, they always return the same interface. Even if it’s not what you asked for.

Exercise: Some people say that “these problems wouldn’t be there if Microsoft Windows had enforced correct behavior to begin with.” My exercise to you, commenter “foo”, is to come up with a list of all bugs in IUnknown::QueryInterface which Windows should enforce and describe how to enforce it. (If your response is “You should have designed it differently so these bugs are impossible to write”, please outline that alternate bug-resistant design. Remember that your design must be language-independent, while still supporting things like tear-offs, aggregation, and remote objects. Oh and it needs to work on typical PC-class computers of the early 1990’s, which ran at 25MHz with 4MB of memory.)

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.