From 5dd826ee388bf3d6d6331c73558616fdd70b5fb6 Mon Sep 17 00:00:00 2001 From: HarrievG <061623@gmail.com> Date: Mon, 18 Jan 2021 00:36:02 +0100 Subject: [PATCH] Dll load errors (#1) * Windows DLL-Load-Errors Added error reporting using formatmessage, ignoring if the DLL just doesn't exist, custom warning for "[193 (0xC1)] is not a valid Win32 application." (probably wrong architecture) * update gitignore with build folder --- .gitignore | 4 ++++ neo/sys/win32/win_main.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8f05fb06..258b4d5a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,7 @@ /dhewm* /*-releases/ +/neo/.vs* +/neo/out* +/neo/build* + diff --git a/neo/sys/win32/win_main.cpp b/neo/sys/win32/win_main.cpp index 997352a6..0a92dcc4 100644 --- a/neo/sys/win32/win_main.cpp +++ b/neo/sys/win32/win_main.cpp @@ -602,7 +602,31 @@ uintptr_t Sys_DLL_Load( const char *dllName ) { } } else { DWORD e = GetLastError(); - // TODO + LPVOID msgBuf = nullptr; + + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + e, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&msgBuf, + 0, NULL); + + idStr errorStr = va( "[%i (0x%X)]\t%s", e, e, msgBuf ); + + // common, skipped. + if ( e == 0x7E ) // [126 (0x7E)] The specified module could not be found. + errorStr = ""; + // probably going to be common. Lets try to be less cryptic. + else if ( e == 0xC1 ) // [193 (0xC1)] is not a valid Win32 application. + errorStr = va( "[%i (0x%X)]\t%s", e, e, "probably the DLL is of the wrong architecture, like x64 instead of x86" ); + + if ( errorStr.Length() ) + common->Warning( "LoadLibrary(%s) Failed ! %s", dllName, errorStr.c_str() ); + + ::LocalFree( msgBuf ); } return (uintptr_t)libHandle; }