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.

202 lines
4.2 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. HRESULT hr = S_OK;
  29. if (pctInfo == NULL) {
  30. return E_POINTER;
  31. }
  32. //
  33. //We implement GetTypeInfo so return 1
  34. //
  35. try {
  36. *pctInfo = 1;
  37. } catch (...) {
  38. hr = E_POINTER;
  39. }
  40. return S_OK;
  41. }
  42. STDMETHODIMP CImpIDispatch::GetTypeInfo(
  43. UINT itInfo,
  44. LCID,/* lcid */
  45. ITypeInfo **ppITypeInfo
  46. )
  47. {
  48. HRESULT hr = S_OK;
  49. if (0 != itInfo) {
  50. return TYPE_E_ELEMENTNOTFOUND;
  51. }
  52. if (NULL == ppITypeInfo) {
  53. return E_POINTER;
  54. }
  55. try {
  56. *ppITypeInfo=NULL;
  57. //
  58. //We ignore the LCID
  59. //
  60. hr = g_pITypeLib->GetTypeInfoOfGuid(m_DIID, ppITypeInfo);
  61. } catch (...) {
  62. hr = E_POINTER;
  63. }
  64. return hr;
  65. }
  66. STDMETHODIMP CImpIDispatch::GetIDsOfNames(
  67. REFIID riid,
  68. OLECHAR **rgszNames,
  69. UINT cNames,
  70. LCID lcid,
  71. DISPID *rgDispID
  72. )
  73. {
  74. HRESULT hr = S_OK;
  75. ITypeInfo *pTI = NULL;
  76. if (IID_NULL != riid) {
  77. return DISP_E_UNKNOWNINTERFACE;
  78. }
  79. hr = GetTypeInfo(0, lcid, &pTI);
  80. if (SUCCEEDED(hr))
  81. {
  82. try {
  83. hr = DispGetIDsOfNames(pTI, rgszNames, cNames, rgDispID);
  84. } catch (...) {
  85. hr = E_POINTER;
  86. }
  87. }
  88. if (pTI) {
  89. pTI->Release();
  90. }
  91. return hr;
  92. }
  93. /*
  94. * CImpIDispatch::Invoke
  95. *
  96. * Purpose:
  97. * Calls a method in the dispatch interface or manipulates a
  98. * property.
  99. *
  100. * Parameters:
  101. * dispID DISPID of the method or property of interest.
  102. * riid REFIID reserved, must be IID_NULL.
  103. * lcid LCID of the locale.
  104. * wFlags USHORT describing the context of the invocation.
  105. * pDispParams DISPPARAMS * to the array of arguments.
  106. * pVarResult VARIANT * in which to store the result. Is
  107. * NULL if the caller is not interested.
  108. * pExcepInfo EXCEPINFO * to exception information.
  109. * puArgErr UINT * in which to store the index of an
  110. * invalid parameter if DISP_E_TYPEMISMATCH
  111. * is returned.
  112. *
  113. * Return Value:
  114. * HRESULT NOERROR or a general error code.
  115. */
  116. STDMETHODIMP CImpIDispatch::Invoke(
  117. DISPID dispID,
  118. REFIID riid,
  119. LCID lcid,
  120. unsigned short wFlags,
  121. DISPPARAMS *pDispParams,
  122. VARIANT *pVarResult,
  123. EXCEPINFO *pExcepInfo,
  124. UINT *puArgErr
  125. )
  126. {
  127. HRESULT hr = S_OK;
  128. ITypeInfo *pTI = NULL;
  129. //riid is supposed to be IID_NULL always
  130. if (IID_NULL != riid) {
  131. return DISP_E_UNKNOWNINTERFACE;
  132. }
  133. if (g_dwScriptPolicy == URLPOLICY_DISALLOW) {
  134. if (m_DIID == DIID_DISystemMonitor)
  135. return E_ACCESSDENIED;
  136. }
  137. // if dispatching to the graph control, use our internal interface
  138. // that is generated from the direct interface (see smonctrl.odl)
  139. if (m_DIID == DIID_DISystemMonitor) {
  140. hr = g_pITypeLib->GetTypeInfoOfGuid(DIID_DISystemMonitorInternal, &pTI);
  141. }
  142. else {
  143. hr = GetTypeInfo(0, lcid, &pTI);
  144. }
  145. if (SUCCEEDED(hr)) {
  146. try {
  147. hr = pTI->Invoke(m_pInterface,
  148. dispID,
  149. wFlags,
  150. pDispParams,
  151. pVarResult,
  152. pExcepInfo,
  153. puArgErr);
  154. } catch (...) {
  155. hr = E_POINTER;
  156. }
  157. if (pTI) {
  158. pTI->Release();
  159. }
  160. }
  161. return hr;
  162. }