CodeGuru
Earthweb Search
Forums Wireless Jars Gamelan Developer.com
CodeGuru Navigation
Member Sign In
User ID:
Password:
Remember Me:
Forgot Password?
Not a member?
Click here for more information and to register.

Become a Marketplace Partner

jobs.internet.com

internet.commerce
Partners & Affiliates
















RSS Feeds

RSSAll

RSSVC++/C++

RSS.NET/C#

RSSVB

See more EarthWeb Network feeds

Home >> Visual C++ / C++ >> Windows Programming >> DLL


Application Specific Paths for DLL Loading
Rating:

William A. Walseth (view profile)
June 19, 1999

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.


(continued)



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()).

  1. The directory where the executable module for the current process is located.
  2. The current directory.
  3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
  4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
  5. The directories listed in the PATH environment variable.

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.

1) Put all applications into a single directory

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?

2) Modify the current directory

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:

  1. Any documents written will be written to the DLL location.
  2. File Open dialogs start out in the DLL location.
  3. Programmatically changing the current directory may cause future DLL loads to fail.
  4. It's difficult to control current directory if one program invokes another.

3) Put common files into the Windows or System directory

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.

4) Modify the PATH environment variable

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:

  1. If the workstation includes several applications, the PATH becomes incredibly long.
  2. The order in which directories appear on the path becomes important.
  3. The system spends a great deal of time searching directories that are never used by the application.
  4. The program cannot determine which location is used to load a DLL.
  5. Installation programs require re-boots for the path changes to take effect.

Finally, Application Specific Paths!

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.

  1. The directories listed in the App Path registry key
  2. The directory where the executable module for the current process is located.
  3. The current directory.
  4. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.
  5. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.
  6. The directories listed in the PATH environment variable.

Run REGEDIT to see examples of other applications, and how they setup their App Path keys.

History

Tools:
Add www.codeguru.com to your favorites
Add www.codeguru.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed







RATE THIS ARTICLE:   Excellent  Very Good  Average  Below Average  Poor  

(You must be signed in to rank an article. Not a member? Click here to register)

Latest Comments:
I seem to get a different order for the algorithm - Legacy CodeGuru (09/25/2002)
Does not work in the Debugger or from command line - Legacy CodeGuru (10/03/2000)
Dll which implicitly loads another dll - Legacy CodeGuru (12/01/1999)
OCX in DLL - Legacy CodeGuru (12/01/1999)
What about dlls already loaded by Windows (MSVCRT)? - Legacy CodeGuru (12/01/1999)

View All Comments
Add a Comment:
Title:
Comment:
Pre-Formatted: Check this if you want the text to display with the formatting as typed (good for source code)



(You must be signed in to comment on an article. Not a member? Click here to register)


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES