From da5befe0a244e0230b4375e9100dccd6fcdd7447 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Thu, 21 Nov 2024 10:48:34 +0000 Subject: [PATCH] Improve logging of loading adapters on Windows This primarily improves the logging when loading an adapter fails on Windows by printing out the result of `GetLastError()` when `LoadLibrarExA()` returns null for cross-reference with https://learn.microsoft.com/en-us/windows/win32/debug/system-error-codes. --- source/common/windows/ur_lib_loader.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/common/windows/ur_lib_loader.cpp b/source/common/windows/ur_lib_loader.cpp index db6d5b3a17..6706c7f938 100644 --- a/source/common/windows/ur_lib_loader.cpp +++ b/source/common/windows/ur_lib_loader.cpp @@ -17,7 +17,7 @@ void LibLoader::freeAdapterLibrary(HMODULE handle) { BOOL res = FreeLibrary(handle); if (!res) { logger::error( - "Failed to unload the library with the handle at address {}", + "Failed to unload the library with the handle at address 0x{}", handle); } else { logger::info("unloaded adapter 0x{}", handle); @@ -27,10 +27,14 @@ void LibLoader::freeAdapterLibrary(HMODULE handle) { std::unique_ptr LibLoader::loadAdapterLibrary(const char *name) { - auto handle = std::unique_ptr( - LoadLibraryExA(name, nullptr, 0)); - logger::info("loaded adapter 0x{} ({})", handle, name); - return handle; + if (HMODULE handle = LoadLibraryExA(name, nullptr, 0)) { + logger::info("loaded adapter 0x{}: {}", handle, name); + return std::unique_ptr{handle}; + } else { + logger::debug("loading adapter failed with error {}: {}", + GetLastError(), name); + } + return nullptr; } void *LibLoader::getFunctionPtr(HMODULE handle, const char *func_name) {