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.

121 lines
5.1 KiB

  1. /********************************************************************
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. pfrutil.h
  5. Abstract:
  6. PFR utility stuff
  7. Revision History:
  8. DerekM created 05/01/99
  9. ********************************************************************/
  10. #ifndef PFRUTIL_H
  11. #define PFRUTIL_H
  12. // make sure both _DEBUG & DEBUG are defined if one is defined. Otherwise
  13. // the ASSERT macro never does anything
  14. #if defined(_DEBUG) && !defined(DEBUG)
  15. #define DEBUG 1
  16. #endif
  17. #if defined(DEBUG) && !defined(_DEBUG)
  18. #define _DEBUG 1
  19. #endif
  20. #define NOTRACE 1
  21. ////////////////////////////////////////////////////////////////////////////
  22. // tracing wrappers
  23. // can't call HRESULT_FROM_WIN32 with a fn as a parameter cuz it is a macro
  24. // and evaluates the expression 3 times. This is a particularlly bad thing
  25. // when u don't look at macros first to see what they do.
  26. _inline HRESULT ChangeErrToHR(DWORD dwErr) { return HRESULT_FROM_WIN32(dwErr); }
  27. #if defined(NOTRACE)
  28. #define INIT_TRACING
  29. #define TERM_TRACING
  30. #define USE_TRACING(sz)
  31. #define TESTHR(hr, fn) \
  32. hr = (fn);
  33. #define TESTBOOL(hr, fn) \
  34. hr = ((fn) ? NOERROR : HRESULT_FROM_WIN32(GetLastError()));
  35. #define TESTERR(hr, fn) \
  36. SetLastError((fn)); \
  37. hr = HRESULT_FROM_WIN32(GetLastError());
  38. #define VALIDATEPARM(hr, expr) \
  39. hr = ((expr) ? E_INVALIDARG : NOERROR);
  40. #define VALIDATEEXPR(hr, expr, hrErr) \
  41. hr = ((expr) ? (hrErr) : NOERROR);
  42. #else
  43. #define INIT_TRACING \
  44. InitAsyncTrace();
  45. #define TERM_TRACING \
  46. TermAsyncTrace();
  47. #define USE_TRACING(sz) \
  48. TraceQuietEnter(sz); \
  49. TraceFunctEntry(sz); \
  50. DWORD __dwtraceGLE = GetLastError(); \
  51. #define TESTHR(hr, fn) \
  52. if (FAILED(hr = (fn))) \
  53. { \
  54. __dwtraceGLE = GetLastError(); \
  55. ErrorTrace(0, "%s failed. Err: 0x%08x", #fn, hr); \
  56. SetLastError(__dwtraceGLE); \
  57. } \
  58. #define TESTBOOL(hr, fn) \
  59. hr = NOERROR; \
  60. if ((fn) == FALSE) \
  61. { \
  62. __dwtraceGLE = GetLastError(); \
  63. hr = HRESULT_FROM_WIN32(__dwtraceGLE); \
  64. ErrorTrace(0, "%s failed. Err: 0x%08x", #fn, hr); \
  65. SetLastError(__dwtraceGLE); \
  66. }
  67. #define TESTERR(hr, fn) \
  68. SetLastError((fn)); \
  69. if (FAILED(hr = HRESULT_FROM_WIN32(GetLastError()))) \
  70. { \
  71. __dwtraceGLE = GetLastError(); \
  72. ErrorTrace(0, "%s failed. Err: %d", #fn, hr); \
  73. SetLastError(__dwtraceGLE); \
  74. }
  75. #define VALIDATEPARM(hr, expr) \
  76. if (expr) \
  77. { \
  78. ErrorTrace(0, "Invalid parameters passed to %s", \
  79. ___pszFunctionName); \
  80. SetLastError(ERROR_INVALID_PARAMETER); \
  81. hr = E_INVALIDARG; \
  82. } \
  83. else hr = NOERROR;
  84. #define VALIDATEEXPR(hr, expr, hrErr) \
  85. if (expr) \
  86. { \
  87. ErrorTrace(0, "Expression failure %s", #expr); \
  88. hr = (hrErr); \
  89. } \
  90. else hr = NOERROR;
  91. #endif
  92. #endif