| [121] | 1 | 
 | 
|---|
 | 2 | /***********************************************************************
 | 
|---|
 | 3 | 
 | 
|---|
 | 4 |   $Id: errutil.c 907 2008-01-06 07:26:17Z stevenhl $
 | 
|---|
 | 5 | 
 | 
|---|
 | 6 |   Error reporting
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
| [907] | 9 |   Copyright (c) 2004, 2008 Steven H. Levine
 | 
|---|
| [121] | 10 | 
 | 
|---|
| [137] | 11 |   12 Aug 04 SHL Comments
 | 
|---|
 | 12 |   23 May 05 SHL Move saymsg here
 | 
|---|
| [144] | 13 |   24 May 05 SHL Rename General_Error to more accurate Win_Error
 | 
|---|
 | 14 |   24 May 05 SHL Rename saymsg to more accurate Misc_Error
 | 
|---|
 | 15 |   24 May 05 SHL Rework Win_Error args and clean up logic
 | 
|---|
| [182] | 16 |   27 May 05 SHL Rework to use common showMsg
 | 
|---|
| [258] | 17 |   14 Aug 05 SHL showMsg: suppress write to stdout if not error message
 | 
|---|
| [327] | 18 |   13 Jul 06 SHL Add Runtime_Error
 | 
|---|
 | 19 |   22 Jul 06 SHL Optimize calling sequences
 | 
|---|
| [383] | 20 |   26 Jul 06 SHL Add ..._Error2
 | 
|---|
| [452] | 21 |   16 Aug 06 SHL Tweak message formatting
 | 
|---|
| [552] | 22 |   07 Jan 07 GKY Move error strings etc. to string file
 | 
|---|
| [613] | 23 |   18 Apr 07 SHL showMsg: correct selective logging checks
 | 
|---|
| [616] | 24 |   19 Apr 07 SHL Add DbgMsg
 | 
|---|
 | 25 |   20 Apr 07 SHL Correct IDS_GENERR1TEXT formatting
 | 
|---|
| [636] | 26 |   23 Apr 07 SHL Add Win_Error_NoMsgBox.  Rework others
 | 
|---|
| [787] | 27 |   14 Aug 07 SHL Add GetMSecTimer
 | 
|---|
 | 28 |   14 Aug 07 SHL Use GetMSecTimer in DbgMsg
 | 
|---|
| [907] | 29 |   05 Jan 08 SHL Renamed from error.c to match errutil.h
 | 
|---|
| [121] | 30 | 
 | 
|---|
 | 31 | ***********************************************************************/
 | 
|---|
 | 32 | 
 | 
|---|
| [907] | 33 | #include <stdio.h>
 | 
|---|
 | 34 | #include <string.h>
 | 
|---|
 | 35 | #include <stdarg.h>
 | 
|---|
 | 36 | 
 | 
|---|
| [2] | 37 | #define INCL_DOS
 | 
|---|
 | 38 | #define INCL_DOSERRORS
 | 
|---|
 | 39 | #define INCL_WIN
 | 
|---|
 | 40 | 
 | 
|---|
| [907] | 41 | #include "errutil.h"
 | 
|---|
 | 42 | #include "strutil.h"                    // GetPString
 | 
|---|
| [2] | 43 | #include "fm3str.h"
 | 
|---|
 | 44 | 
 | 
|---|
| [907] | 45 | #pragma data_seg(GLOBAL2)
 | 
|---|
 | 46 | PSZ DEBUG_STRING;
 | 
|---|
 | 47 | 
 | 
|---|
| [2] | 48 | #pragma data_seg(DATA1)
 | 
|---|
 | 49 | 
 | 
|---|
| [787] | 50 | static PSZ pszSrcFile = __FILE__;
 | 
|---|
 | 51 | 
 | 
|---|
| [636] | 52 | static VOID formatWinError(PSZ pszBuf, UINT cBufBytes, HWND hwndErr, HWND hwndOwner,
 | 
|---|
 | 53 |                            PCSZ pszSrcFile, UINT uSrcLineNo,
 | 
|---|
 | 54 |                            PCSZ pszFmt, va_list pva);
 | 
|---|
 | 55 | 
 | 
|---|
| [613] | 56 | static APIRET showMsg(ULONG mb_type, HWND hwnd, PCSZ pszTitle, PCSZ pszMsg, BOOL wantLog);
 | 
