Archive: CoFreeUnusedLibraries call in InstallLib


CoFreeUnusedLibraries call in InstallLib
In http://nsis.sourceforge.net/Docs/AppendixB.html#B.2.3 under LIBRARY_COM it says "...to call CoFreeUnusedLibraries after registration" and the Library.nsh code shows this.

MSDN:
CoFreeUnusedLibraries
Unloads any DLLs that are no longer in use and that, when loaded, were specified to be freed automatically.
Is there a reason this call is only made after registration? Why isn't it called before installation/registration also? I don't have experience with CoFreeUnusedLibraries, so I'm trying to understand its usage, but from the description it seems like you'd want to call it before installation/registration.

Thanks.

Calling it before unregistration will have no meaning because the unregistered DLL is not loaded at that stage. The idea behind this call is unloading the DLL so it can be deleted after it's unregistered.

Calling it in the registration process is probably useful only for freeing unused memory. In that case as well it wouldn't make any sense calling it before the DLL was even loaded.

See the original thread for more details.


Thanks, I didn't find that older thread when researching.

I had in mind the scenario of an overinstall. For example, a COM DLL is already installed and was being used. The process using it stopped using it, but it had not been unloaded by the time you overinstall. It seemed like CoFreeUnusedLibraries or CoFreeUnusedLibrariesEx would possibly allow you to overinstall the DLL immediately without having to install it as a temp file and rename on reboot. If the DLL is actively being used, the API call would not help...this would all depend on the timing.

I may be (make that 'probably am') completely wrong about this, so I was seeing what others thought about it.


It only frees DLLs of the current process, not all processes on the system.


ah, that makes sense. Thanks for the clarification :)