home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PRINTERR.ZIP / PRINTERR.C next >
Text File  |  1990-02-15  |  3KB  |  76 lines

  1.  
  2. #define  INCL_GPI
  3. #define  INCL_WIN
  4. #include <os2.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7.  
  8. #define     PRIVATE     0
  9. #define     STRSIZE     512
  10. #define     STR1OFFSET  0
  11. #define     STR2OFFSET  500
  12.  
  13. /**************************************************************
  14.  *  printerr:   uses the WinGetErrInfo API to retrieve
  15.  *              error info from the last error in an anchor
  16.  *              block.  Then displays the error message
  17.  *              contained in the error info as well as the
  18.  *              line number and file name of offending program.
  19.  *
  20.  **************************************************************/
  21. VOID far pascal _saveregs _loadds printerr ( PSZ pszFilename
  22.                                              , USHORT usLineNo, HAB hab )
  23. {
  24.     PERRINFO perr;                      // for WinGetErrorInfo
  25.     NPBYTE     npb;                     // temporary pointer
  26.     PBYTE      pb;                      // points to err message
  27.     SEL        sel;                     // we allocate memory for string
  28.     PSZ        pszStr1, pszStr2;        // temporary string pointers
  29.  
  30.   // allocate memory for our temporary strings
  31.  
  32.     if (DosAllocSeg ( STRSIZE, &sel, PRIVATE ) )
  33.     {
  34.         WinMessageBox (   HWND_DESKTOP
  35.                         , HWND_DESKTOP
  36.                         , "Unable to allocate in printerr"
  37.                         , "Error"
  38.                         , 0
  39.                         , MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE );
  40.         return;
  41.     }
  42.  
  43.   // We allocate 512 bytes and then use it as two strings:
  44.   //    pszStr1 -  first 500 bytes
  45.   //    pszStr2 -  last  12  bytes
  46.  
  47.     pszStr1 = MAKEP ( sel, STR1OFFSET   );
  48.     pszStr2 = MAKEP ( sel, STR2OFFSET );
  49.  
  50.   // retrieve a structure containing error info
  51.     perr = WinGetErrorInfo (hab);
  52.  
  53.   // point to the error message string in the structure
  54.     pb = MAKEP ( SELECTOROF(perr), perr->offaoffszMsg );
  55.     npb = (NPBYTE) *pb;
  56.     pb = MAKEP (SELECTOROF(perr), npb );
  57.  
  58.   // format the pszStr1 with a string containing line # and filename
  59.     strcpy ( pszStr1, "Error in line " );
  60.     itoa   ( usLineNo, pszStr2, 10 );
  61.     strcat ( pszStr1, pszStr2 );
  62.     strcat ( pszStr1, " of file " );
  63.     strcat ( pszStr1, pszFilename );
  64.  
  65.   // display the strings in a message box
  66.     WinMessageBox ( HWND_DESKTOP
  67.                     , HWND_DESKTOP
  68.                     , pb               // error message
  69.                     , pszStr1          // line # and filename
  70.                     , 0
  71.                     , MB_OK | MB_ICONEXCLAMATION | MB_MOVEABLE );
  72.  
  73.     WinFreeErrorInfo (hab);
  74.     DosFreeSeg ( sel );
  75. }
  76.