Skip to content

Commit a0de20c

Browse files
committed
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.
1 parent dd84715 commit a0de20c

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

source/common/windows/ur_lib_loader.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void LibLoader::freeAdapterLibrary(HMODULE handle) {
1717
BOOL res = FreeLibrary(handle);
1818
if (!res) {
1919
logger::error(
20-
"Failed to unload the library with the handle at address {}",
20+
"Failed to unload the library with the handle at address 0x{}",
2121
handle);
2222
} else {
2323
logger::info("unloaded adapter 0x{}", handle);
@@ -27,10 +27,14 @@ void LibLoader::freeAdapterLibrary(HMODULE handle) {
2727

2828
std::unique_ptr<HMODULE, LibLoader::lib_dtor>
2929
LibLoader::loadAdapterLibrary(const char *name) {
30-
auto handle = std::unique_ptr<HMODULE, LibLoader::lib_dtor>(
31-
LoadLibraryExA(name, nullptr, 0));
32-
logger::info("loaded adapter 0x{} ({})", handle, name);
33-
return handle;
30+
if (HMODULE handle = LoadLibraryExA(name, nullptr, 0)) {
31+
logger::info("loaded adapter 0x{}: {}", handle, name);
32+
return std::unique_ptr<HMODULE, LibLoader::lib_dtor>{handle};
33+
} else {
34+
logger::debug("loading adapter failed with error {}: {}",
35+
GetLastError(), name);
36+
}
37+
return nullptr;
3438
}
3539

3640
void *LibLoader::getFunctionPtr(HMODULE handle, const char *func_name) {

0 commit comments

Comments
 (0)