{"id":40533,"date":"2004-02-20T07:00:00","date_gmt":"2004-02-20T15:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/02\/20\/why-do-i-get-a-queryinterfaceiid_imarshal-and-then-nothing\/"},"modified":"2025-04-05T06:41:23","modified_gmt":"2025-04-05T13:41:23","slug":"20040220-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040220-00\/?p=40533","title":{"rendered":"Why do I get a QueryInterface(IID_IMarshal) and then nothing?"},"content":{"rendered":"<p>A common problem when trying to get your new COM object off the ground is that you can&#8217;t seem to be able to get it created. The object comes out of the class factory, and it gets a QueryInterface for IMarshal, and then nothing. What&#8217;s going on?<\/p>\n<p>This is a sure sign that you didn&#8217;t register your CLSID properly; most likely you forgot to set your threading model properly. (And if you fail to specify a threading model at all, then you get the dreaded &#8220;main&#8221; threading model.)<\/p>\n<p>If somebody tries to create a COM object from a thread whose model is incompatible with the threading model of the COM object, then a whole bunch of marshalling stuff kicks in. And if the marshalling stuff isn&#8217;t there, then COM can&#8217;t use your object.<\/p>\n<p>There is <a title=\"Understanding the Distributed Object Component Model (DCOM) Architecture\" href=\"https:\/\/web.archive.org\/web\/20050205090232\/http:\/\/www.microsoft.com\/ntserver\/techresources\/appserv\/COM\/DCOM\/5_ConcurrencyMgmt.asp\"> a long and very technical article in MSDN on COM threading models<\/a> which has lots of scary-looking diagrams and tables. In particular, the second scary table in the &#8220;In-process servers: (almost) totally dependent on their clients&#8221; chapter lists all the combinations of thread models with object threading models, and what COM tries to do in each case.<\/p>\n<p>In particular, notice that if you have a (mistakenly marked) &#8220;main&#8221;-threaded object and somebody on any thread other than the main thread tries to create it, marshalling will try to kick in.<\/p>\n<p>So watch those threading models. The failure modes when you get them wrong are quite baffling.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Can&#8217;t get past the first step.<\/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-40533","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Can&#8217;t get past the first step.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/40533","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=40533"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/40533\/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=40533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=40533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=40533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}