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.

193 lines
5.4 KiB

  1. /*----------------------------------------------------------------------------
  2. ErrUtil.H
  3. Exported header file for Error module.
  4. Copyright (C) Microsoft Corporation, 1993 - 1999
  5. All rights reserved.
  6. Authors:
  7. kennt Kenn Takara
  8. ----------------------------------------------------------------------------*/
  9. #ifndef _ERRUTIL_H
  10. #define _ERRUTIL_H
  11. #if _MSC_VER >= 1000 // VC 5.0 or later
  12. #pragma once
  13. #endif
  14. #ifndef _TFSINT_H
  15. #include "tfsint.h"
  16. #endif
  17. BOOL FHrFailed(HRESULT hr);
  18. BOOL FHrSucceeded(HRESULT hr);
  19. BOOL FHrOK(HRESULT hr);
  20. #define FHrOk(hr) FHrOK(hr) // archaic case
  21. inline BOOL FHrFailed(HRESULT hr)
  22. {
  23. return FAILED(hr);
  24. }
  25. inline BOOL FHrSucceeded(HRESULT hr)
  26. {
  27. return SUCCEEDED(hr);
  28. }
  29. inline BOOL FHrOK(HRESULT hr)
  30. {
  31. return hr == 0;
  32. }
  33. /*---------------------------------------------------------------------------
  34. Function: InitializeErrorObject
  35. Initializes the error structure for the current thread (this is all
  36. done on a thread-by-thread basis).
  37. ---------------------------------------------------------------------------*/
  38. extern "C"
  39. {
  40. TFSCORE_API(HRESULT) InitializeTFSError();
  41. TFSCORE_API(HRESULT) CleanupTFSError();
  42. TFSCORE_API(ITFSError *) GetTFSErrorObject();
  43. TFSCORE_API(HANDLE) GetTFSErrorHeap();
  44. TFSCORE_API(HRESULT) CreateTFSErrorInfo(LONG_PTR uReserved);
  45. TFSCORE_API(HRESULT) CreateTFSErrorInfoForThread(DWORD dwThreadId, LONG_PTR uReserved);
  46. TFSCORE_API(HRESULT) DestroyTFSErrorInfo(LONG_PTR uReserved);
  47. TFSCORE_API(HRESULT) DestroyTFSErrorInfoForThread(DWORD dwThreadId, LONG_PTR uReserved);
  48. TFSCORE_API(HRESULT) ClearTFSErrorInfo(LONG_PTR uReserved);
  49. TFSCORE_API(HRESULT) ClearTFSErrorInfoForThread(DWORD dwThreadId, LONG_PTR uReserved);
  50. TFSCORE_API(HRESULT) GetTFSErrorInfo(TFSErrorInfo **ppErrInfo);
  51. TFSCORE_API(HRESULT) GetTFSErrorInfoForThread(DWORD dwThreadId, TFSErrorInfo **ppErrInfo);
  52. TFSCORE_API(HRESULT) SetTFSErrorInfo(const TFSErrorInfo *pErrInfo);
  53. TFSCORE_API(HRESULT) SetTFSErrorInfoForThread(DWORD dwThreadId, const TFSErrorInfo *pErrInfo);
  54. TFSCORE_API(HRESULT) TFSErrorInfoFree(TFSErrorInfo *pErrInfo);
  55. TFSCORE_API(HRESULT) DisplayTFSErrorMessage(HWND hWnd);
  56. #define FILLTFSERR_HIGH 0x01
  57. #define FILLTFSERR_LOW 0x02
  58. #define FILLTFSERR_GEEK 0x04
  59. #define FILLTFSERR_NOCLOBBER 0x08
  60. TFSCORE_API(HRESULT) FillTFSError(LONG_PTR uReserved,
  61. HRESULT hrLow,
  62. DWORD dwFlags,
  63. LPCTSTR pszHigh,
  64. LPCTSTR pszLow,
  65. LPCTSTR pszGeek);
  66. TFSCORE_API(HRESULT) FillTFSErrorId(LONG_PTR uReserved,
  67. HRESULT hrLow,
  68. DWORD dwFlags,
  69. UINT nHigh,
  70. UINT nLow,
  71. UINT nGeek);
  72. };
  73. // Use this function for most error handling
  74. TFSCORE_API(HRESULT) FormatError(HRESULT hr, TCHAR *pszBuffer, UINT cchBuffer);
  75. /*---------------------------------------------------------------------------
  76. Helper APIs for the COR macros.
  77. ---------------------------------------------------------------------------*/
  78. TFSCORE_API(void) AddSystemErrorMessage(HRESULT hr);
  79. TFSCORE_API(void) AddWin32ErrorMessage(DWORD dwErr);
  80. #define AddStringIdErrorMessage(hr,ids) FillTFSErrorId(0, hr, FILLTFSERR_HIGH, ids, 0, 0)
  81. #define AddStringIdErrorMessage2(hr, ids, idsgeek) FillTFSErrorId(0, hr, FILLTFSERR_HIGH | FILLTFSERR_GEEK, ids, 0, idsgeek)
  82. #define AddStringErrorMessage(hr, psz) FillTFSError(0, hr, FILLTFSERR_HIGH, psz, 0, 0)
  83. #define AddStringErrorMessage2(hr, psz, pszGeek) FillTFSError(0, hr, FILLTFSERR_HIGH | FILLTFSERR_GEEK, psz, 0, pszGeek)
  84. /*---------------------------------------------------------------------------
  85. These next three functions set the high-level error string, but
  86. do NOT set the underlying HRESULT.
  87. ---------------------------------------------------------------------------*/
  88. #define AddHighLevelErrorString(psz) AddStringErrorMessage(0, psz)
  89. #define AddHighLevelErrorStringId(ids) AddStringIdErrorMessage(0, ids)
  90. #define AddHighLevelErrorStringId2(ids, idsGeek) AddStringIdErrorMessage2(0, ids, idsGeek)
  91. #define SetDefaultHighLevelErrorStringId(ids) \
  92. FillTFSErrorId(0, hr, FILLTFSERR_HIGH | FILLTFSERR_NOCLOBBER, ids, 0, 0)
  93. #define AddLowLevelErrorString(psz) FillTFSError(0, 0, FILLTFSERR_LOW, NULL, psz, NULL)
  94. #define AddLowLevelErrorStringId(ids) FillTFSErrorId(0, 0, FILLTFSERR_LOW, NULL, ids, NULL)
  95. #define AddGeekLevelErrorString(psz) FillTFSError(0, 0, FILLTFSERR_GEEK, NULL, NULL, psz)
  96. #define AddGeekLevelErrorStringId(ids) FillTFSErrorId(0, 0, FILLTFSERR_GEEK, NULL, NULL, ids)
  97. #define CORg(hResult) \
  98. do\
  99. {\
  100. hr = (hResult);\
  101. if (FHrFailed(hr))\
  102. {\
  103. AddSystemErrorMessage(hr);\
  104. goto Error;\
  105. }\
  106. }\
  107. while (FALSE)
  108. #define CWRg(hResult) \
  109. do\
  110. {\
  111. hr = (DWORD) hResult;\
  112. hr = HRESULT_FROM_WIN32(hr);\
  113. if (FHrFailed(hr))\
  114. {\
  115. AddSystemErrorMessage(hr);\
  116. goto Error;\
  117. }\
  118. }\
  119. while (FALSE)
  120. #define CORg_s(hResult, ids)\
  121. do\
  122. {\
  123. hr = (hResult);\
  124. if (FHrFailed(hr))\
  125. {\
  126. AddStringIdErrorMessage(hr);\
  127. goto Error;\
  128. }\
  129. }\
  130. while (FALSE)
  131. #define CORg_sz(hResult, sz)\
  132. do\
  133. {\
  134. hr = (hResult);\
  135. if (FHrFailed(hr))\
  136. {\
  137. AddStringErrorMessage(hr);\
  138. goto Error;\
  139. }\
  140. }\
  141. while (FALSE)
  142. // Provide for an inline expansion
  143. inline HRESULT HResultFromWin32(DWORD dwError)
  144. {
  145. return HRESULT_FROM_WIN32(dwError);
  146. }
  147. #endif