I have created a application which copies files from hard disk to Floppy drive using the CopyFile() API. In the middle of the copy process for a large file, if the floppy is removed from the drive then windows system popup's up an error message.
I want to suppress this error message that is popped up by the system. I googled and read about SetErrorMode() API used by many applications to solve similar issues and tried using it with all the possible flag options but it fails. Sample code -
UINT uOldErrorMode = SetErrorMode (SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); ::CopyFile("C:\text.dat","A:\text.dat", FALSE); SetErrorMode (uOldErrorMode);
SetErrorMode() API fails to suppress the error message. Can anyone help me in understanding why is it not working with for my application?
I then came across the below link : http://support.microsoft.com/kb/128642 which talks about the key
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Windows\ErrorMode
whose value can be set to 0,1 or 2 to suppress or show the error messages. This solution works for my application but I feel that
a. It is not a good programming practices to access the system key directly? there should be a API that should do this. b. Such a code shall fail the UAC when executed on Windows Vista or Windows 7.
Can anybody please provide some help with the above issue.
Regards, Felix