Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silently catch windows error popups when calling LoadLibrary()

Tags:

winapi

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() ?

like image 375
Franck Freiburger Avatar asked Dec 28 '22 05:12

Franck Freiburger


1 Answers

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.

like image 130
Frédéric Hamidi Avatar answered Apr 17 '23 12:04

Frédéric Hamidi