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.

170 lines
4.1 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Implementation of CAudioVBScriptEngine.
  4. //
  5. #include "stdinc.h"
  6. #include "dll.h"
  7. #include "engine.h"
  8. #include "englex.h" // ��
  9. #include "engparse.h" // ��
  10. //////////////////////////////////////////////////////////////////////
  11. // Creation
  12. CAudioVBScriptEngine::CAudioVBScriptEngine()
  13. : m_cRef(0)
  14. {
  15. LockModule(true);
  16. }
  17. HRESULT
  18. CAudioVBScriptEngine::CreateInstance(IUnknown* pUnknownOuter, const IID& iid, void** ppv)
  19. {
  20. *ppv = NULL;
  21. if (pUnknownOuter)
  22. return CLASS_E_NOAGGREGATION;
  23. CAudioVBScriptEngine *pInst = new CAudioVBScriptEngine;
  24. if (pInst == NULL)
  25. return E_OUTOFMEMORY;
  26. return pInst->QueryInterface(iid, ppv);
  27. }
  28. //////////////////////////////////////////////////////////////////////
  29. // IUnknown
  30. STDMETHODIMP
  31. CAudioVBScriptEngine::QueryInterface(const IID &iid, void **ppv)
  32. {
  33. V_INAME(CAudioVBScriptEngine::QueryInterface);
  34. V_PTRPTR_WRITE(ppv);
  35. V_REFGUID(iid);
  36. if (iid == IID_IUnknown || iid == IID_IActiveScript)
  37. {
  38. *ppv = static_cast<IActiveScript*>(this);
  39. }
  40. else if (iid == IID_IActiveScriptParse)
  41. {
  42. *ppv = static_cast<IActiveScriptParse*>(this);
  43. }
  44. else
  45. {
  46. *ppv = NULL;
  47. return E_NOINTERFACE;
  48. }
  49. reinterpret_cast<IUnknown*>(this)->AddRef();
  50. return S_OK;
  51. }
  52. STDMETHODIMP_(ULONG)
  53. CAudioVBScriptEngine::AddRef()
  54. {
  55. return InterlockedIncrement(&m_cRef);
  56. }
  57. STDMETHODIMP_(ULONG)
  58. CAudioVBScriptEngine::Release()
  59. {
  60. if (!InterlockedDecrement(&m_cRef))
  61. {
  62. delete this;
  63. LockModule(false);
  64. return 0;
  65. }
  66. return m_cRef;
  67. }
  68. //////////////////////////////////////////////////////////////////////
  69. // IActiveScript
  70. HRESULT STDMETHODCALLTYPE
  71. CAudioVBScriptEngine::SetScriptSite(
  72. /* [in] */ IActiveScriptSite __RPC_FAR *pass)
  73. {
  74. V_INAME(CAudioVBScriptEngine::SetScriptSite);
  75. V_INTERFACE(pass);
  76. m_scomActiveScriptSite = pass;
  77. pass->AddRef();
  78. return S_OK;
  79. }
  80. HRESULT STDMETHODCALLTYPE
  81. CAudioVBScriptEngine::Close(void)
  82. {
  83. m_scomActiveScriptSite.Release();
  84. m_scomEngineDispatch.Release();
  85. return S_OK;
  86. }
  87. HRESULT STDMETHODCALLTYPE
  88. CAudioVBScriptEngine::AddNamedItem(
  89. /* [in] */ LPCOLESTR pstrName,
  90. /* [in] */ DWORD dwFlags)
  91. {
  92. // We only provide limited support for named items. We only take a single global item. We don't even remember its name.
  93. if (!m_scomActiveScriptSite || !(dwFlags & SCRIPTITEM_GLOBALMEMBERS) || m_scomGlobalDispatch)
  94. return E_UNEXPECTED;
  95. IUnknown *punkGlobal = NULL;
  96. HRESULT hr = m_scomActiveScriptSite->GetItemInfo(pstrName, SCRIPTINFO_IUNKNOWN, &punkGlobal, NULL);
  97. if (FAILED(hr))
  98. return hr;
  99. hr = punkGlobal->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(&m_scomGlobalDispatch));
  100. punkGlobal->Release();
  101. return hr;
  102. }
  103. HRESULT STDMETHODCALLTYPE
  104. CAudioVBScriptEngine::GetScriptDispatch(
  105. /* [in] */ LPCOLESTR pstrItemName,
  106. /* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppdisp)
  107. {
  108. V_INAME(CAudioVBScriptEngine::GetScriptDispatch);
  109. V_BUFPTR_READ_OPT(pstrItemName, 2);
  110. V_PTR_WRITE(ppdisp, IDispatch *);
  111. if (pstrItemName)
  112. return E_NOTIMPL;
  113. if (!m_scomEngineDispatch)
  114. m_scomEngineDispatch = new EngineDispatch(static_cast<IActiveScript*>(this), m_script, m_scomGlobalDispatch);
  115. if (!m_scomEngineDispatch)
  116. return E_OUTOFMEMORY;
  117. return m_scomEngineDispatch->QueryInterface(IID_IDispatch, reinterpret_cast<void**>(ppdisp));
  118. }
  119. //////////////////////////////////////////////////////////////////////
  120. // IActiveScriptParse
  121. HRESULT STDMETHODCALLTYPE
  122. CAudioVBScriptEngine::ParseScriptText(
  123. /* [in] */ LPCOLESTR pstrCode,
  124. /* [in] */ LPCOLESTR pstrItemName,
  125. /* [in] */ IUnknown __RPC_FAR *punkContext,
  126. /* [in] */ LPCOLESTR pstrDelimiter,
  127. /* [in] */ DWORD_PTR dwSourceContextCookie,
  128. /* [in] */ ULONG ulStartingLineNumber,
  129. /* [in] */ DWORD dwFlags,
  130. /* [out] */ VARIANT __RPC_FAR *pvarResult,
  131. /* [out] */ EXCEPINFO __RPC_FAR *pexcepinfo)
  132. {
  133. V_INAME(CAudioVBScriptEngine::ParseScriptText);
  134. V_BUFPTR_READ(pstrCode, 2);
  135. if (pstrItemName || pstrDelimiter || ulStartingLineNumber != 0 || dwFlags != 0 || pvarResult)
  136. return E_UNEXPECTED;
  137. Lexer lexer(pstrCode);
  138. Parser p(lexer, m_script, m_scomActiveScriptSite, m_scomGlobalDispatch);
  139. return p.hr();
  140. }