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.

99 lines
2.7 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1999
  5. //
  6. // File: macros.h
  7. //
  8. // Contents: Useful macros
  9. //
  10. // Macros: ARRAYLEN
  11. //
  12. // BREAK_ON_FAIL(hresult)
  13. // BREAK_ON_FAIL(hresult)
  14. //
  15. // DECLARE_IUNKNOWN_METHODS
  16. // DECLARE_STANDARD_IUNKNOWN
  17. // IMPLEMENT_STANDARD_IUNKNOWN
  18. //
  19. // SAFE_RELEASE
  20. //
  21. // DECLARE_SAFE_INTERFACE_PTR_MEMBERS
  22. //
  23. // History: 6/3/1996 RaviR Created
  24. // 7/23/1996 JonN Added exception handling macros
  25. //
  26. //____________________________________________________________________________
  27. #ifndef _MACROS_H_
  28. #define _MACROS_H_
  29. //____________________________________________________________________________
  30. //
  31. // Macro: ARRAYLEN
  32. //
  33. // Purpose: To determine the length of an array.
  34. //____________________________________________________________________________
  35. //
  36. #define ARRAYLEN(a) (sizeof(a) / sizeof((a)[0]))
  37. //____________________________________________________________________________
  38. //
  39. // Macros: BREAK_ON_FAIL(hresult), BREAK_ON_ERROR(lastError)
  40. //
  41. // Purpose: To break out of a loop on error.
  42. //____________________________________________________________________________
  43. //
  44. #define BREAK_ON_FAIL(hr) if (FAILED(hr)) { break; } else 1;
  45. #define BREAK_ON_ERROR(lr) if (lr != ERROR_SUCCESS) { break; } else 1;
  46. #define RETURN_ON_FAIL(hr) if (FAILED(hr)) { return(hr); } else 1;
  47. #define THROW_ON_FAIL(hr) if (FAILED(hr)) { _com_issue_error(hr); } else 1;
  48. //____________________________________________________________________________
  49. //
  50. // Macros: DwordAlign(n)
  51. //____________________________________________________________________________
  52. //
  53. #define DwordAlign(n) (((n) + 3) & ~3)
  54. //____________________________________________________________________________
  55. //
  56. // Macros: IF_NULL_RETURN_INVALIDARG
  57. //____________________________________________________________________________
  58. //
  59. #define IF_NULL_RETURN_INVALIDARG(x) \
  60. { \
  61. ASSERT((x) != NULL); \
  62. if ((x) == NULL) \
  63. return E_INVALIDARG; \
  64. }
  65. #define IF_NULL_RETURN_INVALIDARG2(x, y) \
  66. IF_NULL_RETURN_INVALIDARG(x) \
  67. IF_NULL_RETURN_INVALIDARG(y)
  68. #define IF_NULL_RETURN_INVALIDARG3(x, y, z) \
  69. IF_NULL_RETURN_INVALIDARG(x) \
  70. IF_NULL_RETURN_INVALIDARG(y) \
  71. IF_NULL_RETURN_INVALIDARG(z)
  72. #define RELEASE_DATAOBJECT(pDataObj) \
  73. {\
  74. if ( (pDataObj) && (!IS_SPECIAL_DATAOBJECT(pDataObj))) \
  75. pDataObj->Release();\
  76. }
  77. #endif // _MACROS_H_