home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / prtsampl.zip / PMASSERT.H next >
C/C++ Source or Header  |  1998-04-20  |  2KB  |  53 lines

  1. /****************************************************************************
  2. * OS/2 Sample Print Application PRTSAMP
  3. *
  4. * name: pmassert.h
  5. *
  6. * description: similar to C assert.h, but presents debugging information
  7. *   in a PM message box instead of standard error.
  8. *
  9. *   The pmassert macro works when the symbol NDEBUG is not defined to the
  10. *   compiler; thus, the macro works by default.
  11. *
  12. *   To build a non-debug version of the program, define the symbol NDEBUG
  13. *   with the proper compiler switch, usually /DNDEBUG
  14. *
  15. *   The message box shows the last error in hex. The high word is severity,
  16. *   and the low word is an error code. Refer to pmerr.h for an explanation
  17. *   of the error code.
  18. *
  19. *   Do not pmassert any assignment statements or function calls, for these
  20. *   statements will vanish in the non-debug version of the code. Assert only
  21. *   Boolean expressions you think should always be true.
  22. *
  23. ****************************************************************************/
  24.  
  25. #ifndef NDEBUG
  26.  
  27. #define pmassert(hab,exp)\
  28. {\
  29. if(!(exp)) {\
  30.   char ebuff[ 64 ]; unsigned long errorid; unsigned long rc;\
  31.   errorid = WinGetLastError( hab ); \
  32.   sprintf( ebuff, "Line %d\nFile %s\nLast Error %p\nExpression %s\n",\
  33.                  __LINE__, __FILE__, errorid, #exp );\
  34.   rc = WinMessageBox( HWND_DESKTOP, HWND_DESKTOP, ebuff,\
  35.                  "Assertion failed. Continue?", 0, MB_YESNO  );\
  36.   if( rc == MBID_NO ) exit( 1 );\
  37. }\
  38. }
  39.  
  40.  
  41. #else
  42.   #define pmassert(hab,exp)
  43. #endif
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.