From 6e28b4892df485ed9a4f7c97bb043e23b5e618b4 Mon Sep 17 00:00:00 2001 From: Mark Young Date: Tue, 16 May 2017 07:03:56 -0600 Subject: loader: Expand lib search locations Expand library search locations based on recommendations by Dustin. We still attempt to use the old LoadLibrary first, and then, only if that fails, do we attempt to use the new search. Change-Id: I4cf1358f9eb7e45ac61f36435e926aa89c212f83 --- loader/vk_loader_platform.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'loader') diff --git a/loader/vk_loader_platform.h b/loader/vk_loader_platform.h index 0f71d9a3..8b82fe80 100644 --- a/loader/vk_loader_platform.h +++ b/loader/vk_loader_platform.h @@ -242,7 +242,15 @@ static char *loader_platform_basename(char *pathname) { // Dynamic Loading: typedef HMODULE loader_platform_dl_handle; -static loader_platform_dl_handle loader_platform_open_library(const char *libPath) { return LoadLibrary(libPath); } +static loader_platform_dl_handle loader_platform_open_library(const char *lib_path) { + // Try loading the library the original way first. + loader_platform_dl_handle lib_handle = LoadLibrary(lib_path); + if (lib_handle == NULL && GetLastError() == ERROR_MOD_NOT_FOUND && PathFileExists(lib_path)) { + // If that failed, then try loading it with broarder search folders. + lib_handle = LoadLibraryEx(lib_path, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR); + } + return lib_handle; +} static char *loader_platform_open_library_error(const char *libPath) { static char errorMsg[164]; (void)snprintf(errorMsg, 163, "Failed to open dynamic library \"%s\"", libPath); -- cgit v1.2.3