Reputation: 690
I'm trying to load a dll (through LoadLibraryA) from another dll. This is the problem:
c:\**EXE_DIR**\myExe.exe // this exe load the MY_DLL_N1.dll
c:\**DLLS_DIR**\MY_DLL_N1.dll // this dll load the MY_DLL_N2.dll
c:\**DLLS_DIR**\MY_DLL_N2.dll
int LoadMyDLL()
{
// ...
// same path of the MY_DLL_N1.dll ... right?
handle = LoadLibraryA ("MY_DLL_N2.dll");
// ...
}
that's all .... any help is welcome!
Upvotes: 1
Views: 11054
Reputation: 104569
Everything you need to know is located here: Dynamic-Link Library Search Order.
Consider using SetDllDirectory to add your DLL path to the LoadLibrary search path.
Upvotes: 4
Reputation: 613442
handle = LoadLibraryA ("MY_DLL_N2.dll");
Because you do not supply a path, the DLL search order is used. This will look in the executable's directory, but will not search in the directories of any DLLS that are loaded. Hence the failure to find the DLL.
You have a number of options:
Unless you have a need to share the DLLS between different applications, option 1 is always preferred. This makes it easy for you to be sure that the DLLs you load are the right ones. That's because the executable directory is always searched first.
Upvotes: 2