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.

105 lines
5.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Useful classes, macros
  3. #pragma once
  4. #define GXN_EVAL(X) X
  5. #define GXN_STRINGIZE_ARG(X) #X
  6. #define GXN_STRINGIZE(X) GXN_EVAL(GXN_STRINGIZE_ARG(X))
  7. #define GXN_MERGE(A, B) A##B
  8. #define GXN_MAKE_W(A) GXN_MERGE(L, A)
  9. #define GXN_WSTRINGIZE(X) GXN_MAKE_W(GXN_STRINGIZE(X))
  10. #define __GXN_WFILE__ GXN_MAKE_W(GXN_EVAL(__FILE__))
  11. #define GXN_ERROR_CASE(wszBuffer, dwBufferLen, X) \
  12. case X: ::StringCchCopyW(wszBuffer, dwBufferLen, GXN_MAKE_W(GXN_EVAL(#X)) ); break;
  13. #define GXN_WSTR_GUID_FMT L"{%.8x-%.4x-%.4x-%.2x%.2x-%.2x%.2x%.2x%.2x%.2x%.2x}"
  14. #define GXN_WSTR_DWORD_FMT L"%c%c%c%c%c%c%c%c.%c%c%c%c%c%c%c%c.%c%c%c%c%c%c%c%c.%c%c%c%c%c%c%c%c"
  15. #define GXN_GUID_PRINTF_ARG( X ) \
  16. (X).Data1, \
  17. (X).Data2, \
  18. (X).Data3, \
  19. (X).Data4[0], (X).Data4[1], (X).Data4[2], (X).Data4[3], \
  20. (X).Data4[4], (X).Data4[5], (X).Data4[6], (X).Data4[7]
  21. #define GXN_BIT_PRINTF_ARG( X, val ) (((X) & (1 << (val-1)))? L'1': L'0')
  22. #define GXN_DWORD_PRINTF_ARG( X ) \
  23. GXN_BIT_PRINTF_ARG(X,0x20), GXN_BIT_PRINTF_ARG(X,0x1f), GXN_BIT_PRINTF_ARG(X,0x1e), GXN_BIT_PRINTF_ARG(X,0x1d), \
  24. GXN_BIT_PRINTF_ARG(X,0x1c), GXN_BIT_PRINTF_ARG(X,0x1b), GXN_BIT_PRINTF_ARG(X,0x1A), GXN_BIT_PRINTF_ARG(X,0x19), \
  25. GXN_BIT_PRINTF_ARG(X,0x18), GXN_BIT_PRINTF_ARG(X,0x17), GXN_BIT_PRINTF_ARG(X,0x16), GXN_BIT_PRINTF_ARG(X,0x15), \
  26. GXN_BIT_PRINTF_ARG(X,0x14), GXN_BIT_PRINTF_ARG(X,0x13), GXN_BIT_PRINTF_ARG(X,0x12), GXN_BIT_PRINTF_ARG(X,0x11), \
  27. GXN_BIT_PRINTF_ARG(X,0x10), GXN_BIT_PRINTF_ARG(X,0x0f), GXN_BIT_PRINTF_ARG(X,0x0e), GXN_BIT_PRINTF_ARG(X,0x0d), \
  28. GXN_BIT_PRINTF_ARG(X,0x0c), GXN_BIT_PRINTF_ARG(X,0x0b), GXN_BIT_PRINTF_ARG(X,0x0A), GXN_BIT_PRINTF_ARG(X,0x09), \
  29. GXN_BIT_PRINTF_ARG(X,0x08), GXN_BIT_PRINTF_ARG(X,0x07), GXN_BIT_PRINTF_ARG(X,0x06), GXN_BIT_PRINTF_ARG(X,0x05), \
  30. GXN_BIT_PRINTF_ARG(X,0x04), GXN_BIT_PRINTF_ARG(X,0x03), GXN_BIT_PRINTF_ARG(X,0x02), GXN_BIT_PRINTF_ARG(X,0x01)
  31. #define CHECK_CONDITION( Cond, FinalCode ) \
  32. { \
  33. if (!(Cond)) { \
  34. ft.Msg(L"- ERROR: Condition %S not succeeded. \n", #Cond ); \
  35. do { FinalCode } while(0); \
  36. throw(E_UNEXPECTED); \
  37. } else \
  38. ft.Msg(L"- Condition %S succeeded\n", #Cond); \
  39. }
  40. #define CHECK_COM( Call, FinalCode ) \
  41. { \
  42. HRESULT hr = Call; \
  43. if (FAILED(hr)) { \
  44. ft.Msg(L"- ERROR: Call %S not succeeded. \n" \
  45. L"\t Error Code = 0x%08lx. Error description = %s\n", \
  46. #Call, hr, \
  47. GetStringFromFailureType(hr)); \
  48. do { FinalCode } while(0); \
  49. throw(hr); \
  50. } else \
  51. ft.Msg(L"- (OK) %S\n", #Call); \
  52. }
  53. #define CHECK_WIN32( Cond, FinalCode ) \
  54. { \
  55. if (!(Cond)) { \
  56. ft.Msg(L"- ERROR: Condition %S not succeeded. \n" \
  57. L"\t Error Code = 0x%08lx. Error description = %s\n", \
  58. #Cond, HRESULT_FROM_WIN32(GetLastError()), \
  59. GetStringFromFailureType(HRESULT_FROM_WIN32(GetLastError()))); \
  60. do { FinalCode } while(0); \
  61. throw(HRESULT_FROM_WIN32(GetLastError())); \
  62. } else \
  63. ft.Msg(L"- (OK) %S\n", #Cond); \
  64. }
  65. #define CHECK_WIN32_FUNC( LValue, Condition, Call, FinalCode ) \
  66. { \
  67. LValue = Call; \
  68. if (!(Condition)) { \
  69. ft.Msg(L"- ERROR: (%S) when %S \n" \
  70. L"\t Error Code = 0x%08lx. Error description = %s\n", \
  71. #Call, #Condition, HRESULT_FROM_WIN32(GetLastError()), \
  72. GetStringFromFailureType(HRESULT_FROM_WIN32(GetLastError()))); \
  73. do { FinalCode } while(0); \
  74. throw(HRESULT_FROM_WIN32(GetLastError())); \
  75. } else \
  76. ft.Msg(L"- (OK) %S\n", #Call); \
  77. }
  78. #define PRINT_ERROR_DELTA( dwError, dwLastError ) \
  79. if ( dwError == dwLastError ) {} else { \
  80. ft.Msg(L"- ERROR: %s = 0x%08lx [%s]. (Previous value 0x%08lx)\n", \
  81. #dwLastError, dwError, \
  82. GetStringFromFailureType(HRESULT_FROM_WIN32(GetLastError())), \
  83. dwLastError ); \
  84. dwLastError = dwError; \
  85. }