|---|
| [2] | 57 | 
 | 
|---|
| [636] | 58 | //=== DbgMsg: output debug message stderr ===
 | 
|---|
| [144] | 59 | 
 | 
|---|
| [636] | 60 | VOID DbgMsg(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...)
 | 
|---|
| [121] | 61 | {
 | 
|---|
| [144] | 62 |   va_list va;
 | 
|---|
| [2] | 63 | 
 | 
|---|
| [787] | 64 | #if 1 // fixme to be selectable
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 |   static ULONG ul1stMSec;
 | 
|---|
 | 67 |   // static ULONG ulLastMSec;
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 |   ULONG msec = GetMSecTimer();
 | 
|---|
 | 70 |   ULONG delta;
 | 
|---|
 | 71 | 
 | 
|---|
 | 72 |   if (!ul1stMSec) {
 | 
|---|
 | 73 |     ul1stMSec = msec;
 | 
|---|
 | 74 |     // ulLastMSec = msec;                       // Avoid big delta 1st time
 | 
|---|
 | 75 |   }
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 |   delta = msec - ul1stMSec;
 | 
|---|
 | 78 |   // ulLastMSec = msec;
 | 
|---|
 | 79 |   fprintf(stderr, "%03lu.%03lu ", delta / 1000, delta % 1000);
 | 
|---|
 | 80 | 
 | 
|---|
 | 81 | #endif
 | 
|---|
 | 82 | 
 | 
|---|
| [636] | 83 |   // OK for source file name to be null
 | 
|---|
 | 84 |   fprintf(stderr, "%s %u", pszSrcFile ? pszSrcFile : "n/a", uSrcLineNo);
 | 
|---|
 | 85 |   // If format null want just file and line
 | 
|---|
 | 86 |   if (pszFmt) {
 | 
|---|
 | 87 |     fputc(' ', stderr);
 | 
|---|
 | 88 |     va_start(va, pszFmt);
 | 
|---|
 | 89 |     vfprintf(stderr, pszFmt, va);
 | 
|---|
 | 90 |     va_end(va);
 | 
|---|
| [613] | 91 |   }
 | 
|---|
| [636] | 92 |   fputc('\n', stderr);
 | 
|---|
 | 93 |   fflush(stderr);
 | 
|---|
| [613] | 94 | 
 | 
|---|
| [636] | 95 | } // DbgMsg
 | 
|---|
| [327] | 96 | 
 | 
|---|
| [452] | 97 | //== Dos_Error: report Dos...() error using passed message string ===
 | 
|---|
| [144] | 98 | 
 | 
|---|
| [636] | 99 | INT Dos_Error(ULONG mb_type, ULONG ulRC, HWND hwndOwner,
 | 
|---|
 | 100 |               PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...)
 | 
