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.

135 lines
3.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: derror.cxx
  7. //
  8. // Contents: Ole NTSD extension routines to display the error
  9. // message for a Win32 or OLE error code
  10. //
  11. // Functions: displayVtbl
  12. //
  13. //
  14. // History: 06-01-95 BruceMa Created
  15. //
  16. //
  17. //--------------------------------------------------------------------------
  18. #include <ole2int.h>
  19. #include <windows.h>
  20. #include "ole.h"
  21. //+-------------------------------------------------------------------------
  22. //
  23. // Function: displayHr
  24. //
  25. // Synopsis: Display the mnesage for a Win32 error or OLE HRESULT
  26. //
  27. // Arguments: [hProcess] - Handle of this process
  28. // [lpExtensionApis] - Table of extension functions
  29. //
  30. // Returns: -
  31. //
  32. // History: 01-Jun-95 BruceMa Created
  33. //
  34. //--------------------------------------------------------------------------
  35. void displayHr (HANDLE hProcess,
  36. PNTSD_EXTENSION_APIS lpExtensionApis,
  37. char *arg)
  38. {
  39. DWORD err = 0;
  40. BOOL fHex = FALSE;
  41. // Determine if it's hex or decimal. Also allow '800xxxxx' to implicitly
  42. // be treated as hexadecimal
  43. if (arg[0] == '0' && (arg[1] == 'x' || arg[1] == 'X'))
  44. {
  45. fHex = TRUE;
  46. arg += 2;
  47. }
  48. else if (arg[0] == '8' && arg[1] == '0' && arg[2] == '0')
  49. {
  50. fHex = TRUE;
  51. }
  52. else
  53. {
  54. char *s = arg;
  55. while (*s)
  56. {
  57. if (('a' <= *s && *s <= 'f') || ('A' <= *s && *s <= 'F'))
  58. {
  59. fHex = TRUE;
  60. break;
  61. }
  62. s++;
  63. }
  64. }
  65. // Parse the error number
  66. if (fHex)
  67. {
  68. int k = 0;
  69. char c;
  70. while (c = arg[k++])
  71. {
  72. c = c - '0';
  73. if (c > 9)
  74. {
  75. if (c <= 'F' && c >= 'A')
  76. {
  77. c = c + '0' - 'A' + 10;
  78. }
  79. else
  80. {
  81. c = c + '0' - 'a' + 10;
  82. }
  83. }
  84. err = (16 * err) + c;
  85. }
  86. }
  87. else
  88. {
  89. int k = 0;
  90. char c;
  91. while (c = arg[k++])
  92. {
  93. c = c - '0';
  94. err = (10 * err) + c;
  95. }
  96. }
  97. // Fetch the associated error message
  98. int cbMsgLen;
  99. char szBuffer[512];
  100. cbMsgLen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
  101. FORMAT_MESSAGE_IGNORE_INSERTS,
  102. NULL,
  103. err,
  104. (DWORD) NULL,
  105. szBuffer,
  106. 511,
  107. NULL);
  108. // Output the message
  109. if (cbMsgLen == 0)
  110. {
  111. Printf("...No such error code\n");
  112. }
  113. else
  114. {
  115. szBuffer[cbMsgLen] = '\0';
  116. Printf("%s\n", szBuffer);
  117. }
  118. }