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.

516 lines
14 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // object.h
  6. //
  7. // alanbos 27-Mar-00 Created.
  8. //
  9. // CSWbemObject and CSWbemObjectSet definition.
  10. //
  11. //***************************************************************************
  12. #ifndef _OBJECT_H_
  13. #define _OBJECT_H_
  14. //***************************************************************************
  15. //
  16. // CLASS NAME:
  17. //
  18. // CSWbemObject
  19. //
  20. // DESCRIPTION:
  21. //
  22. // Implements the ISWbemObjectEx interface.
  23. //
  24. //***************************************************************************
  25. class CSWbemObject : public ISWbemObjectEx,
  26. public IDispatchEx,
  27. public ISWbemInternalObject,
  28. public IObjectSafety,
  29. public ISupportErrorInfo,
  30. public IProvideClassInfo
  31. {
  32. friend CSWbemServices;
  33. private:
  34. bool m_isErrorObject;
  35. CSWbemServices *m_pSWbemServices;
  36. IWbemClassObject *m_pIWbemClassObject;
  37. CWbemDispatchMgr *m_pDispatch;
  38. IServiceProvider *m_pIServiceProvider;
  39. IWbemRefresher *m_pIWbemRefresher;
  40. bool m_bCanUseRefresher;
  41. // If an embedded object, we store the parent site
  42. CWbemSite *m_pSite;
  43. bool CastToScope (IDispatch *pContext, CComPtr<ISWbemServicesEx> &pISWbemServicesEx);
  44. protected:
  45. long m_cRef; //Object reference count
  46. public:
  47. CSWbemObject(CSWbemServices *pService, IWbemClassObject *pIWbemClassObject,
  48. CSWbemSecurity *pSecurity = NULL, bool isErrorObject = false);
  49. virtual ~CSWbemObject(void);
  50. //Non-delegating object IUnknown
  51. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  52. STDMETHODIMP_(ULONG) AddRef(void);
  53. STDMETHODIMP_(ULONG) Release(void);
  54. // IDispatch should be inline
  55. STDMETHODIMP GetTypeInfoCount(UINT* pctinfo);
  56. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo);
  57. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  58. UINT cNames, LCID lcid, DISPID* rgdispid);
  59. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  60. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  61. EXCEPINFO* pexcepinfo, UINT* puArgErr);
  62. // IDispatchEx methods should be inline
  63. HRESULT STDMETHODCALLTYPE GetDispID(
  64. /* [in] */ BSTR bstrName,
  65. /* [in] */ DWORD grfdex,
  66. /* [out] */ DISPID __RPC_FAR *pid);
  67. /* [local] */ HRESULT STDMETHODCALLTYPE InvokeEx(
  68. /* [in] */ DISPID id,
  69. /* [in] */ LCID lcid,
  70. /* [in] */ WORD wFlags,
  71. /* [in] */ DISPPARAMS __RPC_FAR *pdp,
  72. /* [out] */ VARIANT __RPC_FAR *pvarRes,
  73. /* [out] */ EXCEPINFO __RPC_FAR *pei,
  74. /* [unique][in] */ IServiceProvider __RPC_FAR *pspCaller);
  75. HRESULT STDMETHODCALLTYPE DeleteMemberByName(
  76. /* [in] */ BSTR bstr,
  77. /* [in] */ DWORD grfdex);
  78. HRESULT STDMETHODCALLTYPE DeleteMemberByDispID(
  79. /* [in] */ DISPID id);
  80. HRESULT STDMETHODCALLTYPE GetMemberProperties(
  81. /* [in] */ DISPID id,
  82. /* [in] */ DWORD grfdexFetch,
  83. /* [out] */ DWORD __RPC_FAR *pgrfdex);
  84. HRESULT STDMETHODCALLTYPE GetMemberName(
  85. /* [in] */ DISPID id,
  86. /* [out] */ BSTR __RPC_FAR *pbstrName);
  87. HRESULT STDMETHODCALLTYPE GetNextDispID(
  88. /* [in] */ DWORD grfdex,
  89. /* [in] */ DISPID id,
  90. /* [out] */ DISPID __RPC_FAR *pid);
  91. HRESULT STDMETHODCALLTYPE GetNameSpaceParent(
  92. /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunk);
  93. // ISWbemObject methods
  94. HRESULT STDMETHODCALLTYPE Put_
  95. (
  96. /*[in]*/ long lFlags,
  97. /*[in]*/ /*ISWbemNamedValueSet*/ IDispatch *pContext,
  98. /*[out]*/ ISWbemObjectPath **ppObject
  99. );
  100. HRESULT STDMETHODCALLTYPE Delete_
  101. (
  102. /*[in]*/ long lFlags,
  103. /*[in]*/ /*ISWbemNamedValueSet*/ IDispatch *pContext
  104. );
  105. HRESULT STDMETHODCALLTYPE Instances_
  106. (
  107. /*[in]*/ long lFlags,
  108. /*[in]*/ /*ISWbemNamedValueSet*/ IDispatch *pContext,
  109. /*[out]*/ ISWbemObjectSet **ppEnum
  110. );
  111. HRESULT STDMETHODCALLTYPE Subclasses_
  112. (
  113. /*[in]*/ long lFlags,
  114. /*[in]*/ /*ISWbemNamedValueSet*/ IDispatch *pContext,
  115. /*[out]*/ ISWbemObjectSet **ppEnum
  116. );
  117. HRESULT STDMETHODCALLTYPE ExecMethod_
  118. (
  119. /*[in]*/ BSTR methodName,
  120. /*[in]*/ /*ISWbemObject*/ IDispatch *pInParams,
  121. /*[in]*/ long lFlags,
  122. /*[in]*/ /*ISWbemNamedValueSet*/ IDispatch *pContext,
  123. /*[out]*/ ISWbemObject **ppOutParams
  124. );
  125. HRESULT STDMETHODCALLTYPE Associators_
  126. (
  127. /*[in]*/ BSTR assocClass,
  128. /*[in]*/ BSTR resultClass,
  129. /*[in]*/ BSTR resultRole,
  130. /*[in]*/ BSTR role,
  131. /*[in]*/ VARIANT_BOOL classesOnly,
  132. /*[in]*/ VARIANT_BOOL schemaOnly,
  133. /*[in]*/ BSTR requiredAssocQualifier,
  134. /*[in]*/ BSTR requiredQualifier,
  135. /*[in]*/ long lFlags,
  136. /*[in]*/ /*ISWbemNamedValueSet*/ IDispatch *pContext,
  137. /*[out]*/ ISWbemObjectSet **ppEnum
  138. );
  139. HRESULT STDMETHODCALLTYPE References_
  140. (
  141. /*[in]*/ BSTR resultClass,
  142. /*[in]*/ BSTR role,
  143. /*[in]*/ VARIANT_BOOL classesOnly,
  144. /*[in]*/ VARIANT_BOOL schemaOnly,
  145. /*[in]*/ BSTR requiredQualifier,
  146. /*[in]*/ long lFlags,
  147. /*[in]*/ /*ISWbemNamedValueSet*/ IDispatch *pContext,
  148. /*[out]*/ ISWbemObjectSet **ppEnum
  149. );
  150. HRESULT STDMETHODCALLTYPE Clone_
  151. (
  152. /*[out]*/ ISWbemObject **ppCopy
  153. );
  154. HRESULT STDMETHODCALLTYPE GetObjectText_
  155. (
  156. /*[in]*/ long lFlags,
  157. /*[out]*/ BSTR *pObjectText
  158. );
  159. HRESULT STDMETHODCALLTYPE SpawnDerivedClass_
  160. (
  161. /*[in]*/ long lFlags,
  162. /*[out]*/ ISWbemObject** ppNewClass
  163. );
  164. HRESULT STDMETHODCALLTYPE SpawnInstance_
  165. (
  166. /*[in]*/ long lFlags,
  167. /*[out]*/ ISWbemObject** ppNewInstance
  168. );
  169. HRESULT STDMETHODCALLTYPE CompareTo_
  170. (
  171. /*[in]*/ /*ISWbemObject*/ IDispatch *pCompareTo,
  172. /*[in]*/ long lFlags,
  173. /*[out]*/ VARIANT_BOOL *result
  174. );
  175. HRESULT STDMETHODCALLTYPE get_Qualifiers_
  176. (
  177. /*[out]*/ ISWbemQualifierSet **ppQualifierSet
  178. );
  179. HRESULT STDMETHODCALLTYPE get_Properties_
  180. (
  181. /*[out]*/ ISWbemPropertySet **ppPropertySet
  182. );
  183. HRESULT STDMETHODCALLTYPE get_Methods_
  184. (
  185. /*[out]*/ ISWbemMethodSet **ppMethodSet
  186. );
  187. HRESULT STDMETHODCALLTYPE get_Derivation_
  188. (
  189. /*[out]*/ VARIANT *pClassNames
  190. );
  191. HRESULT STDMETHODCALLTYPE get_Path_
  192. (
  193. /*[out]*/ ISWbemObjectPath **ppObjectPath
  194. );
  195. // Async methods
  196. HRESULT STDMETHODCALLTYPE PutAsync_(
  197. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  198. /* [defaultvalue][optional][in] */ long iFlags,
  199. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  200. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext);
  201. HRESULT STDMETHODCALLTYPE DeleteAsync_(
  202. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  203. /* [defaultvalue][optional][in] */ long iFlags,
  204. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  205. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext);
  206. HRESULT STDMETHODCALLTYPE InstancesAsync_(
  207. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  208. /* [defaultvalue][optional][in] */ long iFlags,
  209. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  210. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext);
  211. HRESULT STDMETHODCALLTYPE SubclassesAsync_(
  212. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  213. /* [defaultvalue][optional][in] */ long iFlags,
  214. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  215. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext);
  216. HRESULT STDMETHODCALLTYPE AssociatorsAsync_(
  217. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  218. /* [defaultvalue][optional][in] */ BSTR strAssocClass,
  219. /* [defaultvalue][optional][in] */ BSTR strResultClass,
  220. /* [defaultvalue][optional][in] */ BSTR strResultRole,
  221. /* [defaultvalue][optional][in] */ BSTR strRole,
  222. /* [defaultvalue][optional][in] */ VARIANT_BOOL bClassesOnly,
  223. /* [defaultvalue][optional][in] */ VARIANT_BOOL bSchemaOnly,
  224. /* [defaultvalue][optional][in] */ BSTR strRequiredAssocQualifier,
  225. /* [defaultvalue][optional][in] */ BSTR strRequiredQualifier,
  226. /* [defaultvalue][optional][in] */ long iFlags,
  227. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  228. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext);
  229. HRESULT STDMETHODCALLTYPE ReferencesAsync_(
  230. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  231. /* [defaultvalue][optional][in] */ BSTR strResultClass,
  232. /* [defaultvalue][optional][in] */ BSTR strRole,
  233. /* [defaultvalue][optional][in] */ VARIANT_BOOL bClassesOnly,
  234. /* [defaultvalue][optional][in] */ VARIANT_BOOL bSchemaOnly,
  235. /* [defaultvalue][optional][in] */ BSTR strRequiredQualifier,
  236. /* [defaultvalue][optional][in] */ long iFlags,
  237. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  238. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext);
  239. HRESULT STDMETHODCALLTYPE ExecMethodAsync_(
  240. /* [in] */ IDispatch __RPC_FAR *pAsyncNotify,
  241. /* [in] */ BSTR strMethodName,
  242. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objInParams,
  243. /* [defaultvalue][optional][in] */ long iFlags,
  244. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *objContext,
  245. /* [defaultvalue][optional][in] */ IDispatch __RPC_FAR *pAsyncContext);
  246. HRESULT STDMETHODCALLTYPE get_Security_
  247. (
  248. /* [in] */ ISWbemSecurity **ppSecurity
  249. );
  250. // ISWbemObjectEx methods
  251. HRESULT STDMETHODCALLTYPE Refresh_ (
  252. /*[ in ]*/ long iFlags,
  253. /*[ in ]*/ /*ISWbemNamedValueSet*/ IDispatch *objWbemNamedValueSet
  254. );
  255. HRESULT STDMETHODCALLTYPE get_SystemProperties_
  256. (
  257. /*[out]*/ ISWbemPropertySet **ppPropertySet
  258. );
  259. HRESULT STDMETHODCALLTYPE GetText_ (
  260. /*[in]*/ WbemObjectTextFormatEnum iObjectTextFormat,
  261. /*[in]*/ long iFlags,
  262. /*[in]*/ /*ISWbemNamedValueSet*/ IDispatch *objWbemNamedValueSet,
  263. /*[out, retval]*/ BSTR *bsText
  264. );
  265. HRESULT STDMETHODCALLTYPE SetFromText_ (
  266. /*[in]*/ BSTR bsText,
  267. /*[in]*/ WbemObjectTextFormatEnum iObjectTextFormat,
  268. /*[in]*/ long iFlags,
  269. /*[in]*/ /*ISWbemNamedValueSet*/ IDispatch *objWbemNamedValueSet
  270. );
  271. // ISWbemInternalObject methods
  272. HRESULT STDMETHODCALLTYPE GetIWbemClassObject (IWbemClassObject **ppObject);
  273. HRESULT STDMETHODCALLTYPE SetSite (ISWbemInternalObject *pParentObject,
  274. BSTR propertyName, long index = -1);
  275. HRESULT STDMETHODCALLTYPE UpdateSite ();
  276. // IObjectSafety methods
  277. HRESULT STDMETHODCALLTYPE SetInterfaceSafetyOptions
  278. (
  279. /* [in] */ REFIID riid,
  280. /* [in] */ DWORD dwOptionSetMask,
  281. /* [in] */ DWORD dwEnabledOptions
  282. )
  283. {
  284. return (dwOptionSetMask & dwEnabledOptions) ? E_FAIL : S_OK;
  285. }
  286. HRESULT STDMETHODCALLTYPE GetInterfaceSafetyOptions(
  287. /* [in] */ REFIID riid,
  288. /* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
  289. /* [out] */ DWORD __RPC_FAR *pdwEnabledOptions
  290. )
  291. {
  292. if (pdwSupportedOptions) *pdwSupportedOptions = 0;
  293. if (pdwEnabledOptions) *pdwEnabledOptions = 0;
  294. return S_OK;
  295. }
  296. // ISupportErrorInfo methods
  297. HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo
  298. (
  299. /* [in] */ REFIID riid
  300. );
  301. // IProvideClassInfo methods
  302. HRESULT STDMETHODCALLTYPE GetClassInfo
  303. (
  304. /* [in,out] */ ITypeInfo **ppTI
  305. )
  306. {
  307. return (m_pDispatch) ? m_pDispatch->GetClassInfo (ppTI) : E_FAIL;
  308. };
  309. // Other methods
  310. static IWbemClassObject *GetIWbemClassObject (IDispatch *pDispatch);
  311. IWbemClassObject* GetIWbemClassObject ()
  312. {
  313. m_pIWbemClassObject->AddRef ();
  314. return m_pIWbemClassObject;
  315. }
  316. void SetIWbemClassObject (IWbemClassObject *pIWbemClassObject);
  317. static void SetSite (IDispatch *pDispatch,
  318. ISWbemInternalObject *pSObject, BSTR propertyName, long index = -1);
  319. };
  320. //***************************************************************************
  321. //
  322. // CLASS NAME:
  323. //
  324. // CSWbemObjectSet
  325. //
  326. // DESCRIPTION:
  327. //
  328. // Implements the ISWbemObjectSet interface.
  329. //
  330. //***************************************************************************
  331. class CSWbemObjectSet : public ISWbemObjectSet,
  332. public ISupportErrorInfo,
  333. public IProvideClassInfo
  334. {
  335. private:
  336. CSWbemServices *m_pSWbemServices;
  337. CDispatchHelp m_Dispatch;
  338. CSWbemSecurity *m_SecurityInfo;
  339. bool m_firstEnumerator;
  340. bool m_bIsEmpty;
  341. protected:
  342. long m_cRef; //Object reference count
  343. public:
  344. CSWbemObjectSet(CSWbemServices *pService, IEnumWbemClassObject *pIEnumWbemClassObject,
  345. CSWbemSecurity *pSecurity = NULL);
  346. CSWbemObjectSet (void);
  347. ~CSWbemObjectSet(void);
  348. //Non-delegating object IUnknown
  349. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  350. STDMETHODIMP_(ULONG) AddRef(void);
  351. STDMETHODIMP_(ULONG) Release(void);
  352. // IDispatch
  353. STDMETHODIMP GetTypeInfoCount(UINT* pctinfo)
  354. {return m_Dispatch.GetTypeInfoCount(pctinfo);}
  355. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  356. {return m_Dispatch.GetTypeInfo(itinfo, lcid, pptinfo);}
  357. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  358. UINT cNames, LCID lcid, DISPID* rgdispid)
  359. {return m_Dispatch.GetIDsOfNames(riid, rgszNames, cNames,
  360. lcid,
  361. rgdispid);}
  362. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  363. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  364. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  365. {return m_Dispatch.Invoke(dispidMember, riid, lcid, wFlags,
  366. pdispparams, pvarResult, pexcepinfo, puArgErr);}
  367. // Collection methods
  368. HRESULT STDMETHODCALLTYPE get__NewEnum
  369. (
  370. /*[out]*/ IUnknown **ppUnk
  371. );
  372. HRESULT STDMETHODCALLTYPE get_Count
  373. (
  374. /*[out]*/ long *plCount
  375. );
  376. HRESULT STDMETHODCALLTYPE Item
  377. (
  378. /*[in]*/ BSTR objectPath,
  379. /*[in]*/ long lFlags,
  380. /*[out]*/ ISWbemObject **ppObject
  381. );
  382. // ISWbemObjectSet methods
  383. HRESULT STDMETHODCALLTYPE Reset
  384. (
  385. );
  386. HRESULT STDMETHODCALLTYPE Next
  387. (
  388. /*[in]*/ long lTimeout,
  389. /*[out]*/ ISWbemObject **ppObject
  390. );
  391. HRESULT STDMETHODCALLTYPE Clone
  392. (
  393. /*[out]*/ ISWbemObjectSet **ppEnum
  394. );
  395. HRESULT STDMETHODCALLTYPE Skip
  396. (
  397. /*[in]*/ ULONG lElements,
  398. /*[in]*/ long lTimeout
  399. );
  400. HRESULT STDMETHODCALLTYPE get_Security_
  401. (
  402. /* [in] */ ISWbemSecurity **ppSecurity
  403. );
  404. // ISupportErrorInfo methods
  405. HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo
  406. (
  407. /* [in] */ REFIID riid
  408. );
  409. // IProvideClassInfo methods
  410. HRESULT STDMETHODCALLTYPE GetClassInfo
  411. (
  412. /* [in,out] */ ITypeInfo **ppTI
  413. )
  414. {
  415. return m_Dispatch.GetClassInfo (ppTI);
  416. };
  417. // Other methods
  418. CSWbemServices *GetSWbemServices ()
  419. {
  420. return m_pSWbemServices;
  421. }
  422. HRESULT CloneObjectSet (CSWbemObjectSet **ppEnum);
  423. };
  424. #endif