A customer pointed out that you can use
regsvr32 to register a DLL or to unregister it, but how do you query whether a DLL has been registered?
DLL registration (via
regsvr32) is not declarative; it is procedural. A DLL does not provide a manifest of things it would like to happen when installed. Instead, the DLL merely provides two functions for
regsvr32 to call, one for registration (
DllRegisterServer) and another for unregistration (
DllUnregisterServer). All the
regsvr32 function does is call those functions.
How those functions perform their registration and unregistration is not specified. Most of the time, those functions merely write some registry settings, but the
DllRegisterServer is not limited to that. For example, the
DllRegisterServer function might write some values only conditionally, say, only if the user is running a specific version of Windows. Or it might back up the old value of a registry key before it overwrites it. It might create or modify files as part of its installation or configure your firewall settings or look for and uninstall previous versions of the same DLL.
By convention, the
DllRegisterServer performs whatever operations are necessary for DLL registration, and the
DllUnregisterServer reverses those operations, but since those functions are provided by the DLL, there's no guarantee that that's what actually happens. Who knows, maybe
DllRegisterServer formats your hard drive. A
DllRegisterServer function might just return
S_OK without doing anything. How can you tell whether a function with no side effects has been called?
Given that DLL registration can encompass arbitrary operations, there is no general-purpose way of determining whether registration has taken place for an arbitrary DLL.
To determine whether a DLL has been registered, you need to bring in domain-specific knowledge. If you know that a DLL registers a COM object with a particular CLSID, you can check whether that CLSID is indeed registered.