| 1 | #define INCL_DOS
|
|---|
| 2 | #define INCL_DOSERRORS
|
|---|
| 3 | #define INCL_WIN
|
|---|
| 4 |
|
|---|
| 5 | #include <os2.h>
|
|---|
| 6 | #include <stdlib.h>
|
|---|
| 7 | #include <stdio.h>
|
|---|
| 8 | #include <string.h>
|
|---|
| 9 | #include <stdarg.h>
|
|---|
| 10 | #include "fm3dll.h"
|
|---|
| 11 | #include "fm3str.h"
|
|---|
| 12 |
|
|---|
| 13 | #pragma data_seg(DATA1)
|
|---|
| 14 | #pragma alloc_text(FMINPUT,General_Error,Dos_Error)
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | VOID General_Error(HAB hab,HWND hwnd, PSZ ErrModule,LONG ErrLine,CHAR *s,...) {
|
|---|
| 18 |
|
|---|
| 19 | PERRINFO pErrInfoBlk; /* Pointer to ERRINFO structure that is filled
|
|---|
| 20 | by WinGetErrorInfo */
|
|---|
| 21 | PSZ pszOffset; /* Pointer to the current error message returned
|
|---|
| 22 | by WinGetErrorInfo */
|
|---|
| 23 | CHAR ErrBuffer[4096]; /* The whole error message that is displayed to
|
|---|
| 24 | the user via WinMessageBox */
|
|---|
| 25 | va_list ap;
|
|---|
| 26 |
|
|---|
| 27 | va_start(ap,s);
|
|---|
| 28 | vsprintf(ErrBuffer,s,ap);
|
|---|
| 29 | va_end(ap);
|
|---|
| 30 | sprintf(&ErrBuffer[strlen(ErrBuffer)],
|
|---|
| 31 | GetPString(IDS_GENERR1TEXT),
|
|---|
| 32 | ErrModule,
|
|---|
| 33 | ErrLine,
|
|---|
| 34 | " ");
|
|---|
| 35 | /* Get last error for the current thread. */
|
|---|
| 36 | pErrInfoBlk = WinGetErrorInfo(hab);
|
|---|
| 37 | if(pErrInfoBlk != (PERRINFO)NULL) {
|
|---|
| 38 | if(!hwnd)
|
|---|
| 39 | hwnd = HWND_DESKTOP;
|
|---|
| 40 | /* Find offset in array of message offsets */
|
|---|
| 41 | pszOffset = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
|
|---|
| 42 | /* Address error message in array of messages and
|
|---|
| 43 | append error message to source code linenumber */
|
|---|
| 44 | sprintf(&ErrBuffer[strlen(ErrBuffer)],"#0x%04x \"",
|
|---|
| 45 | ERRORIDERROR(pErrInfoBlk->idError));
|
|---|
| 46 | strcat(ErrBuffer,(((PSZ)pErrInfoBlk) + *((PSHORT)pszOffset)));
|
|---|
| 47 | strcat(ErrBuffer,"\"");
|
|---|
| 48 | WinFreeErrorInfo(pErrInfoBlk); /* Free resource segment */
|
|---|
| 49 | WinMessageBox(HWND_DESKTOP, /* Parent window is DESKTOP */
|
|---|
| 50 | hwnd, /* Owner window is DESKTOP */
|
|---|
| 51 | (PSZ)ErrBuffer, /* General_Error message */
|
|---|
| 52 | /* Title bar message */
|
|---|
| 53 | GetPString(IDS_GENERR2TEXT),
|
|---|
| 54 | 0, /* Message identifier */
|
|---|
| 55 | MB_ENTER | MB_ICONEXCLAMATION | MB_MOVEABLE);
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | INT Dos_Error(INT type,ULONG Error,HWND hwnd, PSZ ErrModule,
|
|---|
| 61 | LONG ErrLine,CHAR *s,...) {
|
|---|
| 62 |
|
|---|
| 63 | CHAR MsgBuffer[4096]; /* The whole error message that
|
|---|
| 64 | is displayed to
|
|---|
| 65 | the user via WinMessageBox */
|
|---|
| 66 | ULONG Class = 17; /* Error class */
|
|---|
| 67 | ULONG action = 9; /* Error action */
|
|---|
| 68 | ULONG Locus = 7; /* Error location */
|
|---|
| 69 | ULONG len;
|
|---|
| 70 | CHAR *p,*pp;
|
|---|
| 71 | va_list ap;
|
|---|
| 72 |
|
|---|
| 73 | if(Error != 0) {
|
|---|
| 74 | strset(MsgBuffer,0);
|
|---|
| 75 | if(!hwnd)
|
|---|
| 76 | hwnd = HWND_DESKTOP;
|
|---|
| 77 | va_start(ap,s);
|
|---|
| 78 | vsprintf(MsgBuffer,s,ap);
|
|---|
| 79 | va_end(ap);
|
|---|
| 80 | DosErrClass(Error,&Class,&action,&Locus);
|
|---|
| 81 | sprintf(&MsgBuffer[strlen(MsgBuffer)],
|
|---|
| 82 | GetPString(IDS_DOSERR1TEXT),
|
|---|
| 83 | ErrModule,
|
|---|
| 84 | ErrLine,
|
|---|
| 85 | Error,
|
|---|
| 86 | GetPString(IDS_ERRCLASS1TEXT + (Class - 1)),
|
|---|
| 87 | GetPString(IDS_ERRACTION1TEXT + (action - 1)),
|
|---|
| 88 | GetPString(IDS_ERRLOCUS1TEXT + (Locus - 1)));
|
|---|
| 89 | p = MsgBuffer + strlen(MsgBuffer) + 1;
|
|---|
| 90 | if(!DosGetMessage(NULL,0L,(PCHAR)p + 1,1024,Error,"OSO001.MSG",&len) ||
|
|---|
| 91 | !DosGetMessage(NULL,0L,(PCHAR)p + 1,1024,Error,"OSO001H.MSG",&len)) {
|
|---|
| 92 | p[len + 1] = 0;
|
|---|
| 93 | *(p - 1) = '\n';
|
|---|
| 94 | *p = '\"';
|
|---|
| 95 | pp = p + len;
|
|---|
| 96 | while(*pp && (*pp == '\r' || *pp == '\n' || *pp == ' ' || *pp == '\t')) {
|
|---|
| 97 | *pp = 0;
|
|---|
| 98 | pp--;
|
|---|
| 99 | }
|
|---|
| 100 | strcat(p,"\"");
|
|---|
| 101 | pp = p;
|
|---|
| 102 | while(*pp) {
|
|---|
| 103 | if(*pp == '\n' || *pp == '\r') {
|
|---|
| 104 | while(*(pp + 1) == '\n' || *(pp + 1) == '\r')
|
|---|
| 105 | memmove(pp,pp + 1,strlen(pp));
|
|---|
| 106 | *pp = ' ';
|
|---|
| 107 | }
|
|---|
| 108 | else
|
|---|
| 109 | pp++;
|
|---|
| 110 | }
|
|---|
| 111 | }
|
|---|
| 112 | return WinMessageBox(HWND_DESKTOP, /* Parent window is DESKTOP */
|
|---|
| 113 | hwnd, /* Owner window */
|
|---|
| 114 | (PSZ)MsgBuffer, /* DOS API error message */
|
|---|
| 115 | /* Title bar message */
|
|---|
| 116 | GetPString(IDS_DOSERR2TEXT),
|
|---|
| 117 | 0, /* Message identifier */
|
|---|
| 118 | type | MB_ICONEXCLAMATION | MB_MOVEABLE);
|
|---|
| 119 | }
|
|---|
| 120 | return MBID_ENTER;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|