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.

132 lines
3.1 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. rtrerr.cpp
  7. FILE HISTORY:
  8. */
  9. #include "stdafx.h"
  10. #include "tfschar.h"
  11. #include "tfsres.h"
  12. #include "info.h"
  13. #include "errutil.h"
  14. #include "rtrerr.h"
  15. #include "mprapi.h"
  16. #include "mprerror.h"
  17. #include "raserror.h"
  18. #define IS_WIN32_HRESULT(x) (((x) & 0xFFFF0000) == 0x80070000)
  19. #define WIN32_FROM_HRESULT(hr) (0x0000FFFF & (hr))
  20. /*!--------------------------------------------------------------------------
  21. HandleIRemoteRouterConfigErrors
  22. -
  23. Author: KennT
  24. ---------------------------------------------------------------------------*/
  25. BOOL HandleIRemoteRouterConfigErrors(HRESULT hr, LPCTSTR pszMachineName)
  26. {
  27. BOOL fReturn = FALSE;
  28. if (FHrSucceeded(hr))
  29. return TRUE;
  30. if ((hr == REGDB_E_CLASSNOTREG) ||
  31. (hr == REGDB_E_IIDNOTREG))
  32. {
  33. CString st, stGeek;
  34. // This error indicates that we could not find the server
  35. // on the remote machine. This means that it could be a
  36. // down-level machine or the setup is messed up.
  37. AfxFormatString1(st, IDS_ERR_BAD_INTERFACE,
  38. pszMachineName);
  39. AfxFormatString1(stGeek, IDS_ERR_BAD_INTERFACE_GEEK,
  40. pszMachineName);
  41. AddStringErrorMessage2(hr, st, stGeek);
  42. fReturn = TRUE;
  43. }
  44. else if (hr == E_NOINTERFACE)
  45. {
  46. // These errors indicate that there was an installation
  47. // problem (this IID, probably rrasprxy.dll, should have
  48. // been registered).
  49. CString st, stGeek;
  50. AfxFormatString1(st, IDS_ERR_BAD_CLASSREG,
  51. pszMachineName);
  52. AfxFormatString1(stGeek, IDS_ERR_BAD_CLASSREG_GEEK,
  53. pszMachineName);
  54. AddStringErrorMessage2(hr, st, stGeek);
  55. fReturn = TRUE;
  56. }
  57. return fReturn;
  58. }
  59. HRESULT FormatRasError(HRESULT hr, TCHAR *pszBuffer, UINT cchBuffer)
  60. {
  61. HRESULT hrReturn = hrFalse;
  62. // Copy over default message into szBuffer
  63. _tcscpy(pszBuffer, _T("Error"));
  64. // Ok, we can't get the error info, so try to format it
  65. // using the FormatMessage
  66. // Ignore the return message, if this call fails then I don't
  67. // know what to do.
  68. if (IS_WIN32_HRESULT(hr))
  69. {
  70. DWORD dwErr;
  71. dwErr = WIN32_FROM_HRESULT(hr);
  72. if (((dwErr >= ROUTEBASE) && (dwErr <= ROUTEBASEEND)) ||
  73. ((dwErr >= RASBASE) && (dwErr <= RASBASEEND)))
  74. {
  75. WCHAR * pswzErr;
  76. if ( ::MprAdminGetErrorString(dwErr, &pswzErr) == NO_ERROR ) {
  77. StrnCpyTFromW(pszBuffer, pswzErr, cchBuffer);
  78. ::MprAdminBufferFree(pswzErr);
  79. hrReturn = hrOK;
  80. }
  81. }
  82. }
  83. if (!FHrOK(hrReturn))
  84. {
  85. // If we didn't get any error info, try again
  86. FormatError(hr, pszBuffer, cchBuffer);
  87. }
  88. return hrReturn;
  89. }
  90. void AddRasErrorMessage(HRESULT hr)
  91. {
  92. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  93. if (!FHrSucceeded(hr))
  94. {
  95. TCHAR szBuffer[4096];
  96. CString st, stHr;
  97. FormatRasError(hr, szBuffer, DimensionOf(szBuffer));
  98. stHr.Format(_T("%08lx"), hr);
  99. AfxFormatString2(st, IDS_ERROR_SYSTEM_ERROR_FORMAT,
  100. szBuffer, (LPCTSTR) stHr);
  101. FillTFSError(0, hr, FILLTFSERR_LOW, NULL, (LPCTSTR) st, NULL);
  102. }
  103. }