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.

131 lines
3.7 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Implements a script's global dispatch object.
  4. //
  5. #include "stdinc.h"
  6. #include "globaldisp.h"
  7. #include "autconstants.h"
  8. #include "autperformance.h"
  9. // We need to shift the DISPID's of the performance, constants, and contained
  10. // content so that they can be assembled into one range. The performance will be first,
  11. // followed by the others, which are shifted.
  12. const DISPID g_dispidShiftConstants = 1000;
  13. const DISPID g_dispidShiftContent = g_dispidShiftConstants + 1000;
  14. //////////////////////////////////////////////////////////////////////
  15. // IUnknown
  16. STDMETHODIMP
  17. CGlobalDispatch::QueryInterface(const IID &iid, void **ppv)
  18. {
  19. V_INAME(CGlobalDispatch::QueryInterface);
  20. V_PTRPTR_WRITE(ppv);
  21. V_REFGUID(iid);
  22. if (iid == IID_IUnknown || iid == IID_IDispatch)
  23. {
  24. *ppv = static_cast<IDispatch*>(this);
  25. }
  26. else
  27. {
  28. *ppv = NULL;
  29. return E_NOINTERFACE;
  30. }
  31. reinterpret_cast<IUnknown*>(this)->AddRef();
  32. return S_OK;
  33. }
  34. //////////////////////////////////////////////////////////////////////
  35. // IDispatch
  36. STDMETHODIMP
  37. CGlobalDispatch::GetTypeInfoCount(UINT *pctinfo)
  38. {
  39. V_INAME(CGlobalDispatch::GetTypeInfoCount);
  40. V_PTR_WRITE(pctinfo, UINT);
  41. *pctinfo = 0;
  42. return S_OK;
  43. }
  44. STDMETHODIMP
  45. CGlobalDispatch::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo __RPC_FAR *__RPC_FAR *ppTInfo)
  46. {
  47. *ppTInfo = NULL;
  48. return E_NOTIMPL;
  49. }
  50. STDMETHODIMP
  51. CGlobalDispatch::GetIDsOfNames(
  52. REFIID riid,
  53. LPOLESTR __RPC_FAR *rgszNames,
  54. UINT cNames,
  55. LCID lcid,
  56. DISPID __RPC_FAR *rgDispId)
  57. {
  58. HRESULT hr = S_OK;
  59. hr = AutConstantsGetIDsOfNames(riid, rgszNames, cNames, lcid, rgDispId);
  60. if (hr != DISP_E_UNKNOWNNAME)
  61. {
  62. if (SUCCEEDED(hr))
  63. rgDispId[0] += g_dispidShiftConstants;
  64. return hr;
  65. }
  66. // Try the performance next. Conceptually we're doing this:
  67. // hr = m_pParentScript->m_pDispPerformance->GetIDsOfNames(riid, rgszNames, cNames, lcid, rgDispId);
  68. // However, because AudioVBScript may try and resolve names during parsing (before a performance is set by Init),
  69. // we will won't use a live perfomance object for this. Instead we'll use the dispatch helper and the
  70. // performance's table to return the ID.
  71. hr = AutDispatchGetIDsOfNames(CAutDirectMusicPerformance::ms_Methods, riid, rgszNames, cNames, lcid, rgDispId);
  72. if (hr != DISP_E_UNKNOWNNAME)
  73. return hr;
  74. hr = m_pParentScript->m_pContainerDispatch->GetIDsOfNames(riid, rgszNames, cNames, lcid, rgDispId);
  75. if (SUCCEEDED(hr))
  76. rgDispId[0] += g_dispidShiftContent;
  77. return hr;
  78. }
  79. STDMETHODIMP
  80. CGlobalDispatch::Invoke(
  81. DISPID dispIdMember,
  82. REFIID riid,
  83. LCID lcid,
  84. WORD wFlags,
  85. DISPPARAMS __RPC_FAR *pDispParams,
  86. VARIANT __RPC_FAR *pVarResult,
  87. EXCEPINFO __RPC_FAR *pExcepInfo,
  88. UINT __RPC_FAR *puArgErr)
  89. {
  90. // If script functions are being called, it is an error if the script has not been
  91. // initialized with a performance.
  92. if (!m_pParentScript->m_pDispPerformance)
  93. {
  94. Trace(1, "Error: IDirectMusicScript::Init must be called before the script can be used.\n");
  95. return DMUS_E_NOT_INIT;
  96. }
  97. if (dispIdMember < g_dispidShiftConstants)
  98. {
  99. // Performance method
  100. return m_pParentScript->m_pDispPerformance->Invoke(dispIdMember, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
  101. }
  102. else if (dispIdMember < g_dispidShiftContent)
  103. {
  104. // Constants
  105. return AutConstantsInvoke(dispIdMember - g_dispidShiftConstants, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
  106. }
  107. else
  108. {
  109. // Contained content item
  110. return m_pParentScript->m_pContainerDispatch->Invoke(dispIdMember - g_dispidShiftContent, riid, lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
  111. }
  112. }