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.

126 lines
2.3 KiB

  1. #include "StdAfx.h"
  2. #import <MsPwdMig.tlb> no_namespace implementation_only
  3. #import <ADMTScript.tlb> no_namespace implementation_only
  4. // ThrowError Methods -----------------------------------------------
  5. namespace
  6. {
  7. void __stdcall ThrowErrorImpl(const _com_error& ce, LPCTSTR pszDescription)
  8. {
  9. _bstr_t bstrNewDescription;
  10. try
  11. {
  12. bstrNewDescription = pszDescription;
  13. _bstr_t bstrSource = ce.Source();
  14. if (bstrSource.length() > 0)
  15. {
  16. if (bstrNewDescription.length() > 0)
  17. {
  18. bstrNewDescription += _T(" : ");
  19. }
  20. bstrNewDescription += bstrSource;
  21. }
  22. _bstr_t bstrOldDescription = ce.Description();
  23. if (bstrOldDescription.length() > 0)
  24. {
  25. if (bstrNewDescription.length() > 0)
  26. {
  27. if (bstrSource.length() > 0)
  28. {
  29. bstrNewDescription += _T(": ");
  30. }
  31. else
  32. {
  33. bstrNewDescription += _T(" ");
  34. }
  35. }
  36. bstrNewDescription += bstrOldDescription;
  37. }
  38. // else
  39. // {
  40. // LPCTSTR pszErrorMessage = ce.ErrorMessage();
  41. // if (pszErrorMessage)
  42. // {
  43. // if (bstrNewDescription.length() > 0)
  44. // {
  45. // bstrNewDescription += _T(" : ");
  46. // }
  47. // bstrNewDescription += pszErrorMessage;
  48. // }
  49. // }
  50. }
  51. catch (...)
  52. {
  53. ;
  54. }
  55. ICreateErrorInfoPtr spCreateErrorInfo;
  56. CreateErrorInfo(&spCreateErrorInfo);
  57. if (spCreateErrorInfo)
  58. {
  59. spCreateErrorInfo->SetSource(L"");
  60. spCreateErrorInfo->SetGUID(GUID_NULL);
  61. spCreateErrorInfo->SetDescription(bstrNewDescription);
  62. spCreateErrorInfo->SetHelpFile(L"");
  63. spCreateErrorInfo->SetHelpContext(0);
  64. }
  65. _com_raise_error(ce.Error(), IErrorInfoPtr(spCreateErrorInfo).Detach());
  66. }
  67. }
  68. void __cdecl ThrowError(_com_error ce, LPCTSTR pszFormat, ...)
  69. {
  70. _TCHAR szDescription[1024];
  71. if (pszFormat)
  72. {
  73. va_list args;
  74. va_start(args, pszFormat);
  75. _vsntprintf(szDescription, countof(szDescription), pszFormat, args);
  76. va_end(args);
  77. }
  78. else
  79. {
  80. szDescription[0] = _T('\0');
  81. }
  82. ThrowErrorImpl(ce, szDescription);
  83. }
  84. void __cdecl ThrowError(_com_error ce, UINT uId, ...)
  85. {
  86. _TCHAR szFormat[512];
  87. _TCHAR szDescription[1024];
  88. if (LoadString(GetModuleHandle(NULL), uId, szFormat, countof(szFormat)) > 0)
  89. {
  90. va_list args;
  91. va_start(args, uId);
  92. _vsntprintf(szDescription, countof(szDescription), szFormat, args);
  93. va_end(args);
  94. }
  95. else
  96. {
  97. szDescription[0] = _T('\0');
  98. }
  99. ThrowErrorImpl(ce, szDescription);
  100. }