Skip to content

Commit da24813

Browse files
committed
Improve Dynamic Library for Windows
1 parent 396087b commit da24813

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

aten/src/ATen/DynamicLibrary.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,24 @@ DynamicLibrary::~DynamicLibrary() {
4646

4747
DynamicLibrary::DynamicLibrary(const char* name) {
4848
// NOLINTNEXTLINE(hicpp-signed-bitwise)
49-
HMODULE theModule = LoadLibraryA(name);
49+
HMODULE theModule;
50+
if (GetProcAddress(GetModuleHandle("KERNEL32.DLL"), "AddDllDirectory") != NULL) {
51+
theModule = LoadLibraryExA(
52+
name,
53+
NULL,
54+
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
55+
} else {
56+
theModule = LoadLibraryA(name);
57+
}
5058
if (theModule) {
5159
handle = theModule;
5260
} else {
53-
AT_ERROR("error in LoadLibraryA");
61+
char buf[256];
62+
DWORD dw = GetLastError();
63+
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
64+
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
65+
buf, (sizeof(buf) / sizeof(char)), NULL);
66+
AT_ERROR("error in LoadLibrary for ", name, ". WinError ", dw, ": ", buf);
5467
}
5568
}
5669

0 commit comments

Comments
 (0)