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.

145 lines
5.7 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Declaration of CActiveScriptManager.
  4. //
  5. // CActiveScriptManager handles interfacing with VBScript or any activeX scripting
  6. // language. It intializes an IActiveScript object, sends it code, and sets and gets
  7. // the values of variables. Used by CDirectMusicScript.
  8. #pragma once
  9. #include "ole2.h"
  10. #include "activscp.h"
  11. #include "scriptthread.h"
  12. #include "..\shared\dmusicp.h"
  13. // forward declaration
  14. class CDirectMusicScript;
  15. // little helper class to cache routine and variable names for EnumItem
  16. class ScriptNames
  17. {
  18. public:
  19. ScriptNames() : m_prgbstr(NULL) {}
  20. ~ScriptNames() { Clear(); }
  21. HRESULT Init(bool fUseOleAut, DWORD cNames);
  22. operator bool() { return !!m_prgbstr; }
  23. DWORD size() { return m_dwSize; }
  24. void Clear();
  25. BSTR &operator[](DWORD dwIndex) { assert(m_prgbstr && dwIndex < m_dwSize); return m_prgbstr[dwIndex]; }
  26. private:
  27. bool m_fUseOleAut;
  28. DWORD m_dwSize;
  29. BSTR *m_prgbstr;
  30. };
  31. class CActiveScriptManager
  32. : public IActiveScriptSite,
  33. public ScriptManager
  34. {
  35. public:
  36. CActiveScriptManager(
  37. bool fUseOleAut,
  38. const WCHAR *pwszLanguage,
  39. const WCHAR *pwszSource,
  40. CDirectMusicScript *pParentScript,
  41. HRESULT *phr,
  42. DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  43. HRESULT Start(DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  44. HRESULT CallRoutine(const WCHAR *pwszRoutineName, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  45. HRESULT ScriptTrackCallRoutine(
  46. const WCHAR *pwszRoutineName,
  47. IDirectMusicSegmentState *pSegSt,
  48. DWORD dwVirtualTrackID,
  49. bool fErrorPMsgsEnabled,
  50. __int64 i64IntendedStartTime,
  51. DWORD dwIntendedStartTimeFlags);
  52. HRESULT SetVariable(const WCHAR *pwszVariableName, VARIANT varValue, bool fSetRef, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  53. HRESULT GetVariable(const WCHAR *pwszVariableName, VARIANT *pvarValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  54. HRESULT EnumItem(bool fRoutine, DWORD dwIndex, WCHAR *pwszName, int *pcItems);
  55. HRESULT DispGetIDsOfNames(REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames, LCID lcid, DISPID __RPC_FAR *rgDispId);
  56. HRESULT DispInvoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr);
  57. void Close(); // Releases all references in preparation for shutdown
  58. // IUnknown
  59. STDMETHOD(QueryInterface)(const IID &iid, void **ppv);
  60. STDMETHOD_(ULONG, AddRef)();
  61. STDMETHOD_(ULONG, Release)();
  62. // IActiveScriptSite
  63. STDMETHOD(GetLCID)(/* [out] */ LCID __RPC_FAR *plcid);
  64. STDMETHOD(GetItemInfo)(
  65. /* [in] */ LPCOLESTR pstrName,
  66. /* [in] */ DWORD dwReturnMask,
  67. /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppiunkItem,
  68. /* [out] */ ITypeInfo __RPC_FAR *__RPC_FAR *ppti);
  69. STDMETHOD(GetDocVersionString)(/* [out] */ BSTR __RPC_FAR *pbstrVersion);
  70. STDMETHOD(OnScriptTerminate)(
  71. /* [in] */ const VARIANT __RPC_FAR *pvarResult,
  72. /* [in] */ const EXCEPINFO __RPC_FAR *pexcepinfo);
  73. STDMETHOD(OnStateChange)(/* [in] */ SCRIPTSTATE ssScriptState);
  74. STDMETHOD(OnScriptError)(/* [in] */ IActiveScriptError __RPC_FAR *pscripterror);
  75. STDMETHOD(OnEnterScript)();
  76. STDMETHOD(OnLeaveScript)();
  77. // Retrieve context for the currently running script.
  78. // Some automation model functions need access to the context from which the
  79. // currently running routine was called. For example, they may need to operate
  80. // on the implied global performance.
  81. // Be sure to addref the returned pointer if holding onto it.
  82. static IDirectMusicPerformance8 *GetCurrentPerformanceNoAssertWEAK();
  83. static IDirectMusicPerformance8 *GetCurrentPerformanceWEAK() { IDirectMusicPerformance8 *pPerf = CActiveScriptManager::GetCurrentPerformanceNoAssertWEAK(); if (!pPerf) {assert(false);} return pPerf; }
  84. static IDirectMusicObject *GetCurrentScriptObjectWEAK();
  85. static IDirectMusicComposer8 *GetComposerWEAK();
  86. static void GetCurrentTimingContext(__int64 *pi64IntendedStartTime, DWORD *pdwIntendedStartTimeFlags);
  87. private:
  88. // Functions
  89. HRESULT GetIDOfName(const WCHAR *pwszName, DISPID *pdispid); // returns S_FALSE for unknown name
  90. void ClearErrorInfo();
  91. void SetErrorInfo(ULONG ulLineNumber, LONG ichCharPosition, BSTR bstrSourceLine, const EXCEPINFO &excepinfo);
  92. void ContributeErrorInfo(const WCHAR *pwszActivity, const WCHAR *pwszSubject, const EXCEPINFO &excepinfo);
  93. HRESULT ReturnErrorInfo(HRESULT hr, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  94. static CActiveScriptManager *GetCurrentContext();
  95. static HRESULT SetCurrentContext(CActiveScriptManager *pActiveScriptManager, CActiveScriptManager **ppActiveScriptManagerPrevious); // remember to restore the previous pointer after the call
  96. HRESULT EnsureEnumItemsCached(bool fRoutine);
  97. // Data
  98. long m_cRef;
  99. // Pointer back to the containing script object
  100. CDirectMusicScript *m_pParentScript;
  101. // Active Scripting
  102. bool m_fUseOleAut;
  103. IActiveScript *m_pActiveScript;
  104. IDispatch *m_pDispatchScript;
  105. // Errors (managed via ClearErrorInfo, SetErrorInfo, and ContributeErrorInfo)
  106. bool m_fError;
  107. HRESULT m_hrError;
  108. ULONG m_ulErrorLineNumber;
  109. LONG m_ichErrorCharPosition;
  110. BSTR m_bstrErrorSourceComponent;
  111. BSTR m_bstrErrorDescription;
  112. BSTR m_bstrErrorSourceLineText;
  113. BSTR m_bstrHelpFile;
  114. // Context
  115. struct ThreadContextPair
  116. {
  117. DWORD dwThreadId;
  118. CActiveScriptManager *pActiveScriptManager;
  119. };
  120. static SmartRef::Vector<ThreadContextPair> ms_svecContext;
  121. // Timing context for a routine call from a script track. (Sets the play/stop time of segments, songs, and playingsegments
  122. // to the time of the routine in the script track.)
  123. __int64 m_i64IntendedStartTime;
  124. DWORD m_dwIntendedStartTimeFlags;
  125. // cached names from enum methods
  126. ScriptNames m_snamesRoutines;
  127. ScriptNames m_snamesVariables;
  128. };