home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1995 November / PCWK1195.iso / inne / podstawy / os2 / nakladki / pc2v190.exe / SOURCE.ZIP / Source / Error.c < prev    next >
Encoding:
Text File  |  1995-05-01  |  11.2 KB  |  193 lines

  1. /***********************************************************************\
  2.  *                               Error.h                               *
  3.  *        Copyright (C) by Stangl Roman, 1992, 1993, 1994, 1995        *
  4.  * This Code may be freely distributed, provided the Copyright isn't   *
  5.  * removed.                                                            *
  6.  *                                                                     *
  7.  * Requires: Error.c    The routing General_Error                      *
  8.  *           Error.h    The include-file that defines the macros       *
  9.  *                      GEN_ERR, DOS_ERR, USR_ERR                      *
  10.  *                                                                     *
  11.  * Error is a general errorhandler for OS/2 2.0 PM programmer to easy  *
  12.  * program development. The routine PM_Error displays:                 *
  13.  *      ErrMsg          The message that hints the error reason        *
  14.  *      ErrModule       The module containing the error                *
  15.  *      ErrLine         The sourcecode line, that contains the error   *
  16.  *      Error           The error returned by an OS/2 API              *
  17.  * The routine requires the following parameters passed:               *
  18.  *      HAB hab         The anchor block handle                        *
  19.  *      HWND hwndOwner  The owner windowhandle of the message box      *
  20.  *      ULONG ulWindow  The message box window ID, which is the ID of  *
  21.  *                      an entry in the online help                    *
  22.  *      ULONG ulStyle   The message box style                          *
  23.  *      UCHAR *pucMsg   An optional message that describes where the   *
  24.  *                      error occured                                  *
  25.  *      PSZ ErrModule   The pointer to the name of the module _FILE_   *
  26.  *      LONG ErrLine    The pointer to the sourcecodeline __LINE__     *
  27.  *                                                                     *
  28.  * This routine displays a message box, with the style specified in    *
  29.  * ulStyle. The message box automatically returns the pushbutton       *
  30.  * selected by the user. OS/2 APIs get called to determine the reason  *
  31.  * of the OS/2 (probably) internal error.                              *
  32.  *                                                                     *
  33.  * The routine Dos_Error displays:                                     *
  34.  *      ErrMsg          The message that hints the error reason        *
  35.  *      ErrModule       The module containing the error                *
  36.  *      ErrLine         The sourcecode line, that contains the error   *
  37.  *      Error           The error returned by an OS/2 API              *
  38.  * The routine requires the following parameters passed:               *
  39.  *      ULONG ulRc      The returncode of an OS/2 API                  *
  40.  *      HWND hwndOwner  The owner windowhandle of the message box      *
  41.  *      ULONG ulWindow  The message box window ID, which is the ID of  *
  42.  *                      an entry in the online help                    *
  43.  *      ULONG ulStyle   The message box style                          *
  44.  *      UCHAR *pucMsg   An optional message that describes where the   *
  45.  *                      error occured                                  *
  46.  *      PSZ ErrModule   The pointer to the name of the module _FILE_   *
  47.  *      LONG ErrLine    The pointer to the sourcecodeline __LINE__     *
  48.  *                                                                     *
  49.  * This routine displays a message box, with the style specified in    *
  50.  * ulStyle. The message box automatically returns the pushbutton       *
  51.  * selected by the user. The return code of an OS/2 API is displayed.  *
  52.  *                                                                     *
  53.  * The routine User_Error displays:                                    *
  54.  *      ErrMsg          The message that hints the error reason        *
  55.  *      ErrModule       The module containing the error                *
  56.  *      ErrLine         The sourcecode line, that contains the error   *
  57.  *      Error           The error indicated by the user                *
  58.  * The routine requires the following parameters passed:               *
  59.  *      HWND hwndOwner  The owner windowhandle of the message box      *
  60.  *      ULONG ulWindow  The message box window ID, which is the ID of  *
  61.  *                      an entry in the online help                    *
  62.  *      ULONG ulStyle   The message box style                          *
  63.  *      UCHAR *pucMsg   An optional message that describes where the   *
  64.  *                      error occured                                  *
  65.  *      PSZ ErrModule   The pointer to the name of the module _FILE_   *
  66.  *      LONG ErrLine    The pointer to the sourcecodeline __LINE__     *
  67.  *                                                                     *
  68.  * This routine displays a message box, with the style specified in    *
  69.  * ulStyle. The message box automatically returns the pushbutton       *
  70.  * selected by the user. This function is most useful for user inter-  *
  71.  * action, because no anchor block, but a message, is specified.       *
  72.  *                                                                     *
  73. \***********************************************************************/
  74.  
  75. static char RCSID[]="@(#) $Header: Error.c/Error.h Version 1.90 05,1995 $ (LBL)";
  76.  
  77. #include        "Pc2.h"                 /* User include files */
  78. #include        "error.h"
  79.  
  80. static unsigned char    ErrBuffer[512]; /* The whole error message that is displayed to
  81.                                            the user via WinMessageBox */
  82.  
  83. ULONG   PM_Error(HAB hab, HWND hwndOwner, ULONG ulWindow, ULONG ulStyle, UCHAR *pucMsg, PSZ ErrModule, LONG ErrLine)
  84. {
  85. PERRINFO    pErrInfoBlk;                /* Pointer to ERRINFO structure that is filled
  86.                                            by WinGetErrorInfo */
  87. PSZ         pszOffset;                  /* Pointer to the current error message returned
  88.                                            by WinGetErrorInfo */
  89. USHORT      usResponse;                 /* Message box return value */
  90.  
  91. if(!pucMsg) pucMsg="";                  /* If no special test is given, assume empty string */
  92. sprintf(ErrBuffer, "%s\n\nModule: %s\nLinenumber: %d\nError reported by PM: ",
  93.     pucMsg, ErrModule, ErrLine);
  94.                                         /* Get last error for the current thread. We loop
  95.                                            until no more error is found, although errors
  96.                                            arn't stacked (but things may change) */
  97. pErrInfoBlk=WinGetErrorInfo(hab);
  98.                                         /* Do as long as there is an errorinfo available */
  99. while(pErrInfoBlk!=(PERRINFO)NULL)
  100.     {
  101.     DosBeep(1000,100);                  /* Signal to user via speaker */
  102.     DosBeep(300,100);
  103.     DosBeep(1000,200);
  104.                                         /* Find offset in array of message offsets */
  105.     pszOffset = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
  106.                                         /* Address error message in array of messages and 
  107.                                            append error message to source code linenumber */
  108.     strcat(ErrBuffer,(((PSZ)pErrInfoBlk) + *((PSHORT)pszOffset)));
  109.     WinFreeErrorInfo(pErrInfoBlk);      /* Free resource segment */
  110.     pErrInfoBlk=WinGetErrorInfo(hab);
  111.     }
  112. usResponse=WinMessageBox(
  113.     HWND_DESKTOP,                       /* Parent window is DESKTOP */
  114.     hwndOwner,                          /* Owner window */
  115.     (PSZ)ErrBuffer,                     /* General_Error message */
  116.                                         /* Title bar message */
  117.     "PC/2: PM Error Message Information",
  118.     (USHORT)ulWindow,                   /* Message box identifiert for help */
  119.     (USHORT)ulStyle);                   /* Message box style */
  120. return(usResponse);
  121. }
  122.  
  123. ULONG   Dos_Error(ULONG ulRc, HWND hwndOwner, ULONG ulWindow, ULONG ulStyle, UCHAR *pucMsg, PSZ ErrModule, LONG ErrLine)
  124. {
  125. ULONG       ulClass;                    /* Error class */
  126. ULONG       ulAction;                   /* Error action */
  127. ULONG       ulLocus;                    /* Error location */
  128. USHORT      usResponse;                 /* Message box return value */
  129.  
  130. unsigned char   *Err_Class[]={"Out of ressource",
  131.                               "Temporary situation",
  132.                               "Authorization failed",
  133.                               "Internal error",
  134.                               "Device hardware failure",
  135.                               "System failure",
  136.                               "Probable application failure",
  137.                               "Item not located",
  138.                               "Bad format for call/data",
  139.                               "Resource or data locked",
  140.                               "Incorrect media, CRC check",
  141.                               "Action already taken or done",
  142.                               "Unclassified",
  143.                               "Cannot perform requested action",
  144.                               "Timeout",
  145.                               "Error in file \"Error.c\""};
  146. unsigned char   *Err_Action[]={"Retry immediately",
  147.                                "Delay and retry",
  148.                                "Bad user input - get new values",
  149.                                "Terminate in an orderly manner",
  150.                                "Terminate immediately",
  151.                                "Ignore error",
  152.                                "Retry after user intervention",
  153.                                "Error in file \"Error.c\""};
  154. unsigned char   *Err_Locus[]={"Unknown",
  155.                               "Random access device such as a disk",
  156.                               "Network",
  157.                               "Serial device",
  158.                               "Memory",
  159.                               "Error in file \"Error.c\""};
  160.  
  161. if(ulRc)
  162.     {
  163.     DosBeep(1000,100);                  /* Signal to user via speaker */
  164.     DosBeep(300,100);
  165.     DosBeep(1000,100);
  166.     if(!pucMsg) pucMsg="";              /* If no special test is given, assume empty string */
  167.     DosErrClass(ulRc, &ulClass, &ulAction, &ulLocus);
  168.     sprintf(ErrBuffer, "%s\n\nModule: %s\nLinenumber: %d\nError reported by OS/2: "\
  169.         "%d\nClass: %s\nAction: %s\nLocation: %s\n", 
  170.         pucMsg, ErrModule, ErrLine, ulRc, Err_Class[ulClass-1], Err_Action[ulAction-1], Err_Locus[ulLocus-1]);
  171.     usResponse=WinMessageBox(HWND_DESKTOP, hwndOwner, (PSZ)ErrBuffer,
  172.         "PC/2: OS/2 Error Message Information", (USHORT)ulWindow, (USHORT)ulStyle);
  173.     return(usResponse);
  174.     }
  175. else
  176.     return(MBID_IGNORE);
  177. }
  178.  
  179. ULONG   User_Error(HWND hwndOwner, ULONG ulWindow, ULONG ulStyle, UCHAR *pucMsg, PSZ ErrModule, LONG ErrLine)
  180. {
  181. USHORT      usResponse;                 /* Message box return value */
  182.  
  183. DosBeep(1000,100);                      /* Signal to user via speaker */
  184. DosBeep(300,100);
  185. DosBeep(1000,100);
  186. if(!pucMsg) pucMsg="Debug Information"; /* If no special test is given, assume debugging */
  187. sprintf(ErrBuffer, "%s\n\nModule: %s\nLinenumber: %d\n",
  188.     pucMsg, ErrModule, ErrLine);
  189. usResponse=WinMessageBox(HWND_DESKTOP, hwndOwner, (PSZ)ErrBuffer,
  190.     "PC/2: User Information", (USHORT)ulWindow, (USHORT)ulStyle);
  191. return(usResponse);
  192. }
  193.