When does SHLoadInProc unload a DLL?

Raymond Chen

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.

0 comments

Discussion is closed.

Feedback usabilla icon