简体   繁体   中英

Dll dependency and search order

I have an A.DLL which dependent on B.DLL, so does the DLL search order that applies to applications also holds for DLLs, what I meant is when A.DLL is loaded then how does it search for B.DLL? If the DLL search order does not apply to DLLs, where should I keep the B.DLL? Should i keep it in the Current Directory where A.DLL is located or should I use form Environment paths

Note: I can't put B.DLL is System32

Any suggestions are appreciated.

The search order that applies to both exe and dll: https://docs.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-desktop-applications . The first one regardless of safe mode is always "The directory from which the application loaded." In terms of dll, according to my finding viaProcess Monitor , it depends on if the dll is statically linked or dynamically loaded via LoadLibrary . For static link, this is the directory of the dll, whereas for dynamic load, this is the directory of the exe.

For example, when C:\\App.exe loads D:\\A.dll , which depends on B.dll as in your example, Windows searches B.dll in D:\\ if static linked, or C:\\ if loaded with LoadLibrary . If B.dll is not found there, then it proceeds to search other directories such as System32.

Down that line of search order is "The current directory". Many applications that loads external modules may have SetDllDirectory("") to remove current directory in the search in order to avoid dll preloading vulnerability .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM