Useful Win API function -- SetErrorMode

Hi everyone!

I am new to the world of Delphi and the Windows API, so I was pretty e{*word*277}d
when I stumbled across the solution to a problem that has been plaguing me for
weeks!!!  I thought I'd post it in case someone else is struggling with the
same problem.

BACKGROUND:  I am writing an application that reports various statistics about
a PC.  Included in these statistics is a listing of the total capacity of
system disk
drives and total free space of these disk drives.  

ORIGINAL PROBLEM:  Whenever I tried to report the size of a floppy or cd-rom
drive that
was empty, I received a system modal dialog from windows stating that my drive
was
not ready or not working properly.  Exception handling would not handle this
error...
Windows was taking control immediately after I accessed the drive.

INITIAL REACTION:  Confusion and frustration... until I found the SetErrorMode
API function.

SOLUTION:  Call the SetErrorMode Windows API function (available in the
WinProcs unit
in Delphi).  

To quote the Windows API Help file directly, "The SetErrorMode function
controls whether Windows handles MS-DOS Interrupt 24h errors or allows the
calling application to handle them."

To rephrase this in plain english, this function allows you take control of
error handling
that would normally be done automatically by Windows.  For my particular
program, I
made the following call...

SetErrorMode(SEM_FAILCRITICALERRORS);

The SEM_FAILCRITICALERRORS function basically tells Windows not to display the
"critical-error-handler" message box when accessing an empty drive -- just
return the error
to the calling application.

As a result, I am now able to proceed normally as I loop through all of the
available
drives on my system -- even if they don't contain a disk.

CONCLUSION:  I can now sleep at night knowing that this is no longer a problem
;)

Hope this helps somebody!!!

Scott