home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / internet / scripting / spruuids / debug.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  3.2 KB  |  84 lines

  1. //---------------------------------------------------------------------------
  2. // Debug.H
  3. //---------------------------------------------------------------------------
  4. // Contains the various macros and the like which are only useful in DEBUG
  5. // builds.
  6. //---------------------------------------------------------------------------
  7. // (C) Copyright 1995-1997 by Microsoft Corporation. All rights reserved.
  8. //
  9. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  10. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  11. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  12. // PARTICULAR PURPOSE.
  13. //---------------------------------------------------------------------------
  14.  
  15. //---------------------------------------------------------------------------
  16. // All the things required to handle our ASSERT mechanism
  17. //---------------------------------------------------------------------------
  18. #undef DEBUG
  19. // ;begin_internal
  20. // BUGBUG DisplayAssert is not coded in this release,
  21. // until it is, debug builds do not get these debug functions
  22. // ;end_internal
  23.  
  24. #ifdef DEBUG
  25.  
  26. VOID DisplayAssert(LPSTR pszMsg, LPSTR pszAssert, LPSTR pszFile, UINT line);
  27.  
  28. // *** Include this macro at the top of any source file using *ASSERT*() macros ***
  29. #define SZTHISFILE    static char _szThisFile[] = __FILE__;
  30.  
  31. // Our versions of the ASSERT and FAIL macros.
  32. #define ASSERT(fTest, szMsg)                                \
  33.     if (!(fTest))                                           \
  34.         {                                                   \
  35.         static char szMsgCode[] = szMsg;                    \
  36.         static char szAssert[] = #fTest;                    \
  37.         DisplayAssert(szMsgCode, szAssert, _szThisFile, __LINE__); \
  38.         }
  39.  
  40. #define FAIL(szMsg)                                         \
  41.         { static char szMsgCode[] = szMsg;                    \
  42.         DisplayAssert(szMsgCode, "FAIL", _szThisFile, __LINE__); }
  43.  
  44. #else  // DEBUG
  45.  
  46. #define SZTHISFILE
  47. #define ASSERT(fTest, err)
  48. #define FAIL(err)
  49.  
  50. #endif    // DEBUG
  51.  
  52.  
  53. //---------------------------------------------------------------------------
  54. // Macro that checks a pointer for validity on input
  55. //---------------------------------------------------------------------------
  56. #ifdef DEBUG
  57. #define CHECK_POINTER(val) if (!(val) || IsBadWritePtr((void *)(val), sizeof(void *))) return E_POINTER
  58. #else  // DEBUG
  59. #define CHECK_POINTER(val)
  60. #endif // DEBUG
  61.  
  62.  
  63. //---------------------------------------------------------------------------
  64. // Track signatures on objects for debugging
  65. //---------------------------------------------------------------------------
  66. #ifdef DEBUG
  67.  
  68. #define SIG_destroyed 'XxXx'
  69. #define DECLARE_SIGNATURE(x)    DWORD __sig
  70. #define CHECK_SIGNATURE(x)      ASSERT(this->__sig == (x), "Bad signature")
  71. #define INIT_SIGNATURE(x)       this->__sig = (x)
  72. #define DESTROY_SIGNATURE(x)    this->__sig = SIG_destroyed
  73.  
  74. #else // DEBUG
  75.  
  76. #define DECLARE_SIGNATURE(x)
  77. #define CHECK_SIGNATURE(x)
  78. #define INIT_SIGNATURE(x)
  79. #define DESTROY_SIGNATURE(x)
  80.  
  81. #endif // DEBUG
  82.  
  83. //--- EOF -------------------------------------------------------------------
  84.