Tuesday, September 27, 2011
When an installation program copies a DLL to the system, it looks in HKLM\Software\Microsoft\Windows\CurrentVersion\SharedDLLs for the path where the DLL is going to be installed. If the DLL's install path is in this registry location, the counter for the path is incremented. If it isn't there already, there is usually an option in the installation development tool that causes the path to be entered there with an initial count of one. When the product is uninstalled, the reference count is decremented. When the count becomes zero, this means that the DLL is no longer being used and it can be removed from the system.
Note that this reference counting scheme is based on the path to the DLL. If a COM DLL is installed to the wrong location, the reference counting breaks. It does no good to have the COM DLL with a reference count of one in two seperate paths in the sharedDLLs entries.