|---|
| [121] | 101 | {
 | 
|---|
| [182] | 102 |   CHAR szMsg[4096];
 | 
|---|
| [636] | 103 |   ULONG Class;                          // Error class
 | 
|---|
 | 104 |   ULONG action;                         // Error action
 | 
|---|
 | 105 |   ULONG Locus;                          // Error location
 | 
|---|
| [144] | 106 |   ULONG ulMsgLen;
 | 
|---|
 | 107 |   CHAR *pszMsgStart;
 | 
|---|
 | 108 |   CHAR *psz;
 | 
|---|
 | 109 |   va_list va;
 | 
|---|
| [2] | 110 | 
 | 
|---|
| [144] | 111 |   if (!ulRC)
 | 
|---|
 | 112 |     return MBID_ENTER;                  // Should not have been called
 | 
|---|
| [121] | 113 | 
 | 
|---|
| [144] | 114 |   // Format caller's message
 | 
|---|
 | 115 |   va_start(va, pszFmt);
 | 
|---|
| [613] | 116 |   szMsg[sizeof(szMsg) - 1] = 0;
 | 
|---|
| [182] | 117 |   vsprintf(szMsg, pszFmt, va);
 | 
|---|
| [144] | 118 |   va_end(va);
 | 
|---|
| [121] | 119 | 
 | 
|---|
| [613] | 120 |   if (szMsg[sizeof(szMsg) - 1]) {
 | 
|---|
 | 121 |     fprintf(stderr, "Buffer overflow in Dos_Error - need %u bytes\n", strlen(szMsg) + 1);
 | 
|---|
 | 122 |     fflush(stderr);
 | 
|---|
 | 123 |   }
 | 
|---|
 | 124 | 
 | 
|---|
| [327] | 125 |   if (strchr(szMsg, ' ') == NULL)
 | 
|---|
| [636] | 126 |     strcat(szMsg, " failed");           // Assume simple function name
 | 
|---|
| [327] | 127 | 
 | 
|---|
| [144] | 128 |   DosErrClass(ulRC, &Class, &action, &Locus);
 | 
|---|
 | 129 | 
 | 
|---|
| [182] | 130 |   sprintf(szMsg + strlen(szMsg),
 | 
|---|
| [144] | 131 |           GetPString(IDS_DOSERR1TEXT),
 | 
|---|
| [636] | 132 |           pszSrcFile,
 | 
|---|
 | 133 |           uSrcLineNo,
 | 
|---|
| [144] | 134 |           ulRC,
 | 
|---|
 | 135 |           GetPString(IDS_ERRCLASS1TEXT + (Class - 1)),
 | 
|---|
 | 136 |           GetPString(IDS_ERRACTION1TEXT + (action - 1)),
 | 
|---|
 | 137 |           GetPString(IDS_ERRLOCUS1TEXT + (Locus - 1)));
 | 
|---|
| [182] | 138 |   pszMsgStart = szMsg + strlen(szMsg) + 1;
 | 
|---|
| [144] | 139 |   // Get message leaving space for NL separator
 | 
|---|
| [551] | 140 |   if (!DosGetMessage
 | 
|---|
 | 141 |       (NULL, 0L, (PCHAR) pszMsgStart + 1, 1024, ulRC, "OSO001.MSG", &ulMsgLen)
 | 
|---|
 | 142 |       || !DosGetMessage(NULL, 0L, (PCHAR) pszMsgStart + 1, 1024, ulRC,
 | 
|---|
 | 143 |                         "OSO001H.MSG", &ulMsgLen)) {
 | 
|---|
| [144] | 144 |     // Got message
 | 
|---|
 | 145 |     pszMsgStart[ulMsgLen + 1] = 0;      // Terminate
 | 
|---|
| [182] | 146 |     *(pszMsgStart - 1) = '\n';          // Stuff NL before message text
 | 
|---|
| [144] | 147 |     *pszMsgStart = '\"';                // Prefix message text with quote
 | 
|---|
| [182] | 148 | 
 | 
|---|
| [144] | 149 |     psz = pszMsgStart + ulMsgLen;       // Point at last char
 | 
|---|
 | 150 |     // Chop trailing NL CR TAB
 | 
|---|
 | 151 |     while (*psz &&
 | 
|---|
| [551] | 152 |            (*psz == '\r' || *psz == '\n' || *psz == ' ' || *psz == '\t')) {
 | 
|---|
| [144] | 153 |       *psz-- = 0;
 | 
|---|
 | 154 |     }
 | 
|---|
 | 155 |     strcat(psz, "\"");                  // Append trailing quote
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 |     // Convert CR and NL combos to single space
 | 
|---|
 | 158 |     psz = pszMsgStart;
 | 
|---|
| [551] | 159 |     while (*psz) {
 | 
|---|
 | 160 |       if (*psz == '\n' || *psz == '\r') {
 | 
|---|
| [144] | 161 |         while (*(psz + 1) == '\n' || *(psz + 1) == '\r')
 | 
|---|
 | 162 |           memmove(psz, psz + 1, strlen(psz));
 | 
|---|
 | 163 |         *psz = ' ';
 | 
|---|
| [2] | 164 |       }
 | 
|---|
| [144] | 165 |       else
 | 
|---|
 | 166 |         psz++;
 | 
|---|
| [2] | 167 |     }
 | 
|---|
 | 168 |   }
 | 
|---|
| [137] | 169 | 
 | 
|---|
| [613] | 170 |   return showMsg(mb_type | MB_ICONEXCLAMATION, hwndOwner, GetPString(IDS_DOSERR2TEXT),
 | 
|---|
 | 171 |                  szMsg, TRUE);
 | 
|---|
| [137] | 172 | 
 | 
|---|
| [636] | 173 | } // Dos_Error
 | 
|---|
| [137] | 174 | 
 | 
|---|
| [452] | 175 | //== Dos_Error2: report Dos...() error using passed message id ===
 | 
|---|
| [383] | 176 | 
 | 
