When does an icon handler shell extension get unloaded?

Raymond Chen

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.

0 comments

Discussion is closed.

Feedback usabilla icon