Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32 | LOAD_LIBRARY_SEARCH_USER_DIRS for DLL loading on Windows #47775

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ JL_DLLEXPORT void *jl_dlopen(const char *filename, unsigned flags) JL_NOTSAFEPOI
WCHAR *wfilename = (WCHAR*)alloca(len * sizeof(WCHAR));
if (!MultiByteToWideChar(CP_UTF8, 0, filename, -1, wfilename, len)) return NULL;
HANDLE lib = LoadLibraryExW(wfilename, NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
if (!lib)
{
/* If loading with LOAD_WITH_ALTERED_SEARCH_PATH fails,
search user directories added with `AddDllDirectory`.
In Julia on Windows, user directories can be added to the DLL search path as follows.
`library::String = pwd()`
`@ccall "kernel32".AddDllDirectory(library::Cwstring)::Ptr{Nothing}`
https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-adddlldirectory
Consider `LOAD_LIBRARY_SEARCH_DEFAULT_DIRS` or
`LOAD_LIBRARY_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR` for use below. */
lib = LoadLibraryExW(wfilename, NULL, LOAD_LIBRARY_SEARCH_USER_DIRS);
}
mkitti marked this conversation as resolved.
Show resolved Hide resolved
if (lib)
needsSymRefreshModuleList = 1;
return lib;
Expand Down