Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
4.0 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: coredefs.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: LazarI
  10. *
  11. * DATE: 14-Feb-2001
  12. *
  13. * DESCRIPTION: core definitions
  14. *
  15. *****************************************************************************/
  16. #ifndef _COREDEFS_H_
  17. #define _COREDEFS_H_
  18. ////////////////////////////////////////////////////
  19. // win64 conversion macros
  20. //
  21. #define INT2PTR(i, ptrType) (reinterpret_cast<ptrType>(static_cast<INT_PTR>(i)))
  22. #define PTR2INT(ptr) (static_cast<INT>(reinterpret_cast<INT_PTR>(ptr)))
  23. #define UINT2PTR(u, ptrType) (reinterpret_cast<ptrType>(static_cast<UINT_PTR>(u)))
  24. #define PTR2UINT(ptr) (static_cast<UINT>(reinterpret_cast<UINT_PTR>(ptr)))
  25. #define LONG2PTR(l, ptrType) (reinterpret_cast<ptrType>(static_cast<LONG_PTR>(l)))
  26. #define PTR2LONG(ptr) (static_cast<LONG>(reinterpret_cast<LONG_PTR>(ptr)))
  27. #define DWORD2PTR(dw, ptrType) (reinterpret_cast<ptrType>(static_cast<DWORD_PTR>(dw)))
  28. #define PTR2DWORD(ptr) (static_cast<DWORD>(reinterpret_cast<DWORD_PTR>(ptr)))
  29. ////////////////////////////////////////////////////
  30. // check to define some useful debugging macros
  31. //
  32. #define BREAK_ON_FALSE(expr) \
  33. do \
  34. { \
  35. if (!(expr)) \
  36. { \
  37. if (IsDebuggerPresent()) \
  38. { \
  39. DebugBreak(); \
  40. } \
  41. else \
  42. { \
  43. RaiseException(EXCEPTION_ACCESS_VIOLATION, 0, 0, NULL); \
  44. } \
  45. } \
  46. } \
  47. while (false); \
  48. #if DBG
  49. // ***************** ASSERT *****************
  50. #ifndef ASSERT
  51. #if defined(SPLASSERT)
  52. // use SPLASSERT
  53. #define ASSERT(expr) SPLASSERT(expr)
  54. #else
  55. #if defined(WIA_ASSERT)
  56. // use WIA_ASSERT
  57. #define ASSERT(expr) WIA_ASSERT(expr)
  58. #else
  59. // ASSERT is not defined -- define a simple version
  60. #define ASSERT(expr) BREAK_ON_FALSE(expr)
  61. #endif // WIA_ASSERT
  62. #endif // SPLASSERT
  63. #endif // ASSERT
  64. // ***************** CHECK *****************
  65. #ifndef CHECK
  66. #if defined(DBGMSG) && defined(DBG_INFO)
  67. // use the printui trace macros
  68. #define CHECK(expr) \
  69. do \
  70. { \
  71. if(!(expr)) \
  72. { \
  73. DBGMSG(DBG_INFO, ("Failed: "TSTR", File: "TSTR", Line: %d\n", #expr, __FILE__, __LINE__)); \
  74. } \
  75. } \
  76. while(FALSE)
  77. #else
  78. // nothing special
  79. #define CHECK(expr) (expr)
  80. #endif // DBGMSG && DBG_INFO
  81. #endif // CHECK
  82. // ***************** VERIFY *****************
  83. #ifndef VERIFY
  84. #if defined(ASSERT)
  85. #define VERIFY(expr) ASSERT(expr)
  86. #else
  87. #define VERIFY(expr) (expr)
  88. #endif // ASSERT
  89. #endif // VERIFY
  90. // ***************** RIP *****************
  91. #ifndef RIP
  92. #if defined(ASSERT)
  93. #define RIP(expr) ASSERT(expr)
  94. #else
  95. #define RIP(expr) BREAK_ON_FALSE(expr)
  96. #endif // ASSERT
  97. #endif // RIP
  98. #else // DBG
  99. #undef ASSERT
  100. #undef VERIFY
  101. #undef CHECK
  102. #undef RIP
  103. #define ASSERT(expr)
  104. #define VERIFY(expr) (expr)
  105. #define CHECK(expr) (expr)
  106. #define RIP(expr) BREAK_ON_FALSE(expr)
  107. #endif // DBG
  108. ////////////////////////////////////////////////
  109. // some other helpful macros
  110. //
  111. #ifndef COUNTOF
  112. #define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
  113. #endif // COUNTOF
  114. #ifndef ARRAYSIZE
  115. #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
  116. #endif // ARRAYSIZE
  117. #endif // endif _COREDEFS_H_