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.

276 lines
6.2 KiB

  1. //***************************************************************************
  2. //
  3. // cdisphlp.CPP
  4. //
  5. // Module: Client side of WBEM marshalling.
  6. //
  7. // Purpose: Defines dispatch helper object
  8. //
  9. // Copyright (c) 1998-1999 Microsoft Corporation
  10. //
  11. // a-davj 6-feb-97 Created.
  12. //
  13. //***************************************************************************
  14. #include "precomp.h"
  15. //***************************************************************************
  16. // CDispatchHelp::CDispatchHelp()
  17. // CDispatchHelp::~CDispatchHelp()
  18. //
  19. // Purpose: constructor and destructor
  20. //
  21. //***************************************************************************
  22. CDispatchHelp::CDispatchHelp()
  23. {
  24. m_pITINeutral = NULL; //Type information
  25. m_pCITINeutral = NULL;
  26. m_pObj = NULL;
  27. m_objectName = NULL;
  28. m_hResult = S_OK;
  29. }
  30. CDispatchHelp::~CDispatchHelp(void)
  31. {
  32. RELEASEANDNULL(m_pITINeutral)
  33. RELEASEANDNULL(m_pCITINeutral)
  34. SysFreeString (m_objectName);
  35. }
  36. void CDispatchHelp::SetObj(IDispatch * pObj, GUID iGuid,
  37. GUID cGuid, LPWSTR objectName)
  38. {
  39. m_pObj = pObj;
  40. m_iGUID = iGuid;
  41. m_cGUID = cGuid;
  42. m_objectName = SysAllocString (objectName);
  43. }
  44. SCODE CDispatchHelp::GetTypeInfoCount(UINT FAR* pctinfo)
  45. {
  46. //We implement GetTypeInfo so return 1
  47. *pctinfo=1;
  48. return NOERROR;
  49. }
  50. SCODE CDispatchHelp::GetTypeInfo(
  51. UINT itinfo,
  52. LCID lcid,
  53. ITypeInfo FAR* FAR* ppITypeInfo)
  54. {
  55. HRESULT hr;
  56. if (0!=itinfo)
  57. return TYPE_E_ELEMENTNOTFOUND;
  58. if (NULL==ppITypeInfo)
  59. return E_POINTER;
  60. *ppITypeInfo=NULL;
  61. //Load a type lib if we don't have the information already.
  62. if (NULL==m_pITINeutral)
  63. {
  64. ITypeLib *pITypeLib = NULL;
  65. hr=LoadRegTypeLib(LIBID_WbemScripting, 1, 0, lcid, &pITypeLib);
  66. if (FAILED(hr))
  67. return hr;
  68. //Got the type lib, get type info for the interface we want
  69. hr=pITypeLib->GetTypeInfoOfGuid(m_iGUID, &m_pITINeutral);
  70. pITypeLib->Release();
  71. if (FAILED(hr))
  72. return hr;
  73. }
  74. /*
  75. * Note: the type library is still loaded since we have
  76. * an ITypeInfo from it.
  77. */
  78. m_pITINeutral->AddRef();
  79. *ppITypeInfo = m_pITINeutral;
  80. return NOERROR;
  81. }
  82. SCODE CDispatchHelp::GetClassInfo(
  83. ITypeInfo FAR* FAR* ppITypeInfo)
  84. {
  85. HRESULT hr;
  86. if (NULL==ppITypeInfo)
  87. return E_POINTER;
  88. *ppITypeInfo=NULL;
  89. //Load a type lib if we don't have the information already.
  90. if (NULL==m_pCITINeutral)
  91. {
  92. ITypeLib *pITypeLib = NULL;
  93. hr=LoadRegTypeLib(LIBID_WbemScripting, 1, 0, 0, &pITypeLib);
  94. if (FAILED(hr))
  95. return hr;
  96. //Got the type lib, get type info for the interface we want
  97. hr=pITypeLib->GetTypeInfoOfGuid(m_cGUID, &m_pCITINeutral);
  98. pITypeLib->Release();
  99. if (FAILED(hr))
  100. return hr;
  101. }
  102. /*
  103. * Note: the type library is still loaded since we have
  104. * an ITypeInfo from it.
  105. */
  106. m_pCITINeutral->AddRef();
  107. *ppITypeInfo = m_pCITINeutral;
  108. return NOERROR;
  109. }
  110. SCODE CDispatchHelp::GetIDsOfNames(
  111. REFIID riid,
  112. OLECHAR FAR* FAR* rgszNames,
  113. UINT cNames,
  114. LCID lcid,
  115. DISPID FAR* rgdispid)
  116. {
  117. HRESULT hr;
  118. ITypeInfo *pTI;
  119. if (IID_NULL!=riid)
  120. return DISP_E_UNKNOWNINTERFACE;
  121. //Get the right ITypeInfo for lcid.
  122. hr=GetTypeInfo(0, lcid, &pTI);
  123. if (SUCCEEDED(hr))
  124. {
  125. hr=DispGetIDsOfNames(pTI, rgszNames, cNames, rgdispid);
  126. pTI->Release();
  127. }
  128. return hr;
  129. }
  130. void ParseDispArgs (DISPPARAMS FAR * dispparams)
  131. {
  132. if (dispparams)
  133. {
  134. int argCount = dispparams->cArgs;
  135. for (int i = 0; i < argCount; i++)
  136. {
  137. VARIANTARG &v = dispparams->rgvarg [i];
  138. }
  139. int nargCount = dispparams->cNamedArgs;
  140. }
  141. }
  142. SCODE CDispatchHelp::Invoke(
  143. DISPID dispidMember,
  144. REFIID riid,
  145. LCID lcid,
  146. WORD wFlags,
  147. DISPPARAMS FAR* pdispparams,
  148. VARIANT FAR* pvarResult,
  149. EXCEPINFO FAR* pexcepinfo,
  150. UINT FAR* puArgErr)
  151. {
  152. HRESULT hr;
  153. ITypeInfo *pTI;
  154. m_hResult = S_OK;
  155. if(m_pObj == NULL)
  156. return WBEM_E_FAILED;
  157. //riid is supposed to be IID_NULL always
  158. if (IID_NULL!=riid)
  159. return DISP_E_UNKNOWNINTERFACE;
  160. //Get the ITypeInfo for lcid
  161. hr=GetTypeInfo(0, lcid, &pTI);
  162. if (FAILED(hr))
  163. return hr;
  164. //ParseDispArgs (pdispparams);
  165. // Reinterpret inbound VT_NULLs as VT_ERRORs
  166. if (HandleNulls (dispidMember, wFlags))
  167. MapNulls (pdispparams);
  168. hr=pTI->Invoke(m_pObj, dispidMember, wFlags,
  169. pdispparams, pvarResult,
  170. pexcepinfo, puArgErr);
  171. if (FAILED(hr))
  172. {
  173. // Try the error handler for this object in case it can handle this
  174. hr = HandleError (dispidMember, wFlags, pdispparams, pvarResult, puArgErr, hr);
  175. }
  176. pTI->Release();
  177. if (FAILED(m_hResult))
  178. {
  179. if (NULL != pexcepinfo)
  180. SetException (pexcepinfo, m_hResult, m_objectName);
  181. hr = DISP_E_EXCEPTION;
  182. }
  183. return hr;
  184. }
  185. void CDispatchHelp::RaiseException (HRESULT hr)
  186. {
  187. // Store the HRESULT for processing in the Invoke routine
  188. m_hResult = hr;
  189. // Set a WMI scripting error on this thread for the client
  190. ICreateErrorInfo *pCreateErrorInfo = NULL;
  191. if (SUCCEEDED (CreateErrorInfo (&pCreateErrorInfo)))
  192. {
  193. BSTR bsDescr = MapHresultToWmiDescription (hr);
  194. pCreateErrorInfo->SetDescription (bsDescr);
  195. SysFreeString (bsDescr);
  196. pCreateErrorInfo->SetGUID (m_cGUID);
  197. pCreateErrorInfo->SetSource (m_objectName);
  198. IErrorInfo *pErrorInfo = NULL;
  199. if (SUCCEEDED (pCreateErrorInfo->QueryInterface(IID_IErrorInfo, (void**) &pErrorInfo)))
  200. {
  201. SetErrorInfo (0, pErrorInfo);
  202. pErrorInfo->Release ();
  203. }
  204. pCreateErrorInfo->Release ();
  205. }
  206. }
  207. // IDispatchEx methods
  208. HRESULT STDMETHODCALLTYPE CDispatchHelp::GetDispID(
  209. /* [in] */ BSTR bstrName,
  210. /* [in] */ DWORD grfdex,
  211. /* [out] */ DISPID __RPC_FAR *pid)
  212. {
  213. _RD(static char *me = "CDispatchHelp::GetDispID()";)
  214. _RPrint(me, "Called name:", 0, "");
  215. return GetIDsOfNames(IID_NULL, &((OLECHAR *)bstrName), 1, ENGLISH_LOCALE, pid);
  216. }