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
2.5 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. szDescription[countof(szDescription) - 1] = _T('\0');
  77. va_end(args);
  78. }
  79. else
  80. {
  81. szDescription[0] = _T('\0');
  82. }
  83. ThrowErrorImpl(ce, szDescription);
  84. }
  85. void __cdecl ThrowError(_com_error ce, UINT uId, ...)
  86. {
  87. _TCHAR szFormat[512];
  88. _TCHAR szDescription[1024];
  89. if (LoadString(GetModuleHandle(NULL), uId, szFormat, countof(szFormat)) > 0)
  90. {
  91. va_list args;
  92. va_start(args, uId);
  93. _vsntprintf(szDescription, countof(szDescription), szFormat, args);
  94. szDescription[countof(szDescription) - 1] = _T('\0');
  95. va_end(args);
  96. }
  97. else
  98. {
  99. szDescription[0] = _T('\0');
  100. }
  101. ThrowErrorImpl(ce, szDescription);
  102. }