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.

123 lines
3.6 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. namespace UIErrors
  4. {
  5. /**************************************
  6. UIErrors::ReportResult
  7. Given an HRESULT, map it to a user friendly message (when possible).
  8. If we don't have a mapping, defer to FormatMessage (ugh!)
  9. This function should be a last resort.
  10. ***************************************/
  11. VOID
  12. ReportResult (HWND hwndParent, HINSTANCE hInst, HRESULT hr)
  13. {
  14. switch (hr)
  15. {
  16. case RPC_E_CALL_REJECTED:
  17. case RPC_E_RETRY:
  18. case RPC_E_TIMEOUT:
  19. ReportError (hwndParent, hInst, ErrStiBusy);
  20. break;
  21. case RPC_E_SERVER_DIED:
  22. case RPC_E_SERVER_DIED_DNE:
  23. case RPC_E_DISCONNECTED:
  24. ReportError (hwndParent, hInst, ErrStiCrashed);
  25. break;
  26. default:
  27. LPTSTR szErrMsg = NULL;
  28. FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
  29. NULL,
  30. hr,
  31. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  32. reinterpret_cast<LPTSTR>(&szErrMsg),
  33. 0,
  34. NULL
  35. );
  36. if (szErrMsg)
  37. {
  38. CSimpleString strTitle;
  39. strTitle.LoadString (IDS_ERRTITLE_HRESULT, hInst);
  40. ReportMessage (hwndParent, hInst, NULL, strTitle, szErrMsg);
  41. }
  42. else
  43. {
  44. ReportMessage (hwndParent, hInst, NULL, MAKEINTRESOURCE(IDS_ERRTITLE_UNKNOWNERR), MAKEINTRESOURCE(IDS_ERROR_UNKNOWNERR));
  45. }
  46. break;
  47. }
  48. }
  49. /**************************************
  50. UIErrors::ReportMessage
  51. These functions wrap MessageBoxIndirect to
  52. display given strings.
  53. ***************************************/
  54. VOID
  55. ReportMessage (HWND hwndParent,
  56. HINSTANCE hInst,
  57. LPCTSTR idIcon,
  58. LPCTSTR idTitle,
  59. LPCTSTR idMessage,
  60. DWORD dwStyle)
  61. {
  62. MSGBOXPARAMS mbp = {0};
  63. mbp.cbSize = sizeof(MSGBOXPARAMS);
  64. mbp.hwndOwner = hwndParent;
  65. mbp.hInstance = hInst;
  66. mbp.lpszText = idMessage;
  67. mbp.lpszCaption = idTitle;
  68. mbp.dwStyle = MB_OK | dwStyle;
  69. if (idIcon)
  70. {
  71. mbp.dwStyle |= MB_USERICON;
  72. mbp.lpszIcon = idIcon;
  73. }
  74. else
  75. {
  76. mbp.lpszIcon = NULL;
  77. }
  78. mbp.dwContextHelpId = 0;
  79. mbp.lpfnMsgBoxCallback = 0;
  80. mbp.dwLanguageId = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT);
  81. MessageBoxIndirect (&mbp);
  82. }
  83. // build an array of message ids indexed by the WiaError enum
  84. struct MsgMap
  85. {
  86. INT idTitle;
  87. INT idMessage;
  88. } ErrorCodes [] =
  89. {
  90. {IDS_ERRTITLE_DISCONNECTED, IDS_ERROR_DISCONNECTED},
  91. {IDS_ERRTITLE_COMMFAILURE, IDS_ERROR_COMMFAILURE},
  92. {IDS_ERRTITLE_STICRASH, IDS_ERROR_STICRASH},
  93. {IDS_ERRTITLE_STIBUSY, IDS_ERROR_STIBUSY},
  94. {IDS_ERRTITLE_SCANFAIL, IDS_ERROR_SCANFAIL},
  95. };
  96. VOID
  97. ReportError (HWND hwndParent,
  98. HINSTANCE hInst,
  99. WiaError err)
  100. {
  101. ReportMessage (hwndParent, hInst, NULL, MAKEINTRESOURCE(ErrorCodes[err].idTitle), MAKEINTRESOURCE(ErrorCodes[err].idMessage));
  102. }
  103. }