The search order for. dll

Source: Internet
Author: User

"Windows Core Programming (5th edition)" P522

19.2.3 Run the executable module:

Because the import segment contains only the name of the DLL and does not contain the path to the DLL, the loader must search for the DLL on the user's disk. The following is the search order for the loader:

(1) The path that contains the executable file;

(2) The system directory of Windows, which is obtained by getsystemdirectory;

(3) A 16-bit system directory, that is, the systems subdirectory in the Windows directory;

(4) The Windows directory, which can be obtained by getwindowsdirectory;

(5) The current directory of the process;

(6) The directory listed in the PATH environment variable.




Test environment: Win7u + VS2008SP1

The paths in the above sequence are understood to be:

The directory where the. exe file for the test generated by "1" VS2008.

"2" C:/WINDOWS/SYSTEM32;

"3" C:/windows/system;

"4" c:/windows;

"5" VS2008 in the directory where the project files (. vcproj file directory, that is, the project default path);

The "6" PATH environment variable is listed as a directory.

After testing, the search order is from "1" to "6" priority.

P.S: Previously heard that the environment variable settings do not need to restart the system can be effective, in the process of testing found that is not the case.




setdlldirectory Function

The setdlldirectory function affects all subsequent calls to the LoadLibrary and LoadLibraryEx Functions. It also effectively disables safe DLL search mode while the specified directory are in the search path.

After calling Setdlldirectory, the standard DLL search path is:

1. The directory from which the application loaded.

2. The directory specified by the Lppathname parameter. (Note: Lppathname is a setdlldirectory parameter.) )

3. The system directory. Use the ' getsystemdirectory function to ' the ' path ' of this directory. The name of this directory is System32.

4. The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched. The name of this directory is System.

5. The Windows directory. Use the ' getwindowsdirectory function to ' the ' path ' of this directory.

6. The directories that are listed in the PATH environment variable.

The setdlldirectory function is called, it replaces the directory specified in the previous Setdlld Irectory call. To specify more than one directory, use the adddlldirectory function and call LoadLibraryEx with Load_li Brary_search_user_dirs.

To revert to the standard search path used by LoadLibrary and LoadLibraryEx, call setdlldirectory with NULL. This is also restores safe DLL search mode based on the SafeDllSearchMode registry value.

To compile a application that uses this function, define _WIN32_WINNT as 0x0502 or later. For more information, you are Using the Windows Headers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.