June 28th, 2004

When does SHLoadInProc unload a DLL?

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 then immediately releasing the returned object. That’s all. Explorer pays no attention to your DLL from then on. With this hint, maybe now you can answer the question: When is it unloaded? Still don’t know? Here’s another hint: The issue is no longer a shell issue. Now it’s a COM issue. When is any DLL loaded via CoCreateInstance unloaded?

Answer: The DLL is periodically asked whether it is safe to unload. Once the DLL response in the affirmative (via S_OK), COM will unload it.

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.