SetErrorMode in windows version of ImageMagick
Posted: 2013-09-17T06:24:24-07:00
Hi!
I'm using ImageMagick to read info and convert images in an automated process, and sometimes the reading / conversion fails. This can happen for a number of reasons out of my control, such as corrupt files, corrupt media, access restrictions. Why it fails in the first place is not really important for my suggestion, the point is that it fails sometimes and that i have to deal with that.
I really don't want a windows crash dialog / error report dialog, which is why I use the following snippet of code in my application:
This suppresses the crash messages that I don't want for my applications, and it is also inherited by other processes that i start. My problem is that ImageMagick seems to set the ErrorMode itself (nt-base.c:1575):
As you can see there is an option that I use, but is not used in ImageMagick:
This option means: "The system does not display the Windows Error Reporting dialog." See specification: http://msdn.microsoft.com/en-us/library ... s.85).aspx
So when I start ImageMagick from my application, the ErrorMode is inherited and this option is enabled. But ImageMagick sets the ErrorMode itself disabling this option, which makes windows display the error reporting dialog when ImageMagick crashes.
I propose the following two alternative solutions:
1.
Change the call to:
2.
First read the current ErrorMode (possibly inherited by parent process), then add the two current options to them:
See: http://msdn.microsoft.com/en-us/library ... s.85).aspx
I'm using ImageMagick to read info and convert images in an automated process, and sometimes the reading / conversion fails. This can happen for a number of reasons out of my control, such as corrupt files, corrupt media, access restrictions. Why it fails in the first place is not really important for my suggestion, the point is that it fails sometimes and that i have to deal with that.
I really don't want a windows crash dialog / error report dialog, which is why I use the following snippet of code in my application:
Code: Select all
SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX);
Code: Select all
mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
Code: Select all
ErrorModes.SEM_NOGPFAULTERRORBOX
So when I start ImageMagick from my application, the ErrorMode is inherited and this option is enabled. But ImageMagick sets the ErrorMode itself disabling this option, which makes windows display the error reporting dialog when ImageMagick crashes.
I propose the following two alternative solutions:
1.
Change the call to:
Code: Select all
mode=SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | SEM_NOGPFAULTERRORBOX);
First read the current ErrorMode (possibly inherited by parent process), then add the two current options to them:
Code: Select all
mode=GetErrorMode();
SetErrorMode(mode | SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);