. Dll search sequence

Source: Internet
Author: User

Windows core programming (version 5th) p522

19.2.3 run the executable module:

Because the import segment only contains the DLL name and does not contain the dll path, loadProgramYou must search for DLL on your disk. The following is the search order of the loaded program:

(1) path containing executable files;

(2) Windows System directory, which is obtained through getsystemdirectory;

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

(4) Windows Directory, which can be obtained through getwindowsdirectory;

(5) Current Directory of the process;

(6) Directories listed in PATH environment variables.

 

Test environment: win7u + vs2008sp1

The paths in the above sequence are understood:

[1] Directory of the. exe file generated by vs2008 for testing;

[2] C:/Windows/system32;

[3] C:/Windows/system;

[4] C:/windows;

[5] Directory of the project file in vs2008 (. vcproj file directory, that is, the default project path );

[6] any directory listed in the PATH environment variable.

 

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

 

P.s.: I have heard that the environment variable setting will take effect without restarting the system. This is not the case during the test.

---- [2011.08.12 update] ----

Setdlldirectory Function

TheSetdlldirectoryFunction affects all subsequent calltoLoadlibraryAndLoadLibraryExFunctions.
It also specified tively disables Safe DLL search mode while the specified directory is in the search path.

After callingSetdlldirectory, The standard DLL search path is:

1. The directory from which the application loaded.

2. The directory specified byLppathnameParameter. (Note:LppathnameIs the parameter of setdlldirectory .)

3. The system directory. UseGetsystemdirectoryFunction to get the path of this directory. The name
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. UseGetwindowsdirectoryFunction to get the path of this directory.

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

Each timeSetdlldirectoryFunction is called, it replaces the directory specified in the previousSetdlldirectoryCall. to specify more than one directory, useAdddlldirectoryFunction
And callLoadLibraryExWith load_library_search_user_dirs.

To revert to the standard search path usedLoadlibraryAndLoadLibraryEx,
CallSetdlldirectoryWith null. This also restores Safe DLL Search Mode Based onSafeDllSearchModeRegistry value.

To compile an application that uses this function, define _ win32_winnt as 0x0502 or later. For more information, see 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.