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.

95 lines
2.6 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Implementation of CActiveScriptError.
  4. //
  5. #include "stdinc.h"
  6. #include "enginc.h"
  7. #include "engerror.h"
  8. #include "oleaut.h"
  9. CActiveScriptError::CActiveScriptError(HRESULT hr, Lexer &lexer, const char *pszDescription)
  10. : m_scode(hr),
  11. m_wstrDescription(pszDescription),
  12. m_pwszSource(NULL),
  13. m_ulLineNumber(lexer.line() - 1), // line is reported zero-based from IActiveScriptError
  14. m_lCharacterPosition(lexer.column() - 1) // character position is reported zero-based from IActiveScriptError
  15. {
  16. assert(pszDescription && lexer.line() > 0 && lexer.column() > 0);
  17. // build the near text from the lexer's current position to the end of the line
  18. for (const WCHAR *pwsz = lexer.m_p; *pwsz && *pwsz != '\n' && *pwsz != '\r'; ++pwsz)
  19. {}
  20. m_wstrSourceLine.Assign(lexer.m_p, pwsz - lexer.m_p);
  21. // fill in the source text based on hresult
  22. if (hr == DMUS_E_AUDIOVBSCRIPT_SYNTAXERROR)
  23. {
  24. m_pwszSource = L"Microsoft AudioVBScript syntax error";
  25. }
  26. else if (hr == DMUS_E_AUDIOVBSCRIPT_RUNTIMEERROR)
  27. {
  28. m_pwszSource = L"Microsoft AudioVBScript runtime error";
  29. }
  30. else
  31. {
  32. assert(hr == DMUS_E_AUDIOVBSCRIPT_OPERATIONFAILURE);
  33. m_pwszSource = L"Microsoft AudioVBScript operation failure";
  34. }
  35. }
  36. STDMETHODIMP
  37. CActiveScriptError::GetExceptionInfo(
  38. /* [out] */ EXCEPINFO *pexcepinfo)
  39. {
  40. V_INAME(CActiveScriptError::GetExceptionInfo);
  41. V_PTR_WRITE(pexcepinfo, *pexcepinfo);
  42. Zero(pexcepinfo);
  43. pexcepinfo->scode = m_scode;
  44. if (m_wstrDescription)
  45. pexcepinfo->bstrDescription = DMS_SysAllocString(g_fUseOleAut, m_wstrDescription);
  46. if (!pexcepinfo->bstrDescription)
  47. return E_OUTOFMEMORY;
  48. pexcepinfo->bstrSource = DMS_SysAllocString(g_fUseOleAut, m_pwszSource);
  49. if (!pexcepinfo->bstrSource)
  50. return E_OUTOFMEMORY;
  51. return S_OK;
  52. }
  53. STDMETHODIMP
  54. CActiveScriptError::GetSourcePosition(
  55. /* [out] */ DWORD *pdwSourceContext,
  56. /* [out] */ ULONG *pulLineNumber,
  57. /* [out] */ LONG *plCharacterPosition)
  58. {
  59. V_INAME(CActiveScriptError::GetSourcePosition);
  60. V_PTR_WRITE_OPT(pdwSourceContext, *pdwSourceContext);
  61. V_PTR_WRITE(pulLineNumber, *pulLineNumber);
  62. V_PTR_WRITE(plCharacterPosition, *plCharacterPosition);
  63. assert(!pdwSourceContext);
  64. *pulLineNumber = m_ulLineNumber;
  65. *plCharacterPosition = m_lCharacterPosition;
  66. return S_OK;
  67. }
  68. STDMETHODIMP
  69. CActiveScriptError::GetSourceLineText(
  70. /* [out] */ BSTR *pbstrSourceLine)
  71. {
  72. V_INAME(CActiveScriptError::GetSourceLineText);
  73. V_PTR_WRITE(pbstrSourceLine, *pbstrSourceLine);
  74. *pbstrSourceLine = NULL;
  75. if (m_wstrSourceLine)
  76. *pbstrSourceLine = DMS_SysAllocString(g_fUseOleAut, m_wstrSourceLine);
  77. if (!*pbstrSourceLine)
  78. return E_OUTOFMEMORY;
  79. return S_OK;
  80. }