home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / axscript / spruuids / src / debug.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-15  |  3.0 KB  |  78 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-1996 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. #ifdef DEBUG
  19.  
  20. VOID DisplayAssert(LPSTR pszMsg, LPSTR pszAssert, LPSTR pszFile, UINT line);
  21.  
  22. // *** Include this macro at the top of any source file using *ASSERT*() macros ***
  23. #define SZTHISFILE    static char _szThisFile[] = __FILE__;
  24.  
  25. // Our versions of the ASSERT and FAIL macros.
  26. #define ASSERT(fTest, szMsg)                                \
  27.     if (!(fTest))                                           \
  28.         {                                                   \
  29.         static char szMsgCode[] = szMsg;                    \
  30.         static char szAssert[] = #fTest;                    \
  31.         DisplayAssert(szMsgCode, szAssert, _szThisFile, __LINE__); \
  32.         }
  33.  
  34. #define FAIL(szMsg)                                         \
  35.         { static char szMsgCode[] = szMsg;                    \
  36.         DisplayAssert(szMsgCode, "FAIL", _szThisFile, __LINE__); }
  37.  
  38. #else  // DEBUG
  39.  
  40. #define SZTHISFILE
  41. #define ASSERT(fTest, err)
  42. #define FAIL(err)
  43.  
  44. #endif    // DEBUG
  45.  
  46.  
  47. //---------------------------------------------------------------------------
  48. // Macro that checks a pointer for validity on input
  49. //---------------------------------------------------------------------------
  50. #ifdef DEBUG
  51. #define CHECK_POINTER(val) if (!(val) || IsBadWritePtr((void *)(val), sizeof(void *))) return E_POINTER
  52. #else  // DEBUG
  53. #define CHECK_POINTER(val)
  54. #endif // DEBUG
  55.  
  56.  
  57. //---------------------------------------------------------------------------
  58. // Track signatures on objects for debugging
  59. //---------------------------------------------------------------------------
  60. #ifdef DEBUG
  61.  
  62. #define SIG_destroyed 'XxXx'
  63. #define DECLARE_SIGNATURE(x)    DWORD __sig
  64. #define CHECK_SIGNATURE(x)      ASSERT(this->__sig == (x), "Bad signature")
  65. #define INIT_SIGNATURE(x)       this->__sig = (x)
  66. #define DESTROY_SIGNATURE(x)    this->__sig = SIG_destroyed
  67.  
  68. #else // DEBUG
  69.  
  70. #define DECLARE_SIGNATURE(x)
  71. #define CHECK_SIGNATURE(x)
  72. #define INIT_SIGNATURE(x)
  73. #define DESTROY_SIGNATURE(x)
  74.  
  75. #endif // DEBUG
  76.  
  77. //--- EOF -------------------------------------------------------------------
  78.