|---|
| [636] | 177 | INT Dos_Error2(ULONG mb_type, ULONG ulRC, HWND hwndOwner,
 | 
|---|
 | 178 |                PCSZ pszSrcFile, UINT uSrcLineNo, UINT idMsg)
 | 
|---|
| [383] | 179 | {
 | 
|---|
| [636] | 180 |   return Dos_Error(mb_type, ulRC, hwndOwner, pszSrcFile, uSrcLineNo,
 | 
|---|
| [551] | 181 |                    GetPString(idMsg));
 | 
|---|
| [636] | 182 | } // Dos_Error2
 | 
|---|
| [383] | 183 | 
 | 
|---|
| [636] | 184 | /**
 | 
|---|
 | 185 |  * Format last PM error into passed buffer
 | 
|---|
 | 186 |  */
 | 
|---|
 | 187 | 
 | 
|---|
 | 188 | static VOID formatWinError(PSZ pszBuf, UINT cBufBytes,
 | 
|---|
 | 189 |                            HWND hwndErr, HWND hwndOwner,
 | 
|---|
 | 190 |                            PCSZ pszSrcFile, UINT uSrcLineNo,
 | 
|---|
 | 191 |                            PCSZ pszFmt, va_list pva)
 | 
|---|
 | 192 | {
 | 
|---|
 | 193 |   PERRINFO pErrInfoBlk;         /* Pointer to ERRINFO structure filled
 | 
|---|
 | 194 |                                    by WinGetErrorInfo */
 | 
|---|
 | 195 |   PSZ pszOffset;                /* Pointer to current error message returned
 | 
|---|
 | 196 |                                    by WinGetErrorInfo */
 | 
|---|
 | 197 |   PSZ psz;
 | 
|---|
 | 198 |   HAB hab;
 | 
|---|
 | 199 | 
 | 
|---|
 | 200 |   if (hwndErr == NULLHANDLE)
 | 
|---|
 | 201 |     hab = (HAB)0;
 | 
|---|
 | 202 |   else
 | 
|---|
 | 203 |     hab = WinQueryAnchorBlock(hwndErr);
 | 
|---|
 | 204 | 
 | 
|---|
 | 205 |   // Format callers message
 | 
|---|
 | 206 |   pszBuf[cBufBytes - 1] = 0;
 | 
|---|
 | 207 |   vsprintf(pszBuf, pszFmt, pva);
 | 
|---|
 | 208 | 
 | 
|---|
 | 209 |   if (pszBuf[cBufBytes - 1]) {
 | 
|---|
 | 210 |     fprintf(stderr, "Buffer overflow in formatWinError - need %u bytes\n", strlen(pszBuf) + 1);
 | 
|---|
 | 211 |     fflush(stderr);
 | 
|---|
 | 212 |   }
 | 
|---|
 | 213 | 
 | 
|---|
 | 214 |   if (strchr(pszBuf, ' ') == NULL)
 | 
|---|
 | 215 |     strcat(pszBuf, " failed");          // Assume simple function name
 | 
|---|
 | 216 | 
 | 
|---|
 | 217 |   // Append file name and line number and trailing space
 | 
|---|
 | 218 |   sprintf(pszBuf + strlen(pszBuf),
 | 
|---|
 | 219 |           GetPString(IDS_GENERR1TEXT), pszSrcFile, uSrcLineNo);
 | 
|---|
 | 220 | 
 | 
|---|
 | 221 |   // Get last PM error for the current thread
 | 
|---|
 | 222 |   pErrInfoBlk = WinGetErrorInfo(hab);
 | 
|---|
 | 223 |   if (!pErrInfoBlk) {
 | 
|---|
| [907] | 224 |     ERRORID id = WinGetLastError(hab);
 | 
|---|
| [636] | 225 |     psz = pszBuf + strlen(pszBuf);
 | 
|---|
| [904] | 226 |     sprintf(psz, " WinGetErrorInfo failed (%u)", id);
 | 
|---|
| [636] | 227 |   }
 | 
|---|
 | 228 |   else {
 | 
|---|
 | 229 |     if (!hwndOwner)
 | 
|---|
 | 230 |       hwndOwner = HWND_DESKTOP;
 | 
|---|
 | 231 |     /* Find message offset in array of message offsets
 | 
|---|
 | 232 |        Assume 1 message - fixme?
 | 
|---|
 | 233 |      */
 | 
|---|
 | 234 |     pszOffset = ((PSZ) pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
 | 
|---|
 | 235 |     /* Address error message in array of messages and
 | 
|---|
 | 236 |        append error message to source code linenumber
 | 
|---|
 | 237 |      */
 | 
|---|
 | 238 |     psz = pszBuf + strlen(pszBuf);
 | 
|---|
| [904] | 239 |     sprintf(psz, " #0x%04x \"", ERRORIDERROR(pErrInfoBlk->idError));
 | 
|---|
| [636] | 240 |     psz += strlen(psz);
 | 
|---|
 | 241 |     strcpy(psz, ((PSZ) pErrInfoBlk) + *(PSHORT) pszOffset);
 | 
|---|
 | 242 |     psz += strlen(psz);
 | 
|---|
 | 243 |     // Chop trailing mush
 | 
|---|
 | 244 |     psz--;
 | 
|---|
 | 245 |     while (*psz == '\r' || *psz == '\n' || *psz == ' ')
 | 
|---|
 | 246 |       *psz-- = 0;
 | 
|---|
 | 247 |     if (*psz)
 | 
|---|
 | 248 |       psz++;
 | 
|---|
 | 249 |     strcpy(psz, "\"");
 | 
|---|
 | 250 |     WinFreeErrorInfo(pErrInfoBlk);      // Free resource segment
 | 
|---|
 | 251 |   }
 | 
|---|
 | 252 | 
 | 
|---|
 | 253 | } // formatWinError
 | 
|---|
 | 254 | 
 | 
|---|
| [787] | 255 | /**
 | 
|---|
 | 256 |  * Return millisecond timer value
 | 
|---|
 | 257 |  * Resolution is milliseconds, but accuracy will be less
 | 
|---|
 | 258 |  * depending on systems settings
 | 
|---|
 | 259 |  */
 | 
|---|
 | 260 | 
 | 
|---|
 | 261 | ULONG GetMSecTimer(void)
 | 
|---|
 | 262 | {
 | 
|---|
 | 263 |   ULONG msec;
 | 
|---|
 | 264 | 
 | 
|---|
 | 265 |   APIRET rc = DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT,
 | 
|---|
 | 266 |                               &msec, sizeof(msec));
 | 
|---|
 | 267 |   if (rc) {
 | 
|---|
 | 268 |     Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
 | 
|---|
 | 269 |               "DosQuerySysInfo");
 | 
|---|
 | 270 |     msec = 0;
 | 
|---|
 | 271 |   }
 | 
|---|
 | 272 |   return msec;
 | 
|---|
 | 273 | }
 | 
|---|
 | 274 | 
 | 
|---|
| [452] | 275 | //== Runtime_Error: report runtime library error using passed message string ===
 | 
|---|
| [327] | 276 | 
 | 
|---|
| [551] | 277 | VOID Runtime_Error(PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...)
 | 
|---|
| [327] | 278 | {
 | 
|---|
 | 279 |   CHAR szMsg[4096];
 | 
|---|
 | 280 |   va_list va;
 | 
|---|
 | 281 | 
 | 
|---|
 | 282 |   // Format caller's message
 | 
|---|
 | 283 |   va_start(va, pszFmt);
 | 
|---|
| [613] | 284 |   szMsg[sizeof(szMsg) - 1] = 0;
 | 
|---|
| [327] | 285 |   vsprintf(szMsg, pszFmt, va);
 | 
|---|
 | 286 |   va_end(va);
 | 
|---|
 | 287 | 
 | 
|---|
| [613] | 288 |   if (szMsg[sizeof(szMsg) - 1]) {
 | 
|---|
 | 289 |     fprintf(stderr, "Buffer overflow in Runtime_Error - need %u bytes\n", strlen(szMsg) + 1);
 | 
|---|
 | 290 |     fflush(stderr);
 | 
|---|
 | 291 |   }
 | 
|---|
 | 292 | 
 | 
|---|
| [327] | 293 |   if (strchr(szMsg, ' ') == NULL)
 | 
|---|
| [636] | 294 |     strcat(szMsg, " failed");           // Assume simple function name
 | 
|---|
| [327] | 295 | 
 | 
|---|
 | 296 |   sprintf(szMsg + strlen(szMsg),
 | 
|---|
| [613] | 297 |           GetPString(IDS_GENERR1TEXT), pszSrcFile, uSrcLineNo);
 | 
|---|
| [327] | 298 | 
 | 
|---|
| [613] | 299 |   showMsg(MB_ICONEXCLAMATION, HWND_DESKTOP, DEBUG_STRING, szMsg, TRUE);
 | 
|---|
| [327] | 300 | 
 | 
|---|
| [636] | 301 | } // Runtime_Error
 | 
|---|
| [327] | 302 | 
 | 
|---|
| [452] | 303 | //== Runtime_Error2: report runtime library error using passed message id ===
 | 
|---|
 | 304 | 
 | 
|---|
| [383] | 305 | VOID Runtime_Error2(PCSZ pszSrcFile, UINT uSrcLineNo, UINT idMsg)
 | 
|---|
 | 306 | {
 | 
|---|
 | 307 |   Runtime_Error(pszSrcFile, uSrcLineNo, GetPString(idMsg));
 | 
|---|
 | 308 | 
 | 
|---|
| [636] | 309 | } // Runtime_Error2
 | 
|---|
| [383] | 310 | 
 | 
|---|
| [182] | 311 | // fixme to be rename to Misc_Error
 | 
|---|
| [144] | 312 | 
 | 
|---|
| [452] | 313 | //=== saymsg: report misc error using passed message ===
 | 
|---|
| [144] | 314 | 
 | 
|---|
| [551] | 315 | APIRET saymsg(ULONG mb_type, HWND hwnd, PCSZ pszTitle, PCSZ pszFmt, ...)
 | 
|---|
| [137] | 316 | {
 | 
|---|
| [182] | 317 |   CHAR szMsg[4096];
 | 
|---|
| [144] | 318 |   va_list va;
 | 
|---|
| [137] | 319 | 
 | 
|---|
| [144] | 320 |   va_start(va, pszFmt);
 | 
|---|
| [613] | 321 |   szMsg[sizeof(szMsg) - 1] = 0;
 | 
|---|
| [182] | 322 |   vsprintf(szMsg, pszFmt, va);
 | 
|---|
| [144] | 323 |   va_end(va);
 | 
|---|
 | 324 | 
 | 
|---|
| [613] | 325 |   if (szMsg[sizeof(szMsg) - 1]) {
 | 
|---|
 | 326 |     fprintf(stderr, "Buffer overflow in saymsg - need %u bytes\n", strlen(szMsg) + 1);
 | 
|---|
 | 327 |     fflush(stderr);
 | 
|---|
 | 328 |   }
 | 
|---|
| [452] | 329 | 
 | 
|---|
| [613] | 330 |   return showMsg(mb_type, hwnd, pszTitle, szMsg, FALSE);
 | 
|---|
 | 331 | 
 | 
|---|
| [636] | 332 | } // saymsg
 | 
|---|
| [182] | 333 | 
 | 
|---|
| [452] | 334 | //=== showMsg: display error popup ===
 | 
|---|
| [182] | 335 | 
 | 
|---|
| [636] | 336 | static APIRET showMsg(ULONG mb_type, HWND hwndOwner,
 | 
|---|
 | 337 |                       PCSZ pszTitle, PCSZ pszMsg, BOOL wantLog)
 | 
|---|
| [182] | 338 | {
 | 
|---|
| [613] | 339 |   if (wantLog) {
 | 
|---|
| [258] | 340 |     fputs(pszMsg, stderr);
 | 
|---|
 | 341 |     fputc('\n', stderr);
 | 
|---|
| [614] | 342 |     fputc('\n', stderr);
 | 
|---|
| [258] | 343 |     fflush(stderr);
 | 
|---|
 | 344 |   }
 | 
|---|
 | 345 | 
 | 
|---|
| [616] | 346 |   if (!hwndOwner)
 | 
|---|
 | 347 |     hwndOwner = HWND_DESKTOP;
 | 
|---|
| [144] | 348 | 
 | 
|---|
| [551] | 349 |   DosBeep(250, 100);
 | 
|---|
| [327] | 350 | 
 | 
|---|
| [182] | 351 |   return WinMessageBox(HWND_DESKTOP,    // Parent
 | 
|---|
| [616] | 352 |                        hwndOwner,
 | 
|---|
| [551] | 353 |                        (PSZ) pszMsg, (PSZ) pszTitle, 0, // help id
 | 
|---|
| [182] | 354 |                        mb_type | MB_MOVEABLE);
 | 
|---|
| [613] | 355 | } // showMsg
 | 
|---|
| [616] | 356 | 
 | 
|---|
| [636] | 357 | //== Win_Error: report Win...() error using passed message string ===
 | 
|---|
| [616] | 358 | 
 | 
|---|
| [636] | 359 | VOID Win_Error(HWND hwndErr, HWND hwndOwner,
 | 
|---|
 | 360 |                PCSZ pszSrcFile, UINT uSrcLineNo,
 | 
|---|
 | 361 |                PCSZ pszFmt, ...)
 | 
|---|
| [616] | 362 | {
 | 
|---|
| [636] | 363 |   CHAR szMsg[4096];
 | 
|---|
| [616] | 364 |   va_list va;
 | 
|---|
 | 365 | 
 | 
|---|
| [636] | 366 |   // Format callers message
 | 
|---|
 | 367 |   va_start(va, pszFmt);
 | 
|---|
 | 368 |   formatWinError(szMsg, sizeof(szMsg), hwndErr, hwndOwner, pszSrcFile, uSrcLineNo, pszFmt, va);
 | 
|---|
 | 369 |   va_end(va);
 | 
|---|
 | 370 | 
 | 
|---|
 | 371 |   showMsg(MB_ENTER | MB_ICONEXCLAMATION, hwndOwner, GetPString(IDS_GENERR2TEXT),
 | 
|---|
 | 372 |           szMsg, TRUE);
 | 
|---|
 | 373 | 
 | 
|---|
 | 374 | } // Win_Error
 | 
|---|
 | 375 | 
 | 
|---|
 | 376 | //== Win_Error2: report Win...() error using passed message id ===
 | 
|---|
 | 377 | 
 | 
|---|
 | 378 | VOID Win_Error2(HWND hwndErr, HWND hwndOwner,
 | 
|---|
 | 379 |                 PCSZ pszSrcFile, UINT uSrcLineNo, UINT idMsg)
 | 
|---|
 | 380 | {
 | 
|---|
 | 381 |   Win_Error(hwndErr, hwndOwner, pszSrcFile, uSrcLineNo, GetPString(idMsg));
 | 
|---|
 | 382 | 
 | 
|---|
 | 383 | } // Win_Error2
 | 
|---|
 | 384 | 
 | 
|---|
 | 385 | /**
 | 
|---|
 | 386 |   * Output PM error messsage to stderr
 | 
|---|
 | 387 |   * This does to same reporting as Win_Error, but bypasses the
 | 
|---|
 | 388 |   * message box popup.
 | 
|---|
 | 389 |   * Use this version when the popup would hang PM.
 | 
|---|
 | 390 |   */
 | 
|---|
 | 391 | 
 | 
|---|
 | 392 | VOID Win_Error_NoMsgBox(HWND hwndErr, HWND hwndOwner,
 | 
|---|
 | 393 |                         PCSZ pszSrcFile, UINT uSrcLineNo, PCSZ pszFmt, ...)
 | 
|---|
 | 394 | {
 | 
|---|
 | 395 |   CHAR szMsg[4096];
 | 
|---|
 | 396 |   va_list va;
 | 
|---|
 | 397 | 
 | 
|---|
 | 398 |   // Format callers message
 | 
|---|
 | 399 |   va_start(va, pszFmt);
 | 
|---|
 | 400 |   formatWinError(szMsg, sizeof(szMsg), hwndErr, hwndOwner, pszSrcFile, uSrcLineNo, pszFmt, va);
 | 
|---|
 | 401 |   va_end(va);
 | 
|---|
 | 402 | 
 | 
|---|
 | 403 |   fputs(szMsg, stderr);
 | 
|---|
| [616] | 404 |   fputc('\n', stderr);
 | 
|---|
| [636] | 405 |   fputc('\n', stderr);
 | 
|---|
| [616] | 406 |   fflush(stderr);
 | 
|---|
 | 407 | 
 | 
|---|
| [636] | 408 |   DosBeep(250, 100);
 | 
|---|
| [616] | 409 | 
 | 
|---|
| [636] | 410 | } // Win_Error_NoMsgBox
 | 
|---|
| [787] | 411 | 
 | 
|---|
 | 412 | #pragma alloc_text(ERROR,Win_Error,Dos_Error,saymsg,showMsg,GetHiresTimeer)
 | 
|---|