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.

240 lines
6.4 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // hrstr.cpp
  4. //
  5. // HRESULT-to-string mapper.
  6. //
  7. // Copyright (C) Microsoft Corporation, 1997.
  8. //
  9. //----------------------------------------------------------------------------
  10. #include "pch.cpp"
  11. #pragma hdrstop
  12. #if DBG
  13. #include "cppdbg.hpp"
  14. struct HrStringDef
  15. {
  16. HRESULT hr;
  17. char *pString;
  18. };
  19. #define HRDEF(Name) \
  20. Name, #Name
  21. static HrStringDef g_HrStringDefs[] =
  22. {
  23. // Put specific codes before generic codes so that specific codes
  24. // are returned in the cases where the HRESULT is the same.
  25. HRDEF(DDERR_ALREADYINITIALIZED),
  26. HRDEF(DDERR_BLTFASTCANTCLIP),
  27. HRDEF(DDERR_CANNOTATTACHSURFACE),
  28. HRDEF(DDERR_CANNOTDETACHSURFACE),
  29. HRDEF(DDERR_CANTCREATEDC),
  30. HRDEF(DDERR_CANTDUPLICATE),
  31. HRDEF(DDERR_CLIPPERISUSINGHWND),
  32. HRDEF(DDERR_COLORKEYNOTSET),
  33. HRDEF(DDERR_CURRENTLYNOTAVAIL),
  34. HRDEF(DDERR_DIRECTDRAWALREADYCREATED),
  35. HRDEF(DDERR_EXCEPTION),
  36. HRDEF(DDERR_EXCLUSIVEMODEALREADYSET),
  37. HRDEF(DDERR_GENERIC),
  38. HRDEF(DDERR_HEIGHTALIGN),
  39. HRDEF(DDERR_HWNDALREADYSET),
  40. HRDEF(DDERR_HWNDSUBCLASSED),
  41. HRDEF(DDERR_IMPLICITLYCREATED),
  42. HRDEF(DDERR_INCOMPATIBLEPRIMARY),
  43. HRDEF(DDERR_INVALIDCAPS),
  44. HRDEF(DDERR_INVALIDCLIPLIST),
  45. HRDEF(DDERR_INVALIDDIRECTDRAWGUID),
  46. HRDEF(DDERR_INVALIDMODE),
  47. HRDEF(DDERR_INVALIDOBJECT),
  48. HRDEF(DDERR_INVALIDPARAMS),
  49. HRDEF(DDERR_INVALIDPIXELFORMAT),
  50. HRDEF(DDERR_INVALIDPOSITION),
  51. HRDEF(DDERR_INVALIDRECT),
  52. HRDEF(DDERR_LOCKEDSURFACES),
  53. HRDEF(DDERR_NO3D),
  54. HRDEF(DDERR_NOALPHAHW),
  55. HRDEF(DDERR_NOBLTHW),
  56. HRDEF(DDERR_NOCLIPLIST),
  57. HRDEF(DDERR_NOCLIPPERATTACHED),
  58. HRDEF(DDERR_NOCOLORCONVHW),
  59. HRDEF(DDERR_NOCOLORKEY),
  60. HRDEF(DDERR_NOCOLORKEYHW),
  61. HRDEF(DDERR_NOCOOPERATIVELEVELSET),
  62. HRDEF(DDERR_NODC),
  63. HRDEF(DDERR_NODDROPSHW),
  64. HRDEF(DDERR_NODIRECTDRAWHW),
  65. HRDEF(DDERR_NOEMULATION),
  66. HRDEF(DDERR_NOEXCLUSIVEMODE),
  67. HRDEF(DDERR_NOFLIPHW),
  68. HRDEF(DDERR_NOGDI),
  69. HRDEF(DDERR_NOHWND),
  70. HRDEF(DDERR_NOMIRRORHW),
  71. HRDEF(DDERR_NOOVERLAYDEST),
  72. HRDEF(DDERR_NOOVERLAYHW),
  73. HRDEF(DDERR_NOPALETTEATTACHED),
  74. HRDEF(DDERR_NOPALETTEHW),
  75. HRDEF(DDERR_NORASTEROPHW),
  76. HRDEF(DDERR_NOROTATIONHW),
  77. HRDEF(DDERR_NOSTRETCHHW),
  78. HRDEF(DDERR_NOT4BITCOLOR),
  79. HRDEF(DDERR_NOT4BITCOLORINDEX),
  80. HRDEF(DDERR_NOT8BITCOLOR),
  81. HRDEF(DDERR_NOTAOVERLAYSURFACE),
  82. HRDEF(DDERR_NOTEXTUREHW),
  83. HRDEF(DDERR_NOTFLIPPABLE),
  84. HRDEF(DDERR_NOTFOUND),
  85. HRDEF(DDERR_NOTLOCKED),
  86. HRDEF(DDERR_NOTPALETTIZED),
  87. HRDEF(DDERR_NOVSYNCHW),
  88. HRDEF(DDERR_NOZBUFFERHW),
  89. HRDEF(DDERR_NOZOVERLAYHW),
  90. HRDEF(DDERR_OUTOFCAPS),
  91. HRDEF(DDERR_OUTOFMEMORY),
  92. HRDEF(DDERR_OUTOFVIDEOMEMORY),
  93. HRDEF(DDERR_OVERLAYCANTCLIP),
  94. HRDEF(DDERR_OVERLAYCOLORKEYONLYONEACTIVE),
  95. HRDEF(DDERR_OVERLAYNOTVISIBLE),
  96. HRDEF(DDERR_PALETTEBUSY),
  97. HRDEF(DDERR_PRIMARYSURFACEALREADYEXISTS),
  98. HRDEF(DDERR_REGIONTOOSMALL),
  99. HRDEF(DDERR_SURFACEALREADYATTACHED),
  100. HRDEF(DDERR_SURFACEALREADYDEPENDENT),
  101. HRDEF(DDERR_SURFACEBUSY),
  102. HRDEF(DDERR_SURFACEISOBSCURED),
  103. HRDEF(DDERR_SURFACELOST),
  104. HRDEF(DDERR_SURFACENOTATTACHED),
  105. HRDEF(DDERR_TOOBIGHEIGHT),
  106. HRDEF(DDERR_TOOBIGSIZE),
  107. HRDEF(DDERR_TOOBIGWIDTH),
  108. HRDEF(DDERR_UNSUPPORTED),
  109. HRDEF(DDERR_UNSUPPORTEDFORMAT),
  110. HRDEF(DDERR_UNSUPPORTEDMASK),
  111. HRDEF(DDERR_VERTICALBLANKINPROGRESS),
  112. HRDEF(DDERR_WASSTILLDRAWING),
  113. HRDEF(DDERR_WRONGMODE),
  114. HRDEF(DDERR_XALIGN),
  115. HRDEF(E_OUTOFMEMORY),
  116. HRDEF(E_INVALIDARG),
  117. HRDEF(E_FAIL),
  118. HRDEF(S_FALSE),
  119. HRDEF(S_OK),
  120. HRDEF(D3DERR_WRONGTEXTUREFORMAT),
  121. HRDEF(D3DERR_UNSUPPORTEDCOLOROPERATION),
  122. HRDEF(D3DERR_UNSUPPORTEDCOLORARG),
  123. HRDEF(D3DERR_UNSUPPORTEDALPHAOPERATION),
  124. HRDEF(D3DERR_UNSUPPORTEDALPHAARG),
  125. HRDEF(D3DERR_TOOMANYOPERATIONS),
  126. HRDEF(D3DERR_CONFLICTINGTEXTUREFILTER),
  127. HRDEF(D3DERR_UNSUPPORTEDFACTORVALUE),
  128. HRDEF(D3DERR_CONFLICTINGRENDERSTATE),
  129. HRDEF(D3DERR_UNSUPPORTEDTEXTUREFILTER),
  130. HRDEF(D3DERR_CONFLICTINGTEXTUREPALETTE),
  131. HRDEF(D3DERR_DRIVERINTERNALERROR),
  132. HRDEF(D3DERR_NOTFOUND),
  133. HRDEF(D3DERR_MOREDATA),
  134. HRDEF(D3DERR_DEVICENOTRESET),
  135. HRDEF(D3DERR_DEVICELOST),
  136. HRDEF(D3DERR_NOTAVAILABLE),
  137. HRDEF(D3DERR_INVALIDDEVICE),
  138. HRDEF(D3DERR_INVALIDCALL),
  139. 0, NULL,
  140. };
  141. //----------------------------------------------------------------------------
  142. //
  143. // DebugModule::HrString
  144. //
  145. // Attempts to produce a descriptive string for the given HRESULT.
  146. //
  147. //----------------------------------------------------------------------------
  148. char *DebugModule::HrString(HRESULT hr)
  149. {
  150. HrStringDef *pHrDef;
  151. // Look for a defined string.
  152. for (pHrDef = g_HrStringDefs; pHrDef->pString != NULL; pHrDef++)
  153. {
  154. if (pHrDef->hr == hr)
  155. {
  156. return pHrDef->pString;
  157. }
  158. }
  159. // It's not a defined string so return the numeric value
  160. // as a string. Use a circular buffer of strings so that
  161. // this routine can be used more than once in a particular output
  162. // message.
  163. #define STATIC_BUFFER 256
  164. #define MAX_STRING 16
  165. static char chBuffer[STATIC_BUFFER];
  166. static char *pBuf = chBuffer;
  167. char *pString;
  168. if (pBuf - chBuffer + MAX_STRING > STATIC_BUFFER)
  169. {
  170. pBuf = chBuffer;
  171. }
  172. sprintf(pBuf, "0x%08X", hr);
  173. pString = pBuf;
  174. pBuf += MAX_STRING;
  175. return pString;
  176. }
  177. //----------------------------------------------------------------------------
  178. //
  179. // HrString
  180. //
  181. // Attempts to produce a descriptive string for the given HRESULT.
  182. //
  183. //----------------------------------------------------------------------------
  184. char *HrToStr(HRESULT hr)
  185. {
  186. HrStringDef *pHrDef;
  187. // Look for a defined string.
  188. for (pHrDef = g_HrStringDefs; pHrDef->pString != NULL; pHrDef++)
  189. {
  190. if (pHrDef->hr == hr)
  191. {
  192. return pHrDef->pString;
  193. }
  194. }
  195. // It's not a defined string so return the numeric value
  196. // as a string. Use a circular buffer of strings so that
  197. // this routine can be used more than once in a particular output
  198. // message.
  199. #define STATIC_BUFFER 256
  200. #define MAX_STRING 16
  201. static char chBuffer[STATIC_BUFFER];
  202. static char *pBuf = chBuffer;
  203. char *pString;
  204. if (pBuf - chBuffer + MAX_STRING > STATIC_BUFFER)
  205. {
  206. pBuf = chBuffer;
  207. }
  208. sprintf(pBuf, "0x%08X", hr);
  209. pString = pBuf;
  210. pBuf += MAX_STRING;
  211. return pString;
  212. }
  213. #endif // #if DBG