Skip to content

Commit ea58af4

Browse files
author
Rafael Stahl
committed
hl_test: improve error logging when library load fails
1 parent 8fa0e4a commit ea58af4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/test/main.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,29 @@ int main(int argc, char* argv[])
3434

3535
std::remove("hl_test_success");
3636

37+
std::string error;
3738
#ifdef WIN32
3839
auto result = (void*)LoadLibrary("hl_test_hostd.dll");
40+
if (!result)
41+
{
42+
DWORD code = GetLastError();
43+
LPVOID buf = NULL;
44+
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
45+
NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, NULL);
46+
error = (char*)buf;
47+
LocalFree(buf);
48+
}
3949
#else
4050
auto result = dlopen("./libhl_test_hostd.so", RTLD_NOW | RTLD_LOCAL);
51+
if (!result)
52+
{
53+
error = dlerror();
54+
}
4155
#endif
4256

4357
if (result == NULL)
4458
{
45-
printf("Failed to load hl_test_host shared library\n");
59+
printf("Failed to load hl_test_host shared library: %s\n", error.c_str());
4660
return 1;
4761
}
4862

0 commit comments

Comments
 (0)