Skip to content

Instantly share code, notes, and snippets.

@robUx4
Created March 8, 2017 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robUx4/a38d222e9510459cdb14319fa005995a to your computer and use it in GitHub Desktop.
Save robUx4/a38d222e9510459cdb14319fa005995a to your computer and use it in GitHub Desktop.
libbluray LoadLibraryEx
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