Changing dlopen to use LOAD_LIBRARY_SEARCH_DEFAULT_DIRS rather than LOAD_WITH_ALTERED_SEARCH_PATH
Currently, we use the windows “Alternate Search Order” to find DLLs. I propose that we use a new mechanism that is extensible via the Windows API.
Currently we use LOAD_WITH_ALTERED_SEARCH_PATH
On Windows, we currently use LOAD_WITH_ALTERED_SEARCH_PATH with LoadLibraryExW:
The Alternate Search Order for Desktop Applications is only extensible by appending the PATH environment variable.
Proposal: Use LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
After reading through the documentation on LoadLibraryExW when researching an issue GR.jl, I think we should use LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR.
If we use LOAD_LIBRARY_SEARCH_DEFAULT_DIRS then we could use AddDllDirectory to add directories to the search path. LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR also allows us to use the directory where the DLL is located.
The minimum version supported is Windows 7 with KB2533623: Insecure library loading could allow remote code execution.
Background reading: Cpython bpo36085, github 80266
Since Python 3.8, ctypes uses this approach: