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.

220 lines
4.3 KiB

  1. /*
  2. * resstr.c - Return code to string translation routines.
  3. *
  4. * Taken from URL code
  5. *
  6. * Created: ChrisPi 9-11-95
  7. *
  8. */
  9. /* Headers
  10. **********/
  11. #include "precomp.h"
  12. /* Macros
  13. *********/
  14. /*
  15. * macro for simplifying result to string translation, assumes result string
  16. * pointer pcsz
  17. */
  18. #define STRING_CASE(val) case val: pcsz = #val; break
  19. /****************************** Public Functions *****************************/
  20. #ifdef DEBUG
  21. PCSTR GetINTString(int n)
  22. {
  23. static char s_rgchINT[] = "-2147483646";
  24. wsprintfA(s_rgchINT, "%d", n);
  25. ASSERT(IS_VALID_STRING_PTR_A(s_rgchINT, CSTR));
  26. return(s_rgchINT);
  27. }
  28. PCSTR GetINT_PTRString(INT_PTR n)
  29. {
  30. static char s_rgchINT[] = "-2147483646xxxxxxxxxx";
  31. wsprintfA(s_rgchINT, "%Id", n);
  32. ASSERT(IS_VALID_STRING_PTR_A(s_rgchINT, CSTR));
  33. return(s_rgchINT);
  34. }
  35. PCSTR GetULONGString(ULONG ul)
  36. {
  37. static char s_rgchULONG[] = "4294967295";
  38. wsprintfA(s_rgchULONG, "%lx", ul);
  39. ASSERT(IS_VALID_STRING_PTR_A(s_rgchULONG, CSTR));
  40. return(s_rgchULONG);
  41. }
  42. PCSTR GetBOOLString(BOOL bResult)
  43. {
  44. PCSTR pcsz;
  45. pcsz = bResult ? "TRUE" : "FALSE";
  46. ASSERT(IS_VALID_STRING_PTR_A(pcsz, CSTR));
  47. return(pcsz);
  48. }
  49. PCSTR GetPVOIDString(PVOID ptr)
  50. {
  51. static char s_rgchPVOID[] = "0xffff0000ffff0000";
  52. wsprintfA(s_rgchPVOID, "0x%p", ptr);
  53. ASSERT(IS_VALID_STRING_PTR_A(s_rgchPVOID, CSTR));
  54. return(s_rgchPVOID);
  55. }
  56. PCSTR GetClipboardFormatNameString(UINT ucf)
  57. {
  58. PCSTR pcsz;
  59. static char s_szCFName[MAX_PATH];
  60. switch (ucf)
  61. {
  62. STRING_CASE(CF_TEXT);
  63. STRING_CASE(CF_BITMAP);
  64. STRING_CASE(CF_METAFILEPICT);
  65. STRING_CASE(CF_SYLK);
  66. STRING_CASE(CF_DIF);
  67. STRING_CASE(CF_TIFF);
  68. STRING_CASE(CF_OEMTEXT);
  69. STRING_CASE(CF_DIB);
  70. STRING_CASE(CF_PALETTE);
  71. STRING_CASE(CF_PENDATA);
  72. STRING_CASE(CF_RIFF);
  73. STRING_CASE(CF_WAVE);
  74. STRING_CASE(CF_UNICODETEXT);
  75. STRING_CASE(CF_ENHMETAFILE);
  76. STRING_CASE(CF_HDROP);
  77. STRING_CASE(CF_LOCALE);
  78. STRING_CASE(CF_MAX);
  79. STRING_CASE(CF_OWNERDISPLAY);
  80. STRING_CASE(CF_DSPTEXT);
  81. STRING_CASE(CF_DSPBITMAP);
  82. STRING_CASE(CF_DSPMETAFILEPICT);
  83. STRING_CASE(CF_DSPENHMETAFILE);
  84. default:
  85. if (! GetClipboardFormatNameA(ucf, s_szCFName, sizeof(s_szCFName)))
  86. lstrcpyA(s_szCFName, "UNKNOWN CLIPBOARD FORMAT");
  87. pcsz = s_szCFName;
  88. break;
  89. }
  90. ASSERT(IS_VALID_STRING_PTR_A(pcsz, CSTR));
  91. return(pcsz);
  92. }
  93. PCSTR GetCOMPARISONRESULTString(COMPARISONRESULT cr)
  94. {
  95. PCSTR pcsz;
  96. switch (cr)
  97. {
  98. STRING_CASE(CR_FIRST_SMALLER);
  99. STRING_CASE(CR_FIRST_LARGER);
  100. STRING_CASE(CR_EQUAL);
  101. default:
  102. ERROR_OUT(("GetCOMPARISONRESULTString() called on unknown COMPARISONRESULT %d.",
  103. cr));
  104. pcsz = "UNKNOWN COMPARISONRESULT";
  105. break;
  106. }
  107. ASSERT(IS_VALID_STRING_PTR_A(pcsz, CSTR));
  108. return(pcsz);
  109. }
  110. PCSTR GetHRESULTString(HRESULT hr)
  111. {
  112. PCSTR pcsz;
  113. static char s_rgchHRESULT[] = "0x12345678";
  114. switch (hr)
  115. {
  116. STRING_CASE(S_OK);
  117. STRING_CASE(S_FALSE);
  118. STRING_CASE(DRAGDROP_S_CANCEL);
  119. STRING_CASE(DRAGDROP_S_DROP);
  120. STRING_CASE(DRAGDROP_S_USEDEFAULTCURSORS);
  121. STRING_CASE(E_UNEXPECTED);
  122. STRING_CASE(E_NOTIMPL);
  123. STRING_CASE(E_OUTOFMEMORY);
  124. STRING_CASE(E_INVALIDARG);
  125. STRING_CASE(E_NOINTERFACE);
  126. STRING_CASE(E_POINTER);
  127. STRING_CASE(E_HANDLE);
  128. STRING_CASE(E_ABORT);
  129. STRING_CASE(E_FAIL);
  130. STRING_CASE(E_ACCESSDENIED);
  131. STRING_CASE(CLASS_E_NOAGGREGATION);
  132. STRING_CASE(CO_E_NOTINITIALIZED);
  133. STRING_CASE(CO_E_ALREADYINITIALIZED);
  134. STRING_CASE(CO_E_INIT_ONLY_SINGLE_THREADED);
  135. STRING_CASE(DV_E_DVASPECT);
  136. STRING_CASE(DV_E_LINDEX);
  137. STRING_CASE(DV_E_TYMED);
  138. STRING_CASE(DV_E_FORMATETC);
  139. #ifdef __INTSHCUT_H__
  140. STRING_CASE(E_FLAGS);
  141. STRING_CASE(URL_E_INVALID_SYNTAX);
  142. STRING_CASE(URL_E_UNREGISTERED_PROTOCOL);
  143. STRING_CASE(IS_E_EXEC_FAILED);
  144. STRING_CASE(E_FILE_NOT_FOUND);
  145. STRING_CASE(E_PATH_NOT_FOUND);
  146. #endif
  147. // ULS error codes
  148. //
  149. default:
  150. wsprintfA(s_rgchHRESULT, "%#lx", hr);
  151. pcsz = s_rgchHRESULT;
  152. break;
  153. }
  154. ASSERT(IS_VALID_STRING_PTR_A(pcsz, CSTR));
  155. return(pcsz);
  156. }
  157. #endif /* DEBUG */