The Independent JPEG Group's JPEG software v6b
diff --git a/jerror.c b/jerror.c
index 8b89e39..3da7be8 100644
--- a/jerror.c
+++ b/jerror.c
@@ -1,7 +1,7 @@
/*
* jerror.c
*
- * Copyright (C) 1991-1996, Thomas G. Lane.
+ * Copyright (C) 1991-1998, Thomas G. Lane.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
@@ -10,6 +10,11 @@
* stderr is the right thing to do. Many applications will want to replace
* some or all of these routines.
*
+ * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile,
+ * you get a Windows-specific hack to display error messages in a dialog box.
+ * It ain't much, but it beats dropping error messages into the bit bucket,
+ * which is what happens to output to stderr under most Windows C compilers.
+ *
* These routines are used by both the compression and decompression code.
*/
@@ -19,6 +24,10 @@
#include "jversion.h"
#include "jerror.h"
+#ifdef USE_WINDOWS_MESSAGEBOX
+#include <windows.h>
+#endif
+
#ifndef EXIT_FAILURE /* define exit() codes if not provided */
#define EXIT_FAILURE 1
#endif
@@ -74,6 +83,15 @@
* Actual output of an error or trace message.
* Applications may override this method to send JPEG messages somewhere
* other than stderr.
+ *
+ * On Windows, printing to stderr is generally completely useless,
+ * so we provide optional code to produce an error-dialog popup.
+ * Most Windows applications will still prefer to override this routine,
+ * but if they don't, it'll do something at least marginally useful.
+ *
+ * NOTE: to use the library in an environment that doesn't support the
+ * C stdio library, you may have to delete the call to fprintf() entirely,
+ * not just not use this routine.
*/
METHODDEF(void)
@@ -84,8 +102,14 @@
/* Create the message */
(*cinfo->err->format_message) (cinfo, buffer);
+#ifdef USE_WINDOWS_MESSAGEBOX
+ /* Display it in a message dialog box */
+ MessageBox(GetActiveWindow(), buffer, "JPEG Library Error",
+ MB_OK | MB_ICONERROR);
+#else
/* Send it to stderr, adding a newline */
fprintf(stderr, "%s\n", buffer);
+#endif
}