Windows: Set error mode before calling LoadLibrary()

Unless SEM_FAILCRITICALERRORS is set, Windows may pop-up a dialog box
if the specified module cannot be loaded.  This is not appropriate for
unattended or batch processes.
This commit is contained in:
Asanka C. Herath
2010-11-22 15:01:41 -05:00
parent 5b91a397f8
commit 0ae44152b7

View File

@@ -134,6 +134,7 @@ ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
dlopen(const char *fn, int flags) dlopen(const char *fn, int flags)
{ {
HMODULE hm; HMODULE hm;
UINT old_error_mode;
/* We don't support dlopen(0, ...) on Windows.*/ /* We don't support dlopen(0, ...) on Windows.*/
if ( fn == NULL ) { if ( fn == NULL ) {
@@ -141,12 +142,16 @@ dlopen(const char *fn, int flags)
return NULL; return NULL;
} }
old_error_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
hm = LoadLibrary(fn); hm = LoadLibrary(fn);
if (hm == NULL) { if (hm == NULL) {
set_error_from_last(); set_error_from_last();
} }
SetErrorMode(old_error_mode);
return (void *) hm; return (void *) hm;
} }