{"id":38663,"date":"2004-06-28T07:00:00","date_gmt":"2004-06-28T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2004\/06\/28\/when-does-shloadinproc-unload-a-dll\/"},"modified":"2004-06-28T07:00:00","modified_gmt":"2004-06-28T07:00:00","slug":"when-does-shloadinproc-unload-a-dll","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20040628-00\/?p=38663","title":{"rendered":"When does SHLoadInProc unload a DLL?"},"content":{"rendered":"<p>The  <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/shellcc\/platform\/shell\/reference\/functions\/shloadinproc.asp\">  SHLoadInProc<\/a>  function instructs Explorer to  create an instance of a particular CLSID.  This causes the DLL responsible for that CLSID to be loaded.\n  But when is it unloaded?\n  This is one of those puzzles you should be able to figure out  by thinking about it.\n  Consider: The object is created by calling  <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/com\/htm\/cmf_a2c_1nad.asp\">  CoCreateInstance<\/a>  and then immediately releasing the returned object.  That&#8217;s all.  Explorer pays no attention to your DLL from then on.\n  With this hint, maybe now you can answer the question:  When is it unloaded?\n  Still don&#8217;t know?  Here&#8217;s another hint:  The issue is no longer a shell issue.  Now it&#8217;s a COM issue.\n  When is <strong>any<\/strong> DLL loaded via  CoCreateInstance unloaded?<\/p>\n<p>  Answer: The DLL is periodically asked  <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/com\/htm\/cmf_d2l_531z.asp\">  whether it is safe to unload<\/a>.  Once the DLL response in the affirmative (via S_OK), COM will unload it.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The SHLoadInProc function instructs Explorer to create an instance of a particular CLSID. This causes the DLL responsible for that CLSID to be loaded. But when is it unloaded? This is one of those puzzles you should be able to figure out by thinking about it. Consider: The object is created by calling CoCreateInstance and [&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-38663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>The SHLoadInProc function instructs Explorer to create an instance of a particular CLSID. This causes the DLL responsible for that CLSID to be loaded. But when is it unloaded? This is one of those puzzles you should be able to figure out by thinking about it. Consider: The object is created by calling CoCreateInstance and [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/38663","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=38663"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/38663\/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=38663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=38663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=38663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}