From: Ivan Maidanski Date: Sat, 2 Aug 2014 08:17:57 +0000 (+0400) Subject: Resolve MessageBoxA at run-time (if requested) in GC_init (Win32) X-Git-Tag: gc7_6_0~199^2~18 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=afe7a3308288fcd519d418b78ca6f04499887d3a;p=gc Resolve MessageBoxA at run-time (if requested) in GC_init (Win32) (and code refactoring of GC_abort) * misc.c (GC_win32_MessageBoxA): New static routine (only if MSWIN32, move code from GC_abort). * misc.c (GC_init, GC_abort): Replace MessageBoxA with GC_win32_MessageBoxA call (to resolve "MessageBoxA" at run-time if DONT_USE_USER32_DLL). Conflicts: misc.c --- diff --git a/misc.c b/misc.c index 6e56c3a2..7db5a88c 100644 --- a/misc.c +++ b/misc.c @@ -795,6 +795,29 @@ GC_INNER GC_bool GC_is_initialized = FALSE; } #endif +#if defined(MSWIN32) && (!defined(SMALL_CONFIG) \ + || (!defined(_WIN64) && defined(GC_WIN32_THREADS) \ + && defined(CHECK_NOT_WOW64))) + STATIC void GC_win32_MessageBoxA(const char *msg, const char *caption, + unsigned flags) + { +# ifndef DONT_USE_USER32_DLL + /* Use static binding to "user32.dll". */ + (void)MessageBoxA(NULL, msg, caption, flags); +# else + /* This simplifies linking - resolve "MessageBoxA" at run-time. */ + HINSTANCE hU32 = LoadLibrary(TEXT("user32.dll")); + if (hU32) { + FARPROC pfn = GetProcAddress(hU32, "MessageBoxA"); + if (pfn) + (void)(*(int (WINAPI *)(HWND, LPCSTR, LPCSTR, UINT))pfn)( + NULL /* hWnd */, msg, caption, flags); + (void)FreeLibrary(hU32); + } +# endif + } +#endif /* MSWIN32 */ + STATIC word GC_parse_mem_size_arg(const char *str) { char *endptr; @@ -866,7 +889,7 @@ GC_API void GC_CALL GC_init(void) && (*(BOOL (WINAPI*)(HANDLE, BOOL*))pfn)(GetCurrentProcess(), &bIsWow64) && bIsWow64) { - MessageBoxA(NULL, "This program uses BDWGC garbage collector" + GC_win32_MessageBoxA("This program uses BDWGC garbage collector" " compiled for 32-bit but running on 64-bit Windows.\n" "This is known to be broken due to a design flaw" " in Windows itself! Expect erratic behavior...", @@ -1686,22 +1709,7 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void) if (msg != NULL) { # if defined(MSWIN32) -# ifndef DONT_USE_USER32_DLL - /* Use static binding to "user32.dll". */ - (void)MessageBoxA(NULL, msg, "Fatal error in GC", - MB_ICONERROR | MB_OK); -# else - /* This simplifies linking - resolve "MessageBoxA" at run-time. */ - HINSTANCE hU32 = LoadLibrary(TEXT("user32.dll")); - if (hU32) { - FARPROC pfn = GetProcAddress(hU32, "MessageBoxA"); - if (pfn) - (void)(*(int (WINAPI *)(HWND, LPCSTR, LPCSTR, UINT))pfn)( - NULL /* hWnd */, msg, "Fatal error in GC", - MB_ICONERROR | MB_OK); - (void)FreeLibrary(hU32); - } -# endif + GC_win32_MessageBoxA(msg, "Fatal error in GC", MB_ICONERROR | MB_OK); /* Also duplicate msg to GC log file. */ # endif