Source code of Windows XP (NT5)
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.

194 lines
5.6 KiB

  1. #ifndef _MACROS_H_
  2. #define _MACROS_H_
  3. /*++
  4. Copyright (c) 2000 Microsoft Corporation
  5. Module Name:
  6. MACROS.H
  7. Abstract:
  8. Project agnostic utility macros
  9. Author:
  10. 990518 dane Created.
  11. 990721 dane Removed ASSERTs from ROE_*. A failure does not
  12. necessarily an ASSERT need.
  13. georgema 000310 updated
  14. Environment:
  15. Win98, Win2000
  16. Revision History:
  17. --*/
  18. #include <crtdbg.h>
  19. #if _MSC_VER > 1000
  20. // make the beginning and end of a namespace stand out
  21. //
  22. #define BEGIN_NAMESPACE(name) namespace name {
  23. #define END_NAMESPACE(name) };
  24. #define USING_NAMESPACE(name) using namespace name
  25. #else
  26. #define BEGIN_NAMESPACE(name)
  27. #define END_NAMESPACE(name)
  28. #define USING_NAMESPACE(name)
  29. #endif // _MSC_VER > 1000
  30. // Heap allocation...use CRT debug new when _DEBUG is defined
  31. //
  32. #ifdef _DEBUG
  33. #define _NEW new(_CLIENT_BLOCK, _THIS_FILE_, __LINE__)
  34. #else // ! _DEBUG
  35. #define _NEW new
  36. #endif // _DEBUG
  37. #define _DELETE delete
  38. // aliases for assertion macros
  39. //
  40. #ifdef ASSERT
  41. #undef ASSERT
  42. #endif // ASSERT
  43. #ifdef VERIFY
  44. #undef VERIFY
  45. #endif // VERIFY
  46. #ifdef _DEBUG
  47. #define ASSERT(cond) _ASSERTE(cond)
  48. #define VERIFY(cond) _ASSERTE(cond)
  49. #else // NDEBUG
  50. #define ASSERT(cond) ((void)0)
  51. #define VERIFY(cond) (cond)
  52. #endif // _DEBUG
  53. // aliases for segment names
  54. //
  55. #ifdef DATASEG_READONLY
  56. #undef DATASEG_READONLY
  57. #endif // DATASEG_READONLY
  58. #define DATASEG_READONLY ".rdata"
  59. //////////////////////////////////////////////////////////////////////////////
  60. //
  61. // RETURN ON ERROR macros
  62. //
  63. // ROE_HRESULT
  64. // ROE_LRESULT
  65. // ROE_POINTER
  66. //
  67. // Checks a return code or condition and returns a user-supplied error code if
  68. // an error has occurred.
  69. //
  70. // Usage:
  71. // TYPE Foo( )
  72. // {
  73. // TYPE status = Bar( );
  74. // ROE_TYPE(status, ret);
  75. //
  76. // // continue processing...
  77. // }
  78. //
  79. //
  80. #define ROE_HRESULT(hr, ret) \
  81. if (FAILED(hr)) \
  82. { \
  83. LogError(0, _THIS_FILE_, __LINE__, \
  84. _T("0x%08X 0x%08X\n"), \
  85. hr, ret); \
  86. return (ret); \
  87. }
  88. #define ROE_LRESULT(lr, ret) \
  89. if (ERROR_SUCCESS != lr) \
  90. { \
  91. LogError(0, _THIS_FILE_, __LINE__, \
  92. _T("0x%08X 0x%08X\n"), \
  93. lr, ret); \
  94. return (ret); \
  95. }
  96. #define ROE_POINTER(p, ret) \
  97. if (NULL == (p)) \
  98. { \
  99. LogError(0, _THIS_FILE_, __LINE__, \
  100. _T("0x%08X\n"), \
  101. ret); \
  102. return (ret); \
  103. }
  104. #define ROE_CONDITION(cond, ret) \
  105. if (! (cond)) \
  106. { \
  107. LogError(0, _THIS_FILE_, __LINE__, \
  108. _T("0x%08X 0x%08X\n"), \
  109. ##cond, ret); \
  110. return (ret); \
  111. }
  112. //////////////////////////////////////////////////////////////////////////////
  113. //
  114. // CHECK macros
  115. //
  116. // CHECK_HRESULT
  117. // CHECK_LRESULT
  118. // CHECK_POINTER
  119. // CHECK_MESSAGE
  120. //
  121. // Checks a return code or condition and returns a user-supplied error code if
  122. // an error has occurred.
  123. //
  124. // Usage:
  125. // TYPE Foo( )
  126. // {
  127. // TYPE status = Bar( );
  128. // CHECK_TYPE(status);
  129. //
  130. // // continue processing...
  131. // }
  132. //
  133. //
  134. #define CHECK_HRESULT(hr) \
  135. (FAILED(hr)) \
  136. ? LogError(0, _THIS_FILE_, __LINE__, _T("0x%08X"), hr), hr \
  137. : hr
  138. #define CHECK_LRESULT(lr) \
  139. (ERROR_SUCCESS != lr) \
  140. ? LogError(0, _THIS_FILE_, __LINE__, _T("0x%08X"), lr), lr \
  141. : lr
  142. #define CHECK_POINTER(p) \
  143. (NULL == (p)) \
  144. ? LogError(0, _THIS_FILE_, __LINE__, _T("NULL pointer"), p), p \
  145. : p
  146. #ifdef _DEBUG
  147. #define CHECK_MESSAGE(hwnd, msg, wparam, lparam) \
  148. { \
  149. LogInfo(0, _THIS_FILE_, __LINE__, \
  150. _T("MESSAGE: 0x%08X, 0x%08X, 0x%08X, 0x%08X\n"), \
  151. hwnd, msg, wparam, lparam); \
  152. }
  153. #else
  154. #define CHECK_MESSAGE(hwnd, msg, wparam, lparam) ((void)0)
  155. #endif // _DEBUG
  156. // count of elements in an array
  157. //
  158. #define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
  159. #endif // _MACROS_H_
  160. //
  161. ///// End of file: Macros.h ////////////////////////////////////////////////