February 15th, 2012

When does an icon handler shell extension get unloaded?

A customer had a question about the SHGet­File­Info function. They used the function to obtain the icon for a file, and they discovered that when they asked for the icon of a particular type of file, the shell extension for the associated application was loaded.

But unfortunately the third party shell extension is not getting unloaded, maybe because of a bug. Can we do anything in code to get this shell extension to unload?

You already know everything you need to answer this. Shell extensions are COM objects, and icon handlers are in-process local servers, and in-process local servers remain loaded until the apartment is torn down or the application calls Co­Free­Unused­Libraries (or a moral equivalent).

Therefore, their application can follow the standard COM pattern of calling Co­Free­Unused­Libraries every so often (say, after being idle for five minutes or when there is some indication that the user has stopped one task and started another). The shell extension will then be asked whether it is safe to unload, and if it responds in the affirmative, then 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.