{"id":131,"date":"2008-06-17T16:47:28","date_gmt":"2008-06-18T00:47:28","guid":{"rendered":"http:\/\/www.curlybrace.com\/words\/?p=131"},"modified":"2010-12-15T19:08:46","modified_gmt":"2010-12-16T03:08:46","slug":"cocreateinstance-clsctx_inproc_server-failing-with-class-not-registered","status":"publish","type":"post","link":"https:\/\/www.curlybrace.com\/words\/2008\/06\/cocreateinstance-clsctx_inproc_server-failing-with-class-not-registered\/","title":{"rendered":"CoCreateInstance Fails With &#8220;Class Not Registered&#8221;"},"content":{"rendered":"<p>Recently, I had a problem unique to my test machine.  Attempting to call CoCreateInstance on a COM class provided by one of our DLLs resulted in HRESULT 0x80040154, which corresponds to &#8220;Class not registered&#8221;.<\/p>\n<p>This was a mystery since regsvr32 appeared to properly register our DLL, and all the obvious registry keys were intact!<\/p>\n<p>After a bit of web searching, I experimented with using CLSCTX_ALL instead of CLSCTX_INPROC_SERVER.  Now, the call succeeded!  But why, since this is a DLL and, therefore, should be considered an in-process COM server?<\/p>\n<p><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms686615(VS.85).aspx\">MSDN documentation<\/a> states that CLSCTX_ALL is defined as the combination of CLSCTX_INPROC_SERVER, CLSCTX_INPROC_HANDLER, and CLSCTX_LOCAL_SERVER.  I began substituting each one in turn and found that the key was CLSCTX_LOCAL_SERVER.<\/p>\n<p>Stepping through the code in the debugger revealed that the instant the CoCreateInstance call was made, a new instance of dllhost.exe appeared in the process list.  This explained why CLSCTX_INPROC_SERVER would fail, since strictly speaking, the DLL was being hosted in dllhost&#8217;s process space.<\/p>\n<p>Ultimately, the problem turned out to be an artifact from an old COM+ experiment.  There was a COM+ entry corresponding to our COM server in the Component Services panel (Control Panel | Administrative Tools | Component Services, under Component Services | Computers | My Computer | COM+ Applications).  The COM+ entry dictated that the COM server be hosted by proxy by dllhost.exe.  Deleting this COM+ entry and re-running regsvr32 fixed the problem.<\/p>\n<blockquote><p><img src='http:\/\/www.curlybrace.com\/words\/wp-content\/uploads\/2008\/06\/componentservices.PNG' alt='Component Services panel in Administrative Tools' \/><\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I had a problem unique to my test machine. Attempting to call CoCreateInstance on a COM class provided by one of our DLLs resulted in HRESULT 0x80040154, which corresponds to &#8220;Class not registered&#8221;. This was a mystery since regsvr32 &hellip; <a href=\"https:\/\/www.curlybrace.com\/words\/2008\/06\/cocreateinstance-clsctx_inproc_server-failing-with-class-not-registered\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[198,15,199,283],"tags":[],"class_list":["post-131","post","type-post","status-publish","format-standard","hentry","category-com","category-technology","category-win32-technology-2","category-windows-technology"],"_links":{"self":[{"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/posts\/131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/comments?post=131"}],"version-history":[{"count":2,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":1414,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/posts\/131\/revisions\/1414"}],"wp:attachment":[{"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/media?parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/categories?post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.curlybrace.com\/words\/wp-json\/wp\/v2\/tags?post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}