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.

142 lines
3.3 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. dispatch.cpp
  5. Abstract:
  6. <abstract>
  7. --*/
  8. #include "polyline.h"
  9. #include "unkhlpr.h"
  10. extern ITypeLib *g_pITypeLib;
  11. extern DWORD g_dwScriptPolicy;
  12. //IDispatch interface implementation
  13. IMPLEMENT_CONTAINED_INTERFACE(IUnknown, CImpIDispatch)
  14. /*
  15. * CImpIDispatch::GetTypeInfoCount
  16. * CImpIDispatch::GetTypeInfo
  17. * CImpIDispatch::GetIDsOfNames
  18. *
  19. * The usual
  20. */
  21. void CImpIDispatch::SetInterface(REFIID riid, LPUNKNOWN pIUnk)
  22. {
  23. m_DIID = riid;
  24. m_pInterface = pIUnk;
  25. }
  26. STDMETHODIMP CImpIDispatch::GetTypeInfoCount(UINT *pctInfo)
  27. {
  28. //We implement GetTypeInfo so return 1
  29. *pctInfo=1;
  30. return NOERROR;
  31. }
  32. STDMETHODIMP CImpIDispatch::GetTypeInfo(UINT itInfo, LCID /* lcid */
  33. , ITypeInfo **ppITypeInfo)
  34. {
  35. if (0!=itInfo)
  36. return ResultFromScode(TYPE_E_ELEMENTNOTFOUND);
  37. if (NULL==ppITypeInfo)
  38. return ResultFromScode(E_POINTER);
  39. *ppITypeInfo=NULL;
  40. //We ignore the LCID
  41. return g_pITypeLib->GetTypeInfoOfGuid(m_DIID, ppITypeInfo);
  42. }
  43. STDMETHODIMP CImpIDispatch::GetIDsOfNames(REFIID riid
  44. , OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID *rgDispID)
  45. {
  46. HRESULT hr;
  47. ITypeInfo *pTI;
  48. if (IID_NULL!=riid)
  49. return ResultFromScode(DISP_E_UNKNOWNINTERFACE);
  50. hr=GetTypeInfo(0, lcid, &pTI);
  51. if (SUCCEEDED(hr))
  52. {
  53. hr = DispGetIDsOfNames(pTI, rgszNames, cNames, rgDispID);
  54. pTI->Release();
  55. }
  56. return hr;
  57. }
  58. /*
  59. * CImpIDispatch::Invoke
  60. *
  61. * Purpose:
  62. * Calls a method in the dispatch interface or manipulates a
  63. * property.
  64. *
  65. * Parameters:
  66. * dispID DISPID of the method or property of interest.
  67. * riid REFIID reserved, must be IID_NULL.
  68. * lcid LCID of the locale.
  69. * wFlags USHORT describing the context of the invocation.
  70. * pDispParams DISPPARAMS * to the array of arguments.
  71. * pVarResult VARIANT * in which to store the result. Is
  72. * NULL if the caller is not interested.
  73. * pExcepInfo EXCEPINFO * to exception information.
  74. * puArgErr UINT * in which to store the index of an
  75. * invalid parameter if DISP_E_TYPEMISMATCH
  76. * is returned.
  77. *
  78. * Return Value:
  79. * HRESULT NOERROR or a general error code.
  80. */
  81. STDMETHODIMP CImpIDispatch::Invoke(DISPID dispID, REFIID riid
  82. , LCID lcid, unsigned short wFlags, DISPPARAMS *pDispParams
  83. , VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
  84. {
  85. HRESULT hr;
  86. ITypeInfo *pTI;
  87. //riid is supposed to be IID_NULL always
  88. if (IID_NULL != riid)
  89. return ResultFromScode(DISP_E_UNKNOWNINTERFACE);
  90. if (g_dwScriptPolicy == URLPOLICY_DISALLOW) {
  91. if (m_DIID == DIID_DISystemMonitor)
  92. return E_ACCESSDENIED;
  93. }
  94. // if dispatching to the graph control, use our internal interface
  95. // that is generated from the direct interface (see smonctrl.odl)
  96. if (m_DIID == DIID_DISystemMonitor)
  97. hr = g_pITypeLib->GetTypeInfoOfGuid(DIID_DISystemMonitorInternal, &pTI);
  98. else
  99. hr = GetTypeInfo(0, lcid, &pTI);
  100. if (FAILED(hr))
  101. return hr;
  102. hr = pTI->Invoke(m_pInterface, dispID, wFlags
  103. , pDispParams, pVarResult, pExcepInfo, puArgErr);
  104. pTI->Release();
  105. return hr;
  106. }