Allow plugins to load private DLL files from the plugins folder
The problem is the way Windows searches for dynamically linked DLLs (Dynamic-Link Library Search Order). For example, LuaScript.dll is the plug-in DLL, loaded by Notepad++.exe, and lua53.dll is the auxiliary DLL, required by LuaScript.dll and also by user-installed Lua modules. Both DLLs should be located in \plugins\LuaScript. But, when Notepad++ calls LoadLibrary to load LuaScript.dll, Windows will not find the dynamically linked lua53.dll, hence the LoadLibrary call fails. This happens, because Windows will look in the application directory (which is the location of Notepad++.exe), and not in the LuaScript.dll directory. To make Windows search in the LuaScript.dll directory, Notepad++ needs to call LoadLibraryEx with the LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR flag. Close #5802, close #5853
This commit is contained in:
parent
6c034985a2
commit
31ae813286
@ -114,6 +114,9 @@ cleanup: // release all of our handles
|
||||
return machine_type;
|
||||
}
|
||||
|
||||
#define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100
|
||||
#define LOAD_LIBRARY_SEARCH_DEFAULT_DIRS 0x00001000
|
||||
|
||||
int PluginsManager::loadPlugin(const TCHAR *pluginFilePath)
|
||||
{
|
||||
const TCHAR *pluginFileName = ::PathFindFileName(pluginFilePath);
|
||||
@ -130,7 +133,8 @@ int PluginsManager::loadPlugin(const TCHAR *pluginFilePath)
|
||||
if (GetBinaryArchitectureType(pluginFilePath) != ARCH_TYPE)
|
||||
throw generic_string(ARCH_ERR_MSG);
|
||||
|
||||
pi->_hLib = ::LoadLibrary(pluginFilePath);
|
||||
const DWORD dwFlags = GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "AddDllDirectory") != NULL ? LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0;
|
||||
pi->_hLib = ::LoadLibraryEx(pluginFilePath, NULL, dwFlags);
|
||||
if (!pi->_hLib)
|
||||
{
|
||||
generic_string lastErrorMsg = GetLastErrorAsString();
|
||||
|
Loading…
Reference in New Issue
Block a user