Make LoadLibrary() Failures Silent on Win2k

For a custom installer application, I have been working on a crude but efficient way to determine whether a particular version of the C runtime (CRT) needs to be installed or not. The technique I use is simply to check if a dummy DLL linked to the CRT libraries would load up properly.

Win2k LoadLibrary failure

This works well, except for one small detail. When the CRT is not installed, on Windows 2000 only, the LoadLibrary error would also cause a MessageBox to be displayed. This stops the flow of the installer and of course, is not very elegant…

But there is a simple trick to get rid of the MessageBox, using the very obscure SetErrorMode system call.

HMODULE hDll = ::LoadLibrary("CrtCheck.Dll"); // Won't bark
if (hDll)   ; // CRT is installed
else        ; // CRT is NOT installed

Do you guys know a better (yet simple) way to determine if the CRT is installed?

Update: this is not a Windows 2000 specific issue (thanks Ferruccio). It’s also true for older versions of Windows. As far as I know WinXP, Vista and 7 do NOT display a MessageBox under the same circumstances.