Is it possible to silently catch errors popup like "the procedure entry point xxx could not be located int the dynamic link library xxx" when calling LoadLibrary() ?
+3
A:
You can suppress the error popups by calling SetErrorMode():
// GetErrorMode() only exists on Vista and higher,
// call SetErrorMode() twice to achieve the same effect.
UINT oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS);
SetErrorMode(oldErrorMode | SEM_FAILCRITICALERRORS);
HMODULE library = LoadLibrary("YourLibrary.dll");
// Restore previous error mode.
SetErrorMode(oldErrorMode);
The call to LoadLibrary() will still fail, though.
Frédéric Hamidi
2010-10-30 10:46:20
Thanks a lot for the trick !
Soubok
2010-10-30 11:20:23
perhaps the fist call could be oldErrorMode = SetErrorMode(0) ?
Soubok
2010-10-30 11:23:20
That's debatable :) Another thread could have called `SetErrorMode(SEM_FAILCRITICALERRORS)`, so it would be problematic to reset the error mode, even for a short time. Remember, `SetErrorMode()` is process-scoped. [SetThreadErrorMode()](http://msdn.microsoft.com/en-us/library/dd553630%28v=VS.85%29.aspx) is thread-scoped, but it's only supported on Windows 7 / Server 2008 R2 and higher.
Frédéric Hamidi
2010-10-30 11:33:46