19 #ifndef COMPAT_W32DLFCN_H
20 #define COMPAT_W32DLFCN_H
25 #if (_WIN32_WINNT < 0x0602) || HAVE_WINRT
35 static inline HMODULE win32_dlopen(
const char *
name)
37 #if _WIN32_WINNT < 0x0602
39 if (!GetProcAddress(GetModuleHandleW(
L"kernel32.dll"),
"SetDefaultDllDirectories")) {
40 HMODULE module =
NULL;
41 wchar_t *path =
NULL, *name_w =
NULL;
43 if (utf8towchar(
name, &name_w))
47 pathlen = GetModuleFileNameW(
NULL, path, MAX_PATH);
48 pathlen = wcsrchr(path,
'\\') - path;
49 if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
52 wcscpy(path + pathlen + 1, name_w);
53 module = LoadLibraryExW(path,
NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
56 pathlen = GetSystemDirectoryW(path, MAX_PATH);
57 if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH)
60 wcscpy(path + pathlen + 1, name_w);
61 module = LoadLibraryExW(path,
NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
69 #ifndef LOAD_LIBRARY_SEARCH_APPLICATION_DIR
70 # define LOAD_LIBRARY_SEARCH_APPLICATION_DIR 0x00000200
72 #ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
73 # define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
76 wchar_t *name_w =
NULL;
78 if (utf8towchar(
name, &name_w))
80 ret = LoadPackagedLibrary(name_w, 0);
84 return LoadLibraryExA(
name,
NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32);
87 #define dlopen(name, flags) win32_dlopen(name)
88 #define dlclose FreeLibrary
89 #define dlsym GetProcAddress