Created
March 8, 2017 13:12
-
-
Save robUx4/a38d222e9510459cdb14319fa005995a to your computer and use it in GitHub Desktop.
libbluray LoadLibraryEx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void *_load_dll(const wchar_t *lib_path, const wchar_t *dll_search_path) | |
{ | |
void *result; | |
PVOID WINAPI (*pAddDllDirectory) (PCWSTR); | |
BOOL WINAPI (*pRemoveDllDirectory)(PVOID); | |
pAddDllDirectory = (__typeof__(pAddDllDirectory)) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "AddDllDirectory"); | |
pRemoveDllDirectory = (__typeof__(pRemoveDllDirectory)) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "RemoveDllDirectory"); | |
if (pAddDllDirectory && pRemoveDllDirectory) { | |
result = LoadLibraryExW(lib_path, NULL, | |
LOAD_LIBRARY_SEARCH_SYSTEM32); | |
if (!result) { | |
PVOID cookie = pAddDllDirectory(dll_search_path); | |
result = LoadLibraryExW(lib_path, NULL, | |
LOAD_LIBRARY_SEARCH_SYSTEM32 | | |
LOAD_LIBRARY_SEARCH_USER_DIRS); | |
pRemoveDllDirectory(cookie); | |
} | |
} else { | |
result = LoadLibraryW(lib_path); | |
if (!result) { | |
SetDllDirectoryW(dll_search_path); | |
result = LoadLibraryW(lib_path); | |
SetDllDirectoryW(L""); | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment