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.

128 lines
3.7 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1999 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: dverror.cpp
  6. * Content: Error string handling
  7. *
  8. * History:
  9. * Date By Reason
  10. * ==== == ======
  11. * 01/21/2000 pnewson Created
  12. * 04/19/2000 pnewson Error handling cleanup
  13. *
  14. ***************************************************************************/
  15. #include "dxvutilspch.h"
  16. #undef DPF_SUBCOMP
  17. #define DPF_SUBCOMP DN_SUBCOMP_VOICE
  18. #define MESSAGE_STRING_MAX_LEN 256
  19. #define MAX_ERROR_CODE_STRING_LEN 8
  20. static const TCHAR* g_tszDefaultMessage = _T("DirectPlay Voice has encountered an error\r\n(The error code was 0x%x)");
  21. static const TCHAR* g_tszDefaultMessageCaption = _T("Error");
  22. #undef DPF_MODNAME
  23. #define DPF_MODNAME "DV_DisplayDefaultErrorBox"
  24. void DV_DisplayDefaultErrorBox(HRESULT hr, HWND hwndParent)
  25. {
  26. DPFX(DPFPREP, DVF_ERRORLEVEL, "DV_DisplayDefaultErrorBox called");
  27. TCHAR tszMsgFmt[MESSAGE_STRING_MAX_LEN];
  28. if (_tcslen(g_tszDefaultMessage) + MAX_ERROR_CODE_STRING_LEN + 1 < MESSAGE_STRING_MAX_LEN)
  29. {
  30. _stprintf(tszMsgFmt, g_tszDefaultMessage, hr);
  31. }
  32. else
  33. {
  34. // Programmer mess up, DNASSERT if we're in debug, otherwise just
  35. // copy what we can of the default message over.
  36. DNASSERT(FALSE);
  37. _tcsncpy(tszMsgFmt, g_tszDefaultMessage, MESSAGE_STRING_MAX_LEN - 1);
  38. }
  39. MessageBox(hwndParent, tszMsgFmt, g_tszDefaultMessageCaption, MB_OK|MB_ICONERROR);
  40. return;
  41. }
  42. #undef DPF_MODNAME
  43. #define DPF_MODNAME "DV_DisplayErrorBox"
  44. void DV_DisplayErrorBox(HRESULT hr, HWND hwndParent, UINT idsErrorMessage)
  45. {
  46. DPFX(DPFPREP, DVF_ERRORLEVEL, "DV_DisplayErrorBox called");
  47. TCHAR tszMsg[MESSAGE_STRING_MAX_LEN];
  48. TCHAR tszMsgFmt[MESSAGE_STRING_MAX_LEN];
  49. TCHAR tszCaption[MESSAGE_STRING_MAX_LEN];
  50. #if !defined(DBG) || !defined( DIRECTX_REDIST )
  51. HINSTANCE hDPVoiceDll = LoadLibrary(_T("dpvoice.dll"));
  52. #else
  53. // For redist debug builds we append a 'd' to the name to allow both debug and retail to be installed on the system
  54. HINSTANCE hDPVoiceDll = LoadLibrary(_T("dpvoiced.dll"));
  55. #endif // !defined(DBG) || !defined( DIRECTX_REDIST )
  56. if (hDPVoiceDll == NULL)
  57. {
  58. // Very weird! go with a default message.
  59. DPFX(DPFPREP, DVF_ERRORLEVEL, "LoadLibrary(dpvoice.dll) failed - using default hardcoded message");
  60. DV_DisplayDefaultErrorBox(hr, hwndParent);
  61. return;
  62. }
  63. if (!LoadString(hDPVoiceDll, IDS_ERROR_CAPTION, tszCaption, MESSAGE_STRING_MAX_LEN))
  64. {
  65. DPFX(DPFPREP, DVF_ERRORLEVEL, "LoadString failed - using default hardcoded message");
  66. DV_DisplayDefaultErrorBox(hr, hwndParent);
  67. return;
  68. }
  69. if (idsErrorMessage == 0)
  70. {
  71. if (!LoadString(hDPVoiceDll, IDS_ERROR_MSG, tszMsg, MESSAGE_STRING_MAX_LEN))
  72. {
  73. DPFX(DPFPREP, DVF_ERRORLEVEL, "LoadString failed - using default hardcoded message");
  74. DV_DisplayDefaultErrorBox(hr, hwndParent);
  75. return;
  76. }
  77. if (_tcslen(tszMsg) + MAX_ERROR_CODE_STRING_LEN + 1 < MESSAGE_STRING_MAX_LEN)
  78. {
  79. _stprintf(tszMsgFmt, tszMsg, hr);
  80. }
  81. else
  82. {
  83. // Programmer mess up, DNASSERT if we're in debug, otherwise just
  84. // copy what we can of the default message over.
  85. DNASSERT(FALSE);
  86. _tcsncpy(tszMsgFmt, tszMsg, MESSAGE_STRING_MAX_LEN - 1);
  87. }
  88. }
  89. else
  90. {
  91. //passed a valid error string identifier. Try and pull string in
  92. if (!LoadString(hDPVoiceDll, idsErrorMessage, tszMsgFmt, MESSAGE_STRING_MAX_LEN))
  93. {
  94. DPFX(DPFPREP, DVF_ERRORLEVEL, "LoadString failed - using default hardcoded message");
  95. DV_DisplayDefaultErrorBox(hr, hwndParent);
  96. return;
  97. }
  98. }
  99. if (!IsWindow(hwndParent))
  100. {
  101. hwndParent = NULL;
  102. }
  103. MessageBox(hwndParent, tszMsgFmt, tszCaption, MB_OK|MB_ICONERROR);
  104. return;
  105. }