From 719dfecf95b0c74af6494f05049e56d5771ebfae Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Wed, 4 Oct 2017 10:20:45 +0200 Subject: [PATCH] win: fix non-English dlopen error message Extend https://github.com/libuv/libuv/pull/1116 to work on other Windows languages. PR-URL: https://github.com/libuv/libuv/pull/1585 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig --- src/win/dl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/win/dl.c b/src/win/dl.c index d454014d..97ac1c1a 100644 --- a/src/win/dl.c +++ b/src/win/dl.c @@ -89,9 +89,9 @@ static void uv__format_fallback_error(uv_lib_t* lib, int errorno){ static int uv__dlerror(uv_lib_t* lib, const char* filename, DWORD errorno) { - static const char not_win32_app_msg[] = "%1 is not a valid Win32 application"; DWORD_PTR arg; DWORD res; + char* msg; if (lib->errmsg) { LocalFree(lib->errmsg); @@ -114,16 +114,16 @@ static int uv__dlerror(uv_lib_t* lib, const char* filename, DWORD errorno) { 0, (LPSTR) &lib->errmsg, 0, NULL); } - /* Inexpert hack to get the filename into the error message. */ - if (res && strstr(lib->errmsg, not_win32_app_msg)) { - LocalFree(lib->errmsg); + if (res && errorno == ERROR_BAD_EXE_FORMAT && strstr(lib->errmsg, "%1")) { + msg = lib->errmsg; lib->errmsg = NULL; arg = (DWORD_PTR) filename; res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY | FORMAT_MESSAGE_FROM_STRING, - not_win32_app_msg, + msg, 0, 0, (LPSTR) &lib->errmsg, 0, (va_list*) &arg); + LocalFree(msg); } if (!res)