{"id":16583,"date":"2009-09-25T10:00:00","date_gmt":"2009-09-25T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/09\/25\/the-ways-people-mess-up-iunknownqueryinterface-episode-2\/"},"modified":"2009-09-25T10:00:00","modified_gmt":"2009-09-25T10:00:00","slug":"the-ways-people-mess-up-iunknownqueryinterface-episode-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090925-00\/?p=16583","title":{"rendered":"The ways people mess up IUnknown::QueryInterface, episode 2"},"content":{"rendered":"<p>\nSadly, I get to add another entry to\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/03\/26\/96777.aspx\">\nThe ways people mess up <code>IUnknown::QueryInterface<\/code><\/a>:\n<\/p>\n<dl>\n<dt>Blindly responding to everything.<\/p>\n<dd>\n<p>\nSome people are just too eager to please.\n<\/p>\n<pre>\nHRESULT CSomething::QueryInterface(REFIID riid, void **ppvObj)\n{\n  *ppvObj = this;\n  this-&gt;AddRef();\n  return S_OK;\n}\n<\/pre>\n<p>\nNo matter what the interface is, they say,\n&#8220;<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/02\/11\/71307.aspx\">Sure, we do that<\/a>!&#8221;\n<\/p>\n<\/dl>\n<p>\nFurthermore,\nno matter what you ask for, they always return the same interface.\nEven if it&#8217;s not what you asked for.\n<\/p>\n<p>\n<b>Exercise<\/b>:\nSome people say that\n&#8220;<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2004\/03\/26\/96777.aspx#96826\">these problems wouldn&#8217;t be there if Microsoft Windows\nhad enforced correct behavior to begin with<\/a>.&#8221;\nMy exercise to you, commenter &#8220;foo&#8221;, is to come up with\na list of all bugs in <code>IUnknown::QueryInterface<\/code>\nwhich Windows should enforce and describe how to enforce it.\n(If your response is &#8220;You should have designed it differently\nso these bugs are impossible to write&#8221;, please outline that\nalternate bug-resistant design.\nRemember that your design must be language-independent,\nwhile still supporting things like tear-offs,\naggregation, and remote objects.\nOh\nand it needs to work on typical PC-class computers of the early 1990&#8217;s,\nwhich ran at 25MHz with 4MB of memory.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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-&gt;AddRef(); return S_OK; } No matter what the interface is, they say, &#8220;Sure, we do that!&#8221; Furthermore, no matter what [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-16583","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>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-&gt;AddRef(); return S_OK; } No matter what the interface is, they say, &#8220;Sure, we do that!&#8221; Furthermore, no matter what [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=16583"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/16583\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=16583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=16583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=16583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}