Configuring workstations to handle shared DLLs is difficult. In many organizations, the PATH environment becomes a point of contention between project teams. Configuring a PATH specific to your application can solve the problems associated with using a common search PATH, and eliminate many configuration errors in your application as well. This article first describes the current methods of application configuration and the problems associated with them. Finally, the specific details of adding an application specific path in the registry are described. The solution is compatible with both NT and '95.
As many of you already know, and as the Visual C++ documentation illustrates, the operating system will use the following algorithm for locating a DLL. (Load Visual C++ help on LoadLibrary()).
Now, imagine the following situation in which two applications (ONE.EXE and TWO.EXE) need to share a common DLL (COMMON.DLL). The applications install the files into the following directories.
Application 1 | Application 2 |
C:\Program Files\ONE\ONE.exe | C:\Program Files\TWO\TWO.exe |
C:\Program Files\Common\COMMON.DLL | C:\Program Files\Common\COMMON.DLL |
There are several ways to configure the machine using the above search algorithm.
Hmm, one big directory. Sounds great until you need to remove one application, and can't figure out which files to delete. While your at it, why not just make one big .EXE file?
Faced with the above problems, many programs were configured to be started with the current directory pointing to the DLL. This is easily set in the short-cut which starts the application. While this gives each program control of the DLLs that it loads, it also has several side effects:
Many applications store DLLs in the Windows or System directory. This creates a maintenance problem, particularly if the system files need to be replaced. Many organizations have begun locking down the Windows and System directories, in an effort to reduce maintenance costs.
Certainly the most straight forward approach is to have C:\Program Files\Common added to the path. This was how things were done in the Win 3.1 days. There are several problems:
Microsoft has offered a solution to all these problems. Each application can now store it own path the registry under the following key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
The use the application path, set a key for your application, using ONE.EXE from the example above:
HKEY_LOCAL_MACHINE\...\CurrentVersion\App Paths\ONE.exe
Set the (Default) value to the full path of your executable, for example:
C:\Program Files\ONE\ONE.exe
Add a sub-key named Path, set it's value to the full path of the DLL, for example:
C:\Program Files\Common
With an App Path registry entry, the system will load DLLs in the following order.
Run REGEDIT to see examples of other applications, and how they setup their App Path keys.