0
votes

I need to use libcurl.dll in my program(the binary rely on libcurl.dll in my program is "A.exe"), the libcurl.dll rely on zlib1.dll, libeay32.dll, ssleay32.dll. but there is another version libeay32.dll which already exists in the folder of A.exe. So I plan to create a folder "CURL" an put the new 4 DLL I introduced this time, and then use dynamic DLL load to invoke the libcurl.dll.

=====================

Main folder

|

A.exe, 

libeay32.dll(old one),

Folder "CURL"  -----

                  | 
                  |
                libcurl.dll, zlib1.dll, libeay32.dll, ssleay32.dll

=====================

Question is that how can I control my program to load the DLL in Folder "CURL". I can control "A.exe" load CURL\libcurl.dll by call

HMODULE hModule = LoadLibrary(_T("Curl\libcurl.dll")); But how can I control the path of zlib1.dll, libeay32.dll, ssleay32.dll. It seems that windows search the DLL in the folder which A.exe local in default.

2
I find a solution which can work on high version OS. load the DLL by using: LoadLibraryEx("FullPathofA.exe" , NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_DEFAULT_DIRS); Is there a method work on low version OS. Windows 7, Windows Server 2008 R2, Windows Vista, and Windows Server 2008: This value requires KB2533623 to be installed. Windows Server 2003 and Windows XP: This value is not supported.Leon
I don't think this scheme will work: libeay32.dll is already loaded, so it won't be loaded again - even if the versions would differ !MSalters
@MSalters But what if he loads the right version of libeay32.dll, as I said, before loading libcurl.dll?SamuelVimes
@SamuelVimes: If it's upwards compatible, it will work. This is not a given.MSalters

2 Answers

0
votes

Use include directorys settings of your compiler. or / and make use of windows logic to find dependent dll's. (You can use tools as filemon or process monitor to see which directory's are beeing looked up)

Use the search path of windows. Order is:

  1. The directory where the executable module for the current process is located.

  2. The current directory.

  3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.

  4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.

  5. The directories listed in the PATH environment variable.

0
votes

You should be able to load it with LoadLibrary if you specify the full path to the dll instead of a relative one in the call. When using only the filename or a relative path the search order is as said by lordKain (unless you modify it, for example by calling SetDllDirectory) but when using full path it should only search in the location specified. You can load first in this way the version of libeay32.dll that you need, so that when you load libcurl.dll, the version of libeay32.dll that you want is already loaded. Also be careful that there is no dll redirection manifest.