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.

833 lines
20 KiB

  1. // object.h : Declaration of the CObject
  2. #ifndef __Object_H_
  3. #define __Object_H_
  4. #include "resource.h" // main symbols
  5. #include "property.h"
  6. #include "guidedb.h"
  7. class CObjectType;
  8. class CObjectTypes;
  9. class CObject;
  10. class CObjectGlue;
  11. class CObjects;
  12. class CObjectPropertyBag;
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CObjectType
  15. class CObjectType
  16. {
  17. public:
  18. CObjectType()
  19. {
  20. m_fKnowCollectionCLSID = FALSE;
  21. }
  22. HRESULT CreateInstance(long id, IUnknown **ppobj);
  23. HRESULT Init(CGuideDB *pdb, long id, BSTR bstrCLSID)
  24. {
  25. CLSID clsid;
  26. HRESULT hr = CLSIDFromString(bstrCLSID, &clsid);
  27. if (hr == CO_E_CLASSSTRING)
  28. return E_INVALIDARG;
  29. return Init(pdb, id, clsid);
  30. }
  31. HRESULT Init(CGuideDB *pdb, long id, IID clsid)
  32. {
  33. m_pdb = pdb;
  34. m_id = id;
  35. m_clsid = clsid;
  36. return S_OK;
  37. }
  38. HRESULT GetDB(CGuideDB **ppdb);
  39. public:
  40. STDMETHOD(get_NewCollection)(/*[out, retval]*/ IObjects * *ppobjs);
  41. STDMETHOD(get_New)(/*[out, retval]*/ IUnknown * *pVal);
  42. STDMETHOD(get_IID)(/*[out, retval]*/ BSTR *pVal);
  43. STDMETHOD(get_ID)(/*[out, retval]*/ long *pVal);
  44. friend CObject;
  45. protected:
  46. CComPtr<CGuideDB> m_pdb;
  47. CLSID m_clsid;
  48. long m_id;
  49. boolean m_fKnowCollectionCLSID;
  50. CLSID m_clsidCollection;
  51. };
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CObjectTypes
  54. class CObjectTypes
  55. {
  56. public:
  57. HRESULT Init(CGuideDB *pdb);
  58. CObjectType *Cache(long id, BSTR bstrCLSID);
  59. public:
  60. STDMETHOD(get_AddNew)(BSTR bstrIID, /*[out, retval]*/ CObjectType * *pVal);
  61. #if 0
  62. STDMETHOD(get_AddNew)(CLSID clsid, /*[out, retval]*/ CObjectType * *pVal);
  63. #endif
  64. STDMETHOD(get_ItemWithCLSID)(BSTR bstrCLSID, /*[out, retval]*/ CObjectType * *pVal);
  65. // STDMETHOD(get_ItemWithCLSID)(CLSID clsid, /*[out, retval]*/ CObjectType * *pVal);
  66. protected:
  67. CComPtr<CGuideDB> m_pdb;
  68. ADODB::_RecordsetPtr m_prsObjTypes;
  69. typedef MemCmpLess<CLSID> CLSIDLess;
  70. typedef map<CLSID, CObjectType *, CLSIDLess> t_map;
  71. t_map m_map;
  72. };
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CObject
  75. class DECLSPEC_UUID("4789011b-bc6d-49e2-b4df-420e40f4e318") ATL_NO_VTABLE CObject :
  76. public IUnknown,
  77. public CComObjectRootEx<CComObjectThreadModel>
  78. {
  79. public:
  80. CObject()
  81. {
  82. m_id = 0;
  83. }
  84. DECLARE_GET_CONTROLLING_UNKNOWN()
  85. BEGIN_COM_MAP(CObject)
  86. COM_INTERFACE_ENTRY(CObject)
  87. COM_INTERFACE_ENTRY_AGGREGATE_BLIND(m_punk.p)
  88. END_COM_MAP()
  89. friend class CObjectGlue;
  90. CGuideDB *GetDB()
  91. {
  92. //UNSAFE... doesn't do AddRef()... use the pointer quickly!
  93. return m_pdb;
  94. }
  95. HRESULT get_RelatedObjectID(boolean fInverse, long id, long idRel, long *pidRet);
  96. HRESULT get_ItemsRelatedBy(CObjectType *pobjtype,
  97. long idRel, boolean fInverse, IObjects **ppobjs);
  98. HRESULT CreatePropBag(IPersist *ppersist);
  99. public:
  100. STDMETHOD(Init)(long id, CObjectType * pobjtype);
  101. STDMETHOD(Save)(IUnknown *punk);
  102. STDMETHOD(Load)();
  103. STDMETHOD(get_ItemsInverseRelatedBy)(CObjectType *pobjtype, /* [in] */ long idRel, /*[out, retval]*/ IObjects **ppobjs1);
  104. STDMETHOD(get_ItemInverseRelatedBy)(/* [in] */ long idRel, /*[out, retval]*/ IUnknown **ppobj1);
  105. STDMETHOD(get_ItemsRelatedBy)(CObjectType *pobjtype, /* [in] */ long idRel, /*[out, retval]*/ IObjects **ppobjs2);
  106. STDMETHOD(get_ItemRelatedBy)(/* [in] */ long idRel, /*[out, retval]*/ IUnknown **ppobj2);
  107. STDMETHOD(put_ItemRelatedBy)(/* [in] */ long idRel, /*[in]*/ IUnknown *pobj2);
  108. STDMETHOD(get_MetaProperties)(/*[out, retval]*/ IMetaProperties * *pVal);
  109. STDMETHOD(get_ID)(/*[out, retval]*/ long *pVal);
  110. STDMETHOD(get_Type)(/*[out, retval]*/ CObjectType * *pVal);
  111. protected:
  112. CObjectType *m_pobjtype;
  113. CComPtr<IUnknown> m_punk;
  114. CComPtr<CGuideDB> m_pdb;
  115. CComPtr<IMetaProperties> m_pprops;
  116. long m_id;
  117. CComPtr<CObjectPropertyBag> m_ppropbag;
  118. };
  119. class CObjectGlue
  120. {
  121. public:
  122. virtual IUnknown *GetControllingUnknown() = 0;
  123. HRESULT get_ItemsRelatedBy(CObjectType *pobjtype,
  124. IMetaPropertyType *pproptype, boolean fInverse, IObjects **ppobjs)
  125. {
  126. CComQIPtr<CObject> pobj(GetControllingUnknown());
  127. CComQIPtr<CMetaPropertyType> pproptypeT(pproptype);
  128. long idRel = pproptypeT->GetID();
  129. return pobj->get_ItemsRelatedBy(pobjtype, idRel, fInverse, ppobjs);
  130. }
  131. // IObjectInt
  132. protected:
  133. STDMETHOD(Init)(long id, CObjectType * pobjtype)
  134. {
  135. CComQIPtr<CObject> pobj(GetControllingUnknown());
  136. return pobj->Init(id, pobjtype);
  137. }
  138. public:
  139. STDMETHOD(get_ItemsInverseRelatedBy)(CObjectType *pobjtype,
  140. IMetaPropertyType *pproptype, /*[out, retval]*/ IObjects **ppobjs1)
  141. {
  142. CComQIPtr<CObject> pobj(GetControllingUnknown());
  143. CComQIPtr<CMetaPropertyType> pproptypeT(pproptype);
  144. long idRel = pproptypeT->GetID();
  145. return pobj->get_ItemsInverseRelatedBy(pobjtype, idRel, ppobjs1);
  146. }
  147. STDMETHOD(get_ItemInverseRelatedBy)(IMetaPropertyType *pproptype, /*[out, retval]*/ IUnknown **ppobj1)
  148. {
  149. CComQIPtr<CObject> pobj(GetControllingUnknown());
  150. CComQIPtr<CMetaPropertyType> pproptypeT(pproptype);
  151. long idRel = pproptypeT->GetID();
  152. return pobj->get_ItemInverseRelatedBy(idRel, ppobj1);
  153. }
  154. STDMETHOD(get_ItemsRelatedBy)(CObjectType *pobjtype,
  155. IMetaPropertyType *pproptype, /*[out, retval]*/ IObjects **ppobjs2)
  156. {
  157. CComQIPtr<CObject> pobj(GetControllingUnknown());
  158. CComQIPtr<CMetaPropertyType> pproptypeT(pproptype);
  159. long idRel = pproptypeT->GetID();
  160. return pobj->get_ItemsRelatedBy(pobjtype, idRel, ppobjs2);
  161. }
  162. STDMETHOD(get_ItemRelatedBy)(IMetaPropertyType *pproptype, /*[out, retval]*/ IUnknown **ppobj2)
  163. {
  164. CComQIPtr<CObject> pobj(GetControllingUnknown());
  165. CComQIPtr<CMetaPropertyType> pproptypeT(pproptype);
  166. long idRel = pproptypeT->GetID();
  167. return pobj->get_ItemRelatedBy(idRel, ppobj2);
  168. }
  169. STDMETHOD(put_ItemRelatedBy)(IMetaPropertyType *pproptype, /*[in]*/ IUnknown *pobj2)
  170. {
  171. CComQIPtr<CObject> pobj(GetControllingUnknown());
  172. CComQIPtr<CMetaPropertyType> pproptypeT(pproptype);
  173. long idRel = pproptypeT->GetID();
  174. return pobj->put_ItemRelatedBy(idRel, pobj2);
  175. }
  176. STDMETHOD(get_MetaProperties)(/*[out, retval]*/ IMetaProperties * *ppprops)
  177. {
  178. CComQIPtr<CObject> pobj(GetControllingUnknown());
  179. return pobj->get_MetaProperties(ppprops);
  180. }
  181. STDMETHOD(get_ID)(/*[out, retval]*/ long *pid)
  182. {
  183. CComQIPtr<CObject> pobj(GetControllingUnknown());
  184. return pobj->get_ID(pid);
  185. }
  186. STDMETHOD(get_Type)(/*[out, retval]*/ CObjectType * *pobjtype)
  187. {
  188. CComQIPtr<CObject> pobj(GetControllingUnknown());
  189. return pobj->get_Type(pobjtype);
  190. }
  191. template<class T_Related>
  192. HRESULT _get_ItemRelatedBy(IMetaPropertyType *pproptype, T_Related **ppT)
  193. {
  194. CComPtr<IUnknown> pobj;
  195. HRESULT hr;
  196. hr = get_ItemRelatedBy(pproptype, &pobj);
  197. if (hr == S_FALSE || FAILED(hr))
  198. return hr;
  199. return pobj->QueryInterface(__uuidof(T_Related), (void **) ppT);
  200. }
  201. template<class T_Related>
  202. HRESULT _put_ItemRelatedBy(IMetaPropertyType *pproptype, T_Related *pT)
  203. {
  204. return put_ItemRelatedBy(pproptype, pT);
  205. }
  206. __declspec(property(get=GetDB)) CGuideDB *m_pdb;
  207. CGuideDB *GetDB()
  208. {
  209. CComQIPtr<CObject> pobj(GetControllingUnknown());
  210. return pobj->GetDB();
  211. }
  212. };
  213. /////////////////////////////////////////////////////////////////////////////
  214. // CObjects
  215. class ATL_NO_VTABLE DECLSPEC_UUID("AC0F25D9-81C8-4C9E-B7AC-031E9A539E1E") CObjects :
  216. public CComObjectRootEx<CComObjectThreadModel>,
  217. public CComCoClass<CObjects, &CLSID_Objects>,
  218. public IObjectsPrivate,
  219. public IObjects
  220. {
  221. public:
  222. CObjects()
  223. {
  224. #if defined(_ATL_FREE_THREADED)
  225. m_pUnkMarshaler = NULL;
  226. #endif
  227. m_cItems = -1;
  228. m_fInverse = FALSE;
  229. m_pobjtype = NULL;
  230. m_fOnlyUnreferenced = FALSE;
  231. m_idChanged = NULL;
  232. m_cChanged = 0;
  233. m_idPropTypeKey = 0;
  234. m_idProviderKey = 0;
  235. m_idLangKey = 0;
  236. m_vtKey = 0;
  237. }
  238. CGuideDB *GetDB()
  239. {
  240. //UNSAFE... doesn't do AddRef()... use the pointer quickly!
  241. return m_pdb;
  242. }
  243. void Dump();
  244. HRESULT Clone(IObjects **ppobjs);
  245. HRESULT AddRelationshipAt(long idObj1, long idRel, long iItem, long idObj2);
  246. HRESULT put_OnlyUnreferenced(boolean fOnlyUnreferenced)
  247. {
  248. m_fOnlyUnreferenced = fOnlyUnreferenced;
  249. return S_OK;
  250. }
  251. // If in a transaction, NoteChanged() will be called to keep track of changes.
  252. // TransactionDone() will be called when the transaction is done.
  253. void NoteChanged(long idObj)
  254. {
  255. if (m_idChanged == 0)
  256. {
  257. m_idChanged = idObj;
  258. m_cChanged++;
  259. }
  260. else if (m_idChanged != idObj)
  261. {
  262. m_cChanged++;
  263. }
  264. }
  265. void TransactionDone(boolean fCommited)
  266. {
  267. if (fCommited && (m_cChanged > 0))
  268. {
  269. long idType;
  270. m_pobjtype->get_ID(&idType);
  271. if (m_cChanged == 1)
  272. {
  273. m_pdb->Broadcast_ItemChanged(m_idChanged, idType);
  274. }
  275. else
  276. {
  277. m_pdb->Broadcast_ItemsChanged(idType);
  278. }
  279. }
  280. m_cChanged = 0;
  281. m_idChanged = NULL;
  282. }
  283. DECLARE_REGISTRY_RESOURCEID(IDR_OBJECTS)
  284. DECLARE_GET_CONTROLLING_UNKNOWN()
  285. DECLARE_PROTECT_FINAL_CONSTRUCT()
  286. BEGIN_COM_MAP(CObjects)
  287. COM_INTERFACE_ENTRY(IObjects)
  288. COM_INTERFACE_ENTRY(CObjects)
  289. COM_INTERFACE_ENTRY(IObjectsPrivate)
  290. #if defined(_ATL_FREE_THREADED)
  291. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  292. #endif
  293. COM_INTERFACE_ENTRY_AGGREGATE_BLIND(m_punkCollection.p)
  294. END_COM_MAP()
  295. #if defined(_ATL_FREE_THREADED)
  296. HRESULT FinalConstruct()
  297. {
  298. return CoCreateFreeThreadedMarshaler(
  299. GetControllingUnknown(), &m_pUnkMarshaler.p);
  300. }
  301. void FinalRelease()
  302. {
  303. m_pUnkMarshaler.Release();
  304. }
  305. CComPtr<IUnknown> m_pUnkMarshaler;
  306. #endif
  307. HRESULT Init(CLSID &clsid)
  308. {
  309. return m_punkCollection.CoCreateInstance(clsid, (IObjects *) this);
  310. }
  311. // Call IObjectsNotifications to notify Add/Remove/Change Item
  312. HRESULT Notify_ItemAdded(IUnknown * pobj)
  313. {
  314. CComQIPtr<IObjectsNotifications> pobjsevents((IObjects *) this);
  315. if (pobjsevents == NULL)
  316. return S_OK;
  317. return pobjsevents->Notify_ItemAdded(pobj);
  318. }
  319. HRESULT Notify_ItemRemoved(long idObj)
  320. {
  321. CComQIPtr<IObjectsNotifications> pobjsevents((IObjects *) this);
  322. if (pobjsevents == NULL)
  323. return S_OK;
  324. return pobjsevents->Notify_ItemRemoved(idObj);
  325. }
  326. HRESULT Notify_ItemChanged(IUnknown * pobj)
  327. {
  328. CComQIPtr<IObjectsNotifications> pobjsevents((IObjects *) this);
  329. if (pobjsevents == NULL)
  330. return S_OK;
  331. return pobjsevents->Notify_ItemChanged(pobj);
  332. }
  333. HRESULT Notify_ItemsChanged()
  334. {
  335. CComQIPtr<IObjectsNotifications> pobjsevents((IObjects *) this);
  336. if (pobjsevents == NULL)
  337. return S_OK;
  338. return pobjsevents->Notify_ItemsChanged();
  339. }
  340. //
  341. HRESULT GetRS(ADODB::_Recordset **pprs);
  342. enum QueryType {Select, Delete};
  343. HRESULT GetQuery(QueryType qtype, _bstr_t *pbstr);
  344. HRESULT get_DB(CGuideDB **ppdb)
  345. {
  346. m_pdb.CopyTo(ppdb);
  347. return S_OK;
  348. }
  349. HRESULT put_DB(CGuideDB *pdb)
  350. {
  351. m_pdb = pdb;
  352. return S_OK;
  353. }
  354. HRESULT put_ObjectType(CObjectType *pobjtype)
  355. {
  356. #if 0
  357. return pobjtype->QueryInterface(__uuidof(CObjectType), (void **) &m_pobjtype);
  358. #else
  359. m_pobjtype = pobjtype;
  360. return S_OK;
  361. #endif
  362. }
  363. HRESULT get_ObjectType(CObjectType **ppobjtype)
  364. {
  365. if ((*ppobjtype = m_pobjtype))
  366. return S_OK;
  367. return E_FAIL;
  368. }
  369. HRESULT put_MetaPropertyCond(IMetaPropertyCondition *ppropcond)
  370. {
  371. m_ppropcond = ppropcond;
  372. return S_OK;
  373. }
  374. HRESULT InitRelation(IUnknown *pobj, long idRel, boolean fInverse)
  375. {
  376. m_pobjRelated = pobj;
  377. m_idRel = idRel;
  378. m_fInverse = fInverse;
  379. return S_OK;
  380. }
  381. HRESULT get_ItemsRelatedToBy(IUnknown *pobj, IMetaPropertyType *pproptype,
  382. boolean fInverse, IObjects **ppobjs);
  383. HRESULT Remove(IUnknown *pobj);
  384. HRESULT RemoveFromRelationship(IUnknown *pobj);
  385. HRESULT get_ItemsWithType(CObjectType *ptype, /*[out, retval]*/ IObjects * *pVal);
  386. HRESULT put_Key(IMetaPropertyType *pproptype, IGuideDataProvider *pprovider,
  387. long idLang, long vt)
  388. {
  389. CComQIPtr<CMetaPropertyType> pproptypeKey(pproptype);
  390. m_idPropTypeKey = pproptypeKey->GetID();
  391. if (pprovider != NULL)
  392. {
  393. CComQIPtr<CObject> pobj(pprovider);
  394. pobj->get_ID(&m_idProviderKey);
  395. }
  396. m_idLangKey = idLang;
  397. m_vtKey = vt;
  398. return S_OK;
  399. }
  400. // IObjects
  401. public:
  402. STDMETHOD(Resync)()
  403. {
  404. return Reset();
  405. }
  406. STDMETHOD(UnreferencedItems)(/* [out, retval] */ IObjects **ppobjs);
  407. STDMETHOD(RemoveAll)();
  408. STDMETHOD(Reset)();
  409. STDMETHOD(get_ItemsInverseRelatedToBy)(IUnknown *pobj, /* [in] */ IMetaPropertyType *pproptype, /*[out, retval]*/ IObjects **ppobjs);
  410. STDMETHOD(get_ItemsRelatedToBy)(IUnknown *pobj, /* [in] */ IMetaPropertyType *pproptype, /*[out, retval]*/ IObjects **ppobjs);
  411. STDMETHOD(get_ItemsInTimeRange)(DATE dtStart, DATE dtEnd, /*[out, retval]*/ IObjects * *pVal);
  412. STDMETHOD(get_SQLQuery)(/*[out, retval]*/ BSTR *pbstr)
  413. {
  414. ENTER_API
  415. {
  416. ValidateOut(pbstr);
  417. //UNDONE: Remove this method...just for debugging
  418. _bstr_t bstr;
  419. GetQuery(Select, &bstr);
  420. *pbstr = bstr.copy();
  421. return S_OK;
  422. }
  423. LEAVE_API
  424. }
  425. STDMETHOD(Remove)(VARIANT varIndex);
  426. STDMETHOD(AddAt)(IUnknown *pobj, long index);
  427. STDMETHOD(get_AddNew)(/*[out, retval]*/ IUnknown * *pVal);
  428. STDMETHOD(get_AddNewAt)(long index, /*[out, retval]*/ IUnknown * *pVal);
  429. STDMETHOD(get_ItemsWithMetaPropertyCond)(IMetaPropertyCondition *ppropcond, /*[out, retval]*/ IObjects * *pVal);
  430. STDMETHOD(get_ItemsWithMetaProperty)(IMetaProperty *pprop, /*[out, retval]*/ IObjects * *pVal);
  431. STDMETHOD(get_ItemWithID)(long id, /*[out, retval]*/ IUnknown * *pVal);
  432. STDMETHOD(get_ItemsWithType)(BSTR bstrCLSID, /*[out, retval]*/ IObjects * *pVal);
  433. STDMETHOD(get_ItemWithKey)(VARIANT varIndex, /*[out, retval]*/ IUnknown * *pVal);
  434. STDMETHOD(get_ItemsByKey)(IMetaPropertyType *pproptype, IGuideDataProvider *pprovider, long idLang, long vt, IObjects * *pVal);
  435. STDMETHOD(get_Item)(VARIANT varIndex, /*[out, retval]*/ IUnknown * *pVal);
  436. STDMETHOD(get_Count)(/*[out, retval]*/ long *pVal);
  437. #ifdef IMPLEMENT_NewEnum
  438. STDMETHOD(get__NewEnum)(IUnknown **ppunk)
  439. {
  440. ENTER_API
  441. {
  442. ValidateOutPtr<IUnknown>(ppunk, NULL);
  443. return E_NOTIMPL;
  444. }
  445. LEAVE_API
  446. }
  447. #endif
  448. protected:
  449. void CObjects::Copy(CObjects *pobjs)
  450. {
  451. m_pdb = pobjs->m_pdb;
  452. m_ppropcond = pobjs->m_ppropcond;
  453. m_pobjRelated = pobjs->m_pobjRelated;
  454. m_idRel = pobjs->m_idRel;
  455. m_fInverse = pobjs->m_fInverse;
  456. m_fOnlyUnreferenced = pobjs->m_fOnlyUnreferenced;
  457. m_idPropTypeKey = pobjs->m_idPropTypeKey;
  458. m_idProviderKey = pobjs->m_idProviderKey;
  459. m_idLangKey = pobjs->m_idLangKey;
  460. }
  461. CComPtr<CGuideDB> m_pdb;
  462. // All items in this collection are of the type specified by m_pobjtype.
  463. CObjectType *m_pobjtype;
  464. CComPtr<IUnknown> m_punkCollection;
  465. CComPtr<IMetaPropertyCondition> m_ppropcond;
  466. // All the items in this collection are related (or inverse related) to
  467. // m_pobjRelated by the relationship m_idRel.
  468. CComPtr<IUnknown> m_pobjRelated;
  469. long m_idRel;
  470. boolean m_fInverse;
  471. ADODB::_RecordsetPtr m_prs;
  472. long m_cItems;
  473. boolean m_fOnlyUnreferenced;
  474. long m_idChanged;
  475. long m_cChanged;
  476. long m_idPropTypeKey;
  477. long m_idProviderKey;
  478. long m_idLangKey;
  479. long m_vtKey;
  480. };
  481. /////////////////////////////////////////////////////////////////////////////
  482. // CObjectsGlue
  483. template<class T_Collection, class T_Item>
  484. class ATL_NO_VTABLE CObjectsGlue : public IObjectsNotifications
  485. {
  486. public:
  487. typedef CObjectsGlue<T_Collection, T_Item> ThisClass;
  488. CObjectsGlue()
  489. {
  490. }
  491. ~CObjectsGlue()
  492. {
  493. }
  494. // Thunks to IObjects interface of aggregated CLSID_Objects object.
  495. HRESULT _Remove(VARIANT varIndex)
  496. {
  497. HRESULT hr;
  498. CComQIPtr<IObjects> pobjs(this);
  499. hr = pobjs->Remove(varIndex);
  500. return hr;
  501. }
  502. HRESULT _RemoveAll()
  503. {
  504. CComQIPtr<IObjects> pobjs(this);
  505. return pobjs->RemoveAll();
  506. }
  507. HRESULT _Resync()
  508. {
  509. CComQIPtr<IObjects> pobjs(this);
  510. return pobjs->Resync();
  511. }
  512. HRESULT _get_AddNew(T_Item **ppobj)
  513. {
  514. HRESULT hr;
  515. CComQIPtr<IObjects> pobjs(this);
  516. CComPtr<IUnknown> pobj;
  517. hr = pobjs->get_AddNew(&pobj);
  518. if (FAILED(hr))
  519. return hr;
  520. hr = pobj->QueryInterface(__uuidof(T_Item), (void **) ppobj);
  521. return hr;
  522. }
  523. HRESULT _get_AddNewAt(long index, T_Item **ppobj)
  524. {
  525. HRESULT hr;
  526. CComQIPtr<IObjects> pobjs(this);
  527. CComPtr<IUnknown> pobj;
  528. hr = pobjs->get_AddNewAt(index, &pobj);
  529. if (FAILED(hr))
  530. return hr;
  531. hr = pobj->QueryInterface(__uuidof(T_Item), (void **) ppobj);
  532. return hr;
  533. }
  534. HRESULT _AddAt(T_Item *pobj, long index)
  535. {
  536. HRESULT hr;
  537. CComQIPtr<IObjects> pobjs(this);
  538. hr = pobjs->AddAt(pobj, index);
  539. return hr;
  540. }
  541. HRESULT _get_Item(VARIANT varIndex, T_Item **ppobj)
  542. {
  543. CComQIPtr<IObjects> pobjs(this);
  544. CComPtr<IUnknown> pobj;
  545. HRESULT hr = pobjs->get_Item(varIndex, &pobj);
  546. if (FAILED(hr))
  547. return hr;
  548. return pobj->QueryInterface(__uuidof(T_Item), (void **) ppobj);
  549. }
  550. HRESULT _get_ItemWithID(long id, T_Item **ppobj)
  551. {
  552. CComQIPtr<IObjects> pobjs(this);
  553. CComPtr<IUnknown> pobj;
  554. HRESULT hr = pobjs->get_ItemWithID(id, &pobj);
  555. if (FAILED(hr))
  556. return hr;
  557. return pobj->QueryInterface(__uuidof(T_Item), (void **) ppobj);
  558. }
  559. HRESULT _get_ItemWithKey(VARIANT varKey, T_Item **ppobj)
  560. {
  561. CComQIPtr<IObjects> pobjs(this);
  562. CComPtr<IUnknown> pobj;
  563. HRESULT hr = pobjs->get_ItemWithKey(varKey, &pobj);
  564. if (FAILED(hr))
  565. return hr;
  566. return pobj->QueryInterface(__uuidof(T_Item), (void **) ppobj);
  567. }
  568. HRESULT _get_ItemsByKey(IMetaPropertyType *pproptype, IGuideDataProvider *pprovider, long idLang, long vt, T_Collection **ppobjs)
  569. {
  570. CComQIPtr<IObjects> pobjs(this);
  571. CComPtr<IObjects> pobjsNew;
  572. HRESULT hr = pobjs->get_ItemsByKey(pproptype, pprovider, idLang, vt, &pobjsNew);
  573. if (FAILED(hr))
  574. return hr;
  575. return pobjsNew->QueryInterface(__uuidof(T_Collection), (void **) ppobjs);
  576. }
  577. HRESULT _get_ItemsWithMetaPropertyCond(IMetaPropertyCondition *ppropcond, T_Collection **ppobjs)
  578. {
  579. CComQIPtr<IObjects> pobjs(this);
  580. CComPtr<IObjects> pobjsNew;
  581. HRESULT hr = pobjs->get_ItemsWithMetaPropertyCond(ppropcond, &pobjsNew);
  582. if (FAILED(hr))
  583. return hr;
  584. return pobjsNew->QueryInterface(__uuidof(T_Collection), (void **) ppobjs);
  585. }
  586. HRESULT _get_ItemsInTimeRange(DATE dtStart, DATE dtEnd, /*[out, retval]*/ T_Collection * *ppitems)
  587. {
  588. HRESULT hr;
  589. CComQIPtr<IObjects> pobjs(this);
  590. CComPtr<IObjects> pobjsNew;
  591. hr = pobjs->get_ItemsInTimeRange(dtStart, dtEnd, &pobjsNew);
  592. if (FAILED(hr))
  593. return hr;
  594. return pobjsNew->QueryInterface(__uuidof(T_Collection), (void **) ppitems);
  595. }
  596. HRESULT _get_ItemsWithMetaProperty(IMetaProperty *pprop, T_Collection * *ppobjs)
  597. {
  598. CComQIPtr<IObjects> pobjs(this);
  599. CComPtr<IObjects> pobjsNew;
  600. HRESULT hr = pobjs->get_ItemsWithMetaProperty(pprop, &pobjsNew);
  601. if (FAILED(hr))
  602. return hr;
  603. return pobjsNew->QueryInterface(__uuidof(T_Collection), (void **) ppobjs);
  604. }
  605. HRESULT _UnreferencedItems(T_Collection **ppobjs)
  606. {
  607. CComQIPtr<IObjects> pobjs(this);
  608. CComPtr<IObjects> pobjsNew;
  609. HRESULT hr = pobjs->UnreferencedItems(&pobjsNew);
  610. if (FAILED(hr))
  611. return hr;
  612. return pobjsNew->QueryInterface(__uuidof(T_Collection), (void **) ppobjs);
  613. }
  614. HRESULT _get_Count(long *plCount)
  615. {
  616. CComQIPtr<IObjects> pobjs(this);
  617. return pobjs->get_Count(plCount);
  618. }
  619. #ifdef IMPLEMENT_NewEnum
  620. HRESULT _get__NewEnum(IUnknown **ppunk)
  621. {
  622. CComQIPtr<IObjects> pobjs(this);
  623. return pobjs->get__NewEnum(ppunk);
  624. }
  625. #endif
  626. virtual IUnknown *GetControllingUnknown() = 0;
  627. __declspec(property(get=GetDB)) CGuideDB *m_pdb;
  628. CGuideDB *GetDB()
  629. {
  630. CComQIPtr<CObjects> pobjs(GetControllingUnknown());
  631. return pobjs->GetDB();
  632. }
  633. };
  634. class CObjectPropertyBag :
  635. public CComObjectRootEx<CComObjectThreadModel>,
  636. #if SUPPORT_PROPBAG2
  637. public IPropertyBag2,
  638. #endif
  639. public IPropertyBag
  640. {
  641. public:
  642. void Init(IMetaProperties *pprops, IMetaPropertyTypes *pproptypes)
  643. {
  644. m_pprops = pprops;
  645. m_pproptypes = pproptypes;
  646. }
  647. protected:
  648. IMetaProperty * GetProp(_bstr_t bstrPropName, boolean fCreate);
  649. BEGIN_COM_MAP(CObjectPropertyBag)
  650. COM_INTERFACE_ENTRY(IPropertyBag)
  651. #if SUPPORT_PROPBAG2
  652. COM_INTERFACE_ENTRY(IPropertyBag2)
  653. #endif
  654. END_COM_MAP()
  655. // IPropertyBag interface
  656. STDMETHOD(Read)(LPCOLESTR pszPropName, VARIANT *pvar, IErrorLog *pErrorLog);
  657. STDMETHOD(Write)(LPCOLESTR pszPropName, VARIANT *pvar);
  658. #if SUPPORT_PROPBAG2
  659. // IPropertyBag2 interface
  660. STDMETHOD(CountProperties)(long *plCount);
  661. STDMETHOD(GetPropertyInfo)(ULONG iProp, ULONG cProps, PROPBAG2 *ppropbag2, ULONG *pcProps);
  662. STDMETHOD(LoadObject)(LPCOLESTR pstrName, DWORD dwHint, IUnknown *punk, IErrorLog *perrlog);
  663. STDMETHOD(Read)(ULONG cProps, PROPBAG2 *ppropbag2, IErrorLog *perrlog, VARIANT *rgvar, HRESULT *phr);
  664. STDMETHOD(Write)(ULONG cProps, PROPBAG2 *ppropbag2, VARIANT *rgvar);
  665. #endif
  666. protected:
  667. CComPtr<IMetaProperties> m_pprops;
  668. CComPtr<IMetaPropertyTypes> m_pproptypes;
  669. };
  670. #endif //__Object_H_