GModule win32: disable error dialog popup

When loading a module on win32, a blocking error dialog pops up whenever
the module could not be loaded. This is particularly annoying when
module loading failure is a harmless and expected event...

This patch temporarily disables these error dialogs from popping up.

https://bugzilla.gnome.org/show_bug.cgi?id=777308
This commit is contained in:
Tom Schoonjans 2017-01-16 11:39:49 +05:30 committed by Philip Withnall
parent 54f6c56235
commit 719edde63b

View File

@ -70,6 +70,8 @@ _g_module_open (const gchar *file_name,
{ {
HINSTANCE handle; HINSTANCE handle;
wchar_t *wfilename; wchar_t *wfilename;
DWORD old_mode;
BOOL success;
#ifdef G_WITH_CYGWIN #ifdef G_WITH_CYGWIN
gchar tmp[MAX_PATH]; gchar tmp[MAX_PATH];
@ -78,7 +80,13 @@ _g_module_open (const gchar *file_name,
#endif #endif
wfilename = g_utf8_to_utf16 (file_name, -1, NULL, NULL, NULL); wfilename = g_utf8_to_utf16 (file_name, -1, NULL, NULL, NULL);
/* suppress error dialog */
success = SetThreadErrorMode (SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS, &old_mode);
if (!success)
set_error ("");
handle = LoadLibraryW (wfilename); handle = LoadLibraryW (wfilename);
if (success)
SetThreadErrorMode (old_mode, NULL);
g_free (wfilename); g_free (wfilename);
if (!handle) if (!handle)