SetDefaultDllDirectories function (libloaderapi.h)
Specifies a default set of directories to search when the calling process loads a DLL. This search path is used when LoadLibraryEx is called with no LOAD_LIBRARY_SEARCH flags.
BOOL SetDefaultDllDirectories( [in] DWORD DirectoryFlags );
The directories to search. This parameter can be any combination of the following values.
||If this value is used, the application's installation directory is searched.|
This value is a combination of LOAD_LIBRARY_SEARCH_APPLICATION_DIR,
This value represents the recommended maximum number of directories an application should include in its DLL search path.
||If this value is used, %windows%\system32 is searched.|
||If this value is used, any path explicitly added using the AddDllDirectory or SetDllDirectory function is searched. If more than one directory has been added, the order in which those directories are searched is unspecified.|
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
The DLL search path is the set of directories that are searched for a DLL when a full path is not specified in a LoadLibrary or LoadLibraryEx function call, or when a full path to the DLL is specified but the system must search for dependent DLLs. For more information about the standard DLL search path, see Dynamic-Link Library Search Order.
The standard DLL search path contains directories that can be vulnerable to a DLL pre-loading attack. An application can use the SetDefaultDllDirectories function to specify a default DLL search path for the process that eliminates the most vulnerable directories and limits the other directories that are searched. The process DLL search path applies only to the calling process and persists for the life of the process.
If the DirectoryFlags parameter specifies more than one flag, the directories are searched in the following order:
- The directory that contains the DLL (LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR). This directory is searched only for dependencies of the DLL being loaded.
- The application directory (LOAD_LIBRARY_SEARCH_APPLICATION_DIR).
- Paths explicitly added to the application search path with the AddDllDirectory function (LOAD_LIBRARY_SEARCH_USER_DIRS) or the SetDllDirectory function. If more than one path has been added, the order in which the paths are searched is unspecified.
- The System directory (LOAD_LIBRARY_SEARCH_SYSTEM32).
It is not possible to revert to the standard DLL search path or remove any directory specified with SetDefaultDllDirectories from the search path. However, the process DLL search path can be overridden by calling LoadLibraryEx with one or more LOAD_LIBRARY_SEARCH flags, and directories added with AddDllDirectory can be removed by calling RemoveDllDirectory.
Windows 7, Windows Server 2008 R2, Windows Vista and Windows Server 2008: To call this function in an application, use the GetProcAddress function to retrieve its address from Kernel32.dll. KB2533623 must be installed on the target platform.
|Minimum supported client||Windows 8 [desktop apps only],KB2533623 on Windows 7, Windows Server 2008 R2, Windows Vista, and Windows Server 2008|
|Minimum supported server||Windows Server 2012 [desktop apps only]|
|Header||libloaderapi.h (include Windows.h)|
Dynamic-Link Library Search Order