Monday, August 10, 2009

Windows DLL load order

So when you work with Windows NT services, you might want to make sure the right DLLs are loaded at the proper time. When debugging issues on NT service startup time, this becomes important. On Windows, the order of DLL loading is as follows (see also Visual C++'s help on LoadLibrary()):

  1. The directories listed in the App Path registry key (if any)
  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.
To set an 'App Path' for your application (text.exe), set the (Default) value of
KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\test.exe
to the full path of your executable, for example:
C:\Program Files\Test\test.exe

Add a sub-key named Path, set it's value to the full path of the DLL, for example:

C:\Program Files\Test\lib
Use regedit see examples of other applications, and how they setup their App Path keys.

1 comment:

  1. That’s nice blog , its help you to remove rundll error , click this link and get a free from rundll error .
    How To Remove Rundll Error
    Aalia lyon