SYMPTOMS
If you have multiple copies of your Component Object Model (COM) dynamic-link library (DLL) in different folders, when you run Regsvr32 from the directory where the DLL is located, the Regsvr32 utility registers the DLL from different locations depending on which version of Microsoft Windows you are running. On Windows 2000-based computers, Regsvr32 registers the DLL from the directory where Regsvr32 resides. However, on Windows NT-based computers, Regsvr32 registers the DLL from the current directory.
For example:
- Regsvr32.exe is located in C:\WinNT\System32.Your ActiveX/COM DLL (Test.dll) is located in C:\WinNT\System32 and C:\MyProgram.Your current directory is C:\MyProgram.At a command prompt, type regsvr32 test.dll to register Test.dll.
- Your ActiveX/COM DLL (Test.dll) is located in C:\WinNT\System32 and C:\MyProgram.Your current directory is C:\MyProgram.At a command prompt, type regsvr32 test.dll to register Test.dll.
- Your current directory is C:\MyProgram.At a command prompt, type regsvr32 test.dll to register Test.dll.
- At a command prompt, type regsvr32 test.dll to register Test.dll.
On Windows 2000, Regsvr32 registers the DLL in C:\WinNT\System32. On Windows NT 4.0, Regsvr32 registers the DLL in C:\MyProgram.
CAUSE
To register a COM DLL, the Regsvr32 utility uses the following syntax with the
LoadLibraryEx function:
LoadLibraryEx(lpFileName,NULL,LOAD_WITH_ALTERED_SEARCH_PATH)
If you pass a partial file name (that is, not a fully qualified path) to this function instead of using the altered search path strategy,
LoadLibraryEx uses the standard search path strategy to load the DLL. The standard search path strategy searches for a file in the following sequence:
- The directory from which the application is loaded.The current directory.
- The current directory.
Thus, on Windows 2000, Regsvr32 registers the DLL in C:\Winnt\System32, which is the directory where Regsvr32 resides. However, on Windows NT 4.0,
LoadLibraryEx does not enforce a fully qualified path while it uses LOAD_WITH_ALTERED_SEARCH_PATH because of a bug in
LoadLibraryEx. Because a fully qualified path is not passed to the function,
LoadLibraryEx does not know where the specified DLL is located and cannot start the search at "specified path". Thus,
LoadLibraryEx starts the search at the current directory, and the DLL in the current directory is loaded.