home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / sdktools / image / winnt / pfmon / error.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  2KB  |  96 lines

  1. /*++
  2.  
  3. Copyright (c) 1995-1997  Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     error.c
  8.  
  9. Abstract:
  10.  
  11.     Error handle module for the pfmon program
  12.  
  13. Author:
  14.  
  15.     Mark Lucovsky (markl) 26-Jan-1995
  16.  
  17. Revision History:
  18.  
  19. --*/
  20.  
  21. #include "pfmonp.h"
  22.  
  23. VOID
  24. CDECL
  25. DeclareError(
  26.     UINT ErrorCode,
  27.     UINT SupplementalErrorCode,
  28.     ...
  29.     )
  30. {
  31.     va_list arglist;
  32.     HMODULE ModuleHandle;
  33.     DWORD Flags, Size;
  34.     UCHAR MessageBuffer[ 512 ];
  35.  
  36.     va_start( arglist, SupplementalErrorCode );
  37.  
  38.     if ((ErrorCode & 0x0FFF0000) >> 16 == FACILITY_APPLICATION) {
  39.         ModuleHandle = PfmonModuleHandle;
  40.         Flags = FORMAT_MESSAGE_FROM_HMODULE;
  41.         }
  42.     else {
  43.         ModuleHandle = NULL;
  44.         Flags = FORMAT_MESSAGE_FROM_SYSTEM;
  45.         }
  46.  
  47.     Size = FormatMessage( Flags,
  48.                           (LPCVOID)ModuleHandle,
  49.                           ErrorCode,
  50.                           0,
  51.                           MessageBuffer,
  52.                           sizeof( MessageBuffer ),
  53.                           &arglist
  54.                         );
  55.     va_end( arglist );
  56.  
  57.     if (Size != 0) {
  58.         fprintf( stderr, "PFMON: %s", MessageBuffer );
  59.         }
  60.     else {
  61.         fprintf( stderr, "PFMON: Unable to get message text for %08x\n", ErrorCode );
  62.         }
  63.  
  64.     if (ModuleHandle == PfmonModuleHandle &&
  65.         SupplementalErrorCode != 0 &&
  66.         SupplementalErrorCode != ERROR_GEN_FAILURE
  67.        ) {
  68.  
  69.         ModuleHandle = NULL;
  70.         Flags = FORMAT_MESSAGE_FROM_SYSTEM;
  71.         Size = FormatMessage( Flags,
  72.                               (LPCVOID)ModuleHandle,
  73.                               SupplementalErrorCode,
  74.                               0,
  75.                               MessageBuffer,
  76.                               sizeof( MessageBuffer ),
  77.                               NULL
  78.                             );
  79.         if (Size != 0) {
  80.             while (Size != 0 && MessageBuffer[ Size ] <= ' ') {
  81.                 MessageBuffer[ Size ] = '\0';
  82.                 Size -= 1;
  83.                 }
  84.  
  85.             printf( "          '%s'\n", MessageBuffer );
  86.             }
  87.         else {
  88.             printf( "PFMON: Unable to get message text for %08x\n", SupplementalErrorCode );
  89.             }
  90.         }
  91.  
  92.  
  93.  
  94.     return;
  95. }
  96.