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.

6505 lines
162 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. events.cpp
  5. Abstract:
  6. This module contains the implementation for the Server
  7. Extension Objects Server Events classes.
  8. Author:
  9. Don Dumitru (dondu@microsoft.com)
  10. Revision History:
  11. dondu 04/04/97 created
  12. --*/
  13. // events.cpp : Implementation of Server Events classes
  14. #include "stdafx.h"
  15. #include <new.h>
  16. #include "seodefs.h"
  17. #include "events.h"
  18. #include "comcat.h"
  19. #include "urlmon.h"
  20. #include "seolib.h"
  21. #include <initguid.h>
  22. // {1EF08720-1E76-11d1-AA29-00AA006BC80B}
  23. DEFINE_GUID(IID_ICreateSinkInfo, 0x1ef08720, 0x1e76, 0x11d1, 0xaa, 0x29, 0x0, 0xaa, 0x0, 0x6b, 0xc8, 0xb);
  24. class CCreateSinkInfo : public IUnknown {
  25. public:
  26. BOOL m_bInit;
  27. BOOL m_bEnabled;
  28. CComBSTR m_strSinkClass;
  29. CComPtr<IUnknown> m_pSink;
  30. CComPtr<IEventPropertyBag> m_pSinkProperties;
  31. };
  32. #define BD_DISPLAYNAME L"DisplayName"
  33. #define BD_BINDINGMANAGERMONIKER L"BindingManagerMoniker"
  34. #define BD_SOURCETYPES L"SourceTypes"
  35. #define BD_SOURCES L"Sources"
  36. #define BD_EVENTTYPES L"EventTypes"
  37. //#define BD_BINDINGS L"Bindings"
  38. #define BD_SINKCLASS L"SinkClass"
  39. #define BD_SINKPROPERTIES L"SinkProperties"
  40. #define BD_SOURCEPROPERTIES L"SourceProperties"
  41. #define BD_ENABLED L"Enabled"
  42. #define BD_EXPIRATION L"Expiration"
  43. #define BD_MAXFIRINGS L"MaxFirings"
  44. #define LOCK_TIMEOUT 15000
  45. #define LOCK_TIMEOUT_SHORT 1000
  46. class CLocker {
  47. public:
  48. CLocker(int iTimeout=LOCK_TIMEOUT) {
  49. m_hrRes = S_OK;
  50. m_iTimeout = iTimeout;
  51. };
  52. ~CLocker() {
  53. Unlock();
  54. };
  55. HRESULT Lock(BOOL bWrite, IEventLock *pLock) {
  56. Unlock();
  57. m_bWrite = bWrite;
  58. m_pLock = pLock;
  59. if (m_pLock) {
  60. m_hrRes = m_bWrite ? m_pLock->LockWrite(m_iTimeout) : m_pLock->LockRead(m_iTimeout);
  61. if (!SUCCEEDED(m_hrRes)) {
  62. m_pLock.Release();
  63. }
  64. }
  65. return (m_hrRes);
  66. };
  67. HRESULT Lock(BOOL bWrite, IUnknown *pUnk) {
  68. CComQIPtr<IEventLock,&IID_IEventLock> pLock;
  69. if (pUnk) {
  70. pLock = pUnk;
  71. }
  72. return (Lock(bWrite,pLock));
  73. };
  74. HRESULT Unlock() {
  75. m_hrRes = S_OK;
  76. if (m_pLock) {
  77. m_hrRes = m_bWrite ? m_pLock->UnlockWrite() : m_pLock->UnlockRead();
  78. _ASSERTE(SUCCEEDED(m_hrRes));
  79. }
  80. m_pLock.Release();
  81. return (m_hrRes);
  82. }
  83. HRESULT LockWrite(IUnknown *pUnk) {
  84. return (Lock(TRUE,pUnk));
  85. };
  86. HRESULT LockRead(IUnknown *pUnk) {
  87. return (Lock(FALSE,pUnk));
  88. };
  89. HRESULT LockWrite(IEventLock *pLock) {
  90. return (Lock(TRUE,pLock));
  91. };
  92. HRESULT LockRead(IEventLock *pLock) {
  93. return (Lock(FALSE,pLock));
  94. };
  95. operator HRESULT() {
  96. return (m_hrRes);
  97. };
  98. private:
  99. CComPtr<IEventLock> m_pLock;
  100. BOOL m_bWrite;
  101. HRESULT m_hrRes;
  102. int m_iTimeout;
  103. };
  104. typedef HRESULT (*CreatorFunc)(LPVOID,REFIID,LPVOID *);
  105. static HRESULT AddImpl1(BSTR pszName, CStringGUID& objGuid, CComVariant *pvarName) {
  106. if (!pvarName) {
  107. _ASSERTE(FALSE);
  108. return (E_FAIL);
  109. }
  110. if (pszName && *pszName) {
  111. objGuid = pszName;
  112. if (!objGuid) {
  113. return (E_INVALIDARG);
  114. }
  115. }
  116. if (!pszName || !*pszName || ((GUID&) objGuid == GUID_NULL)) {
  117. objGuid.CalcNew();
  118. if (!objGuid) {
  119. return (E_FAIL);
  120. }
  121. }
  122. *pvarName = (LPCOLESTR) objGuid;
  123. return (S_OK);
  124. }
  125. static HRESULT AddImpl2(IEventPropertyBag *pDatabase,
  126. CreatorFunc pfnCreator,
  127. REFIID iidDesired,
  128. CComVariant *pvarName,
  129. IUnknown **ppResult) {
  130. HRESULT hrRes;
  131. CComPtr<IEventDatabasePlugin> pPlugIn;
  132. CComPtr<IEventPropertyBag> pNewDatabase;
  133. if (ppResult) {
  134. *ppResult = NULL;
  135. }
  136. if (!pDatabase || !pfnCreator || !pvarName || (pvarName->vt != VT_BSTR)) {
  137. _ASSERTE(FALSE);
  138. return (E_FAIL);
  139. }
  140. if (!ppResult) {
  141. return (E_POINTER);
  142. }
  143. hrRes = pfnCreator(NULL,IID_IEventDatabasePlugin,(LPVOID *) &pPlugIn);
  144. if (!SUCCEEDED(hrRes)) {
  145. return (hrRes);
  146. }
  147. _ASSERTE(pPlugIn);
  148. hrRes = pPlugIn->put_Name(pvarName->bstrVal);
  149. if (!SUCCEEDED(hrRes)) {
  150. return (hrRes);
  151. }
  152. hrRes = pPlugIn->put_Parent(pDatabase);
  153. if (!SUCCEEDED(hrRes)) {
  154. return (hrRes);
  155. }
  156. hrRes = CoCreateInstance(CLSID_CSEOMemDictionary,
  157. NULL,
  158. CLSCTX_ALL,
  159. IID_IEventPropertyBag,
  160. (LPVOID *) &pNewDatabase);
  161. if (!SUCCEEDED(hrRes)) {
  162. return (hrRes);
  163. }
  164. _ASSERTE(pNewDatabase);
  165. hrRes = pPlugIn->put_Database(pNewDatabase);
  166. if (!SUCCEEDED(hrRes)) {
  167. return (hrRes);
  168. }
  169. hrRes = pPlugIn->QueryInterface(iidDesired,(LPVOID *) ppResult);
  170. _ASSERTE(!SUCCEEDED(hrRes)||*ppResult);
  171. return (hrRes);
  172. }
  173. static HRESULT CreateSubPropertyBag(IEventPropertyBag *pBase,
  174. VARIANT *pvarName,
  175. IEventPropertyBag **ppResult,
  176. BOOL bCreate) {
  177. HRESULT hrRes;
  178. CComVariant varValue;
  179. BOOL bTmpCreate = bCreate;
  180. if (ppResult) {
  181. *ppResult = NULL;
  182. }
  183. if (!ppResult || !pBase || !pvarName) {
  184. _ASSERTE(FALSE);
  185. return (E_POINTER);
  186. }
  187. if ((pvarName->vt == VT_EMPTY) || ((pvarName->vt == VT_BSTR) && (SysStringLen(pvarName->bstrVal) == 0))) {
  188. *ppResult = pBase;
  189. (*ppResult)->AddRef();
  190. return (S_OK);
  191. }
  192. again:
  193. hrRes = pBase->Item(pvarName,&varValue);
  194. if (!SUCCEEDED(hrRes)) {
  195. return (hrRes);
  196. }
  197. if ((hrRes == S_FALSE) && !bTmpCreate) {
  198. if (bCreate) {
  199. _ASSERTE(FALSE);
  200. return (E_FAIL);
  201. }
  202. return (S_FALSE);
  203. }
  204. hrRes = varValue.ChangeType(VT_UNKNOWN);
  205. if (!SUCCEEDED(hrRes)) {
  206. if (!bTmpCreate || (pvarName->vt != VT_BSTR)) {
  207. return (hrRes);
  208. }
  209. bTmpCreate = FALSE;
  210. varValue.Clear();
  211. hrRes = CoCreateInstance(CLSID_CSEOMemDictionary,
  212. NULL,
  213. CLSCTX_ALL,
  214. IID_IEventPropertyBag,
  215. (LPVOID *) &varValue.punkVal);
  216. if (!SUCCEEDED(hrRes)) {
  217. _ASSERTE(FALSE);
  218. return (hrRes);
  219. }
  220. _ASSERTE(varValue.punkVal);
  221. varValue.vt = VT_UNKNOWN;
  222. hrRes = pBase->Add(pvarName->bstrVal,&varValue);
  223. if (!SUCCEEDED(hrRes)) {
  224. return (hrRes);
  225. }
  226. goto again;
  227. }
  228. hrRes = varValue.punkVal->QueryInterface(IID_IEventPropertyBag,(LPVOID *) ppResult);
  229. _ASSERTE(!SUCCEEDED(hrRes)||*ppResult);
  230. return (hrRes);
  231. }
  232. static HRESULT SetName(IEventPropertyBag *pBase, VARIANT *pvarSubKey, IEventDatabasePlugin *pObject) {
  233. HRESULT hrRes;
  234. VARIANT varTmp;
  235. long lIndex;
  236. if (!pBase || !pvarSubKey || !pObject) {
  237. _ASSERTE(FALSE);
  238. return (E_POINTER);
  239. }
  240. if (pvarSubKey->vt == VT_BSTR) {
  241. if (!pvarSubKey->bstrVal || !*pvarSubKey->bstrVal) {
  242. return (E_INVALIDARG);
  243. }
  244. return (pObject->put_Name(pvarSubKey->bstrVal));
  245. }
  246. VariantInit(&varTmp);
  247. hrRes = VariantChangeType(&varTmp,pvarSubKey,0,VT_I4);
  248. if (!SUCCEEDED(hrRes)) {
  249. return (hrRes);
  250. }
  251. lIndex = varTmp.lVal;
  252. VariantClear(&varTmp);
  253. hrRes = pBase->Name(lIndex,&varTmp.bstrVal);
  254. if (!SUCCEEDED(hrRes)) {
  255. return (hrRes);
  256. }
  257. varTmp.vt = VT_BSTR;
  258. hrRes = pObject->put_Name(varTmp.bstrVal);
  259. VariantClear(&varTmp);
  260. return (hrRes);
  261. }
  262. static HRESULT CreatePluggedInObject(CreatorFunc pfnCreator,
  263. IEventPropertyBag *pBase,
  264. VARIANT *pvarSubKey,
  265. REFIID iidDesired,
  266. IUnknown **ppUnkResult,
  267. BOOL bCreate) {
  268. HRESULT hrRes;
  269. CComPtr<IEventPropertyBag> pDatabase;
  270. CComPtr<IEventDatabasePlugin> pinitResult;
  271. if (ppUnkResult) {
  272. *ppUnkResult = NULL;
  273. }
  274. if (!ppUnkResult) {
  275. _ASSERTE(FALSE);
  276. return (E_POINTER);
  277. }
  278. if (!pfnCreator || !pBase || !pvarSubKey) {
  279. _ASSERTE(FALSE);
  280. return (E_FAIL);
  281. }
  282. hrRes = CreateSubPropertyBag(pBase,pvarSubKey,&pDatabase,bCreate);
  283. if (!SUCCEEDED(hrRes)) {
  284. return (hrRes);
  285. }
  286. if ((hrRes == S_FALSE) && !bCreate) {
  287. return (S_FALSE);
  288. }
  289. hrRes = pfnCreator(NULL,IID_IEventDatabasePlugin,(LPVOID *) &pinitResult);
  290. if (!SUCCEEDED(hrRes)) {
  291. return (hrRes);
  292. }
  293. _ASSERTE(pinitResult);
  294. hrRes = pinitResult->put_Database(pDatabase);
  295. if (!SUCCEEDED(hrRes)) {
  296. return (hrRes);
  297. }
  298. hrRes = SetName(pBase,pvarSubKey,pinitResult);
  299. if (!SUCCEEDED(hrRes)) {
  300. return (hrRes);
  301. }
  302. hrRes = pinitResult->QueryInterface(iidDesired,(LPVOID *) ppUnkResult);
  303. _ASSERTE(!SUCCEEDED(hrRes)||*ppUnkResult);
  304. return (hrRes);
  305. }
  306. static HRESULT CopyPropertyBagShallow(IEventPropertyBag *pIn, IEventPropertyBag **ppOut, BOOL bLock=TRUE) {
  307. HRESULT hrRes;
  308. CComPtr<IUnknown> pUnkEnum;
  309. CComQIPtr<IEnumVARIANT,&IID_IEnumVARIANT> pEnum;
  310. CComPtr<IEventPropertyBag> pTmp;
  311. CLocker lckRead;
  312. CLocker lckWrite;
  313. if (!pIn || !ppOut) {
  314. _ASSERTE(FALSE);
  315. return (E_POINTER);
  316. }
  317. if (!*ppOut) {
  318. hrRes = CoCreateInstance(CLSID_CSEOMemDictionary,
  319. NULL,
  320. CLSCTX_ALL,
  321. IID_IEventPropertyBag,
  322. (LPVOID *) &pTmp);
  323. if (!SUCCEEDED(hrRes)) {
  324. _ASSERTE(FALSE);
  325. return (hrRes);
  326. }
  327. _ASSERTE(pTmp);
  328. } else {
  329. pTmp = *ppOut;
  330. }
  331. if (bLock) {
  332. if (!SUCCEEDED(lckRead.LockRead(pIn))) {
  333. if ((HRESULT) lckRead == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) {
  334. if (!*ppOut) {
  335. *ppOut = pTmp;
  336. (*ppOut)->AddRef();
  337. }
  338. return (S_OK);
  339. }
  340. return ((HRESULT) lckRead);
  341. }
  342. if (*ppOut && !SUCCEEDED(lckWrite.LockWrite(pTmp))) {
  343. return ((HRESULT) lckWrite);
  344. }
  345. }
  346. hrRes = pIn->get__NewEnum(&pUnkEnum);
  347. if (!SUCCEEDED(hrRes)) {
  348. return (hrRes);
  349. }
  350. _ASSERTE(pUnkEnum);
  351. pEnum = pUnkEnum;
  352. if (!pEnum) {
  353. _ASSERTE(FALSE);
  354. return (E_NOINTERFACE);
  355. }
  356. while (1) {
  357. CComVariant varName;
  358. CComVariant varValue;
  359. varName.Clear();
  360. hrRes = pEnum->Next(1,&varName,NULL);
  361. if (!SUCCEEDED(hrRes)) {
  362. return (hrRes);
  363. }
  364. if (hrRes == S_FALSE) {
  365. break;
  366. }
  367. hrRes = varName.ChangeType(VT_BSTR);
  368. if (!SUCCEEDED(hrRes)) {
  369. return (hrRes);
  370. }
  371. _ASSERTE(varName.bstrVal);
  372. varValue.Clear();
  373. hrRes = pIn->Item(&varName,&varValue);
  374. if (!SUCCEEDED(hrRes)) {
  375. return (hrRes);
  376. }
  377. _ASSERT(hrRes!=S_FALSE);
  378. hrRes = pTmp->Add(varName.bstrVal,&varValue);
  379. if (!SUCCEEDED(hrRes)) {
  380. return (hrRes);
  381. }
  382. }
  383. if (!*ppOut) {
  384. *ppOut = pTmp;
  385. (*ppOut)->AddRef();
  386. }
  387. return (S_OK);
  388. }
  389. static HRESULT CopyPropertyBag(IEventPropertyBag *pIn, IEventPropertyBag **ppOut, BOOL bLock=TRUE, int iTimeout=LOCK_TIMEOUT) {
  390. HRESULT hrRes;
  391. CComPtr<IUnknown> pUnkEnum;
  392. CComQIPtr<IEnumVARIANT,&IID_IEnumVARIANT> pEnum;
  393. CComPtr<IEventPropertyBag> pTmp;
  394. CLocker lckRead(iTimeout);
  395. CLocker lckWrite(iTimeout);
  396. if (!pIn || !ppOut) {
  397. _ASSERTE(FALSE);
  398. return (E_POINTER);
  399. }
  400. if (!*ppOut) {
  401. hrRes = CoCreateInstance(CLSID_CSEOMemDictionary,
  402. NULL,
  403. CLSCTX_ALL,
  404. IID_IEventPropertyBag,
  405. (LPVOID *) &pTmp);
  406. if (!SUCCEEDED(hrRes)) {
  407. _ASSERTE(FALSE);
  408. return (hrRes);
  409. }
  410. _ASSERTE(pTmp);
  411. } else {
  412. pTmp = *ppOut;
  413. }
  414. if (bLock) {
  415. if (!SUCCEEDED(lckRead.LockRead(pIn))) {
  416. if ((HRESULT) lckRead == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)) {
  417. if (!*ppOut) {
  418. *ppOut = pTmp;
  419. (*ppOut)->AddRef();
  420. }
  421. return (S_OK);
  422. }
  423. return ((HRESULT) lckRead);
  424. }
  425. if (*ppOut && !SUCCEEDED(lckWrite.LockWrite(pTmp))) {
  426. return ((HRESULT) lckWrite);
  427. }
  428. }
  429. hrRes = pIn->get__NewEnum(&pUnkEnum);
  430. if (!SUCCEEDED(hrRes)) {
  431. return (hrRes);
  432. }
  433. _ASSERTE(pUnkEnum);
  434. pEnum = pUnkEnum;
  435. if (!pEnum) {
  436. _ASSERTE(FALSE);
  437. return (E_NOINTERFACE);
  438. }
  439. while (1) {
  440. CComVariant varName;
  441. CComVariant varValue;
  442. varName.Clear();
  443. hrRes = pEnum->Next(1,&varName,NULL);
  444. if (!SUCCEEDED(hrRes)) {
  445. return (hrRes);
  446. }
  447. if (hrRes == S_FALSE) {
  448. break;
  449. }
  450. hrRes = varName.ChangeType(VT_BSTR);
  451. if (!SUCCEEDED(hrRes)) {
  452. return (hrRes);
  453. }
  454. _ASSERTE(varName.bstrVal);
  455. varValue.Clear();
  456. hrRes = pIn->Item(&varName,&varValue);
  457. if (!SUCCEEDED(hrRes)) {
  458. return (hrRes);
  459. }
  460. _ASSERT(hrRes!=S_FALSE);
  461. hrRes = varValue.ChangeType(VT_UNKNOWN);
  462. if (SUCCEEDED(hrRes)) {
  463. CComQIPtr<IEventPropertyBag,&IID_IEventPropertyBag> pValue;
  464. pValue = varValue.punkVal;
  465. if (pValue) {
  466. varValue.Clear();
  467. varValue.punkVal = NULL;
  468. hrRes = CopyPropertyBag(pValue,(IEventPropertyBag **) &varValue.punkVal,FALSE);
  469. if (!SUCCEEDED(hrRes)) {
  470. return (hrRes);
  471. }
  472. varValue.vt = VT_UNKNOWN;
  473. }
  474. }
  475. hrRes = pTmp->Add(varName.bstrVal,&varValue);
  476. if (!SUCCEEDED(hrRes)) {
  477. return (hrRes);
  478. }
  479. }
  480. if (!*ppOut) {
  481. *ppOut = pTmp;
  482. (*ppOut)->AddRef();
  483. }
  484. return (S_OK);
  485. }
  486. static HRESULT SaveImpl(BSTR strName, CComPtr<IEventPropertyBag>& pDatabase, CComPtr<IEventPropertyBag>& pTmpDatabase, CComPtr<IEventPropertyBag>& pParent) {
  487. HRESULT hrRes;
  488. if (!strName) {
  489. return (E_POINTER);
  490. }
  491. if (!pDatabase) {
  492. _ASSERTE(FALSE);
  493. return (E_FAIL);
  494. }
  495. if (pParent) {
  496. CComVariant varValue;
  497. if (!pTmpDatabase) {
  498. return (EVENTS_E_BADDATA);
  499. }
  500. varValue = pTmpDatabase;
  501. hrRes = pParent->Add(strName,&varValue);
  502. if (!SUCCEEDED(hrRes)) {
  503. return (hrRes);
  504. }
  505. pTmpDatabase.Release();
  506. pDatabase.Release();
  507. varValue.Clear();
  508. hrRes = pParent->Item(&CComVariant(strName),&varValue);
  509. pParent.Release();
  510. if (!SUCCEEDED(hrRes)) {
  511. return (hrRes);
  512. }
  513. if (hrRes == S_FALSE) {
  514. return (E_FAIL);
  515. }
  516. hrRes = varValue.ChangeType(VT_UNKNOWN);
  517. if (!SUCCEEDED(hrRes)) {
  518. return (hrRes);
  519. }
  520. hrRes = varValue.punkVal->QueryInterface(IID_IEventPropertyBag,(LPVOID *) &pDatabase);
  521. if (!SUCCEEDED(hrRes)) {
  522. return (hrRes);
  523. }
  524. return (S_OK);
  525. }
  526. if (!pTmpDatabase) {
  527. return (S_OK);
  528. }
  529. hrRes = CopyPropertyBagShallow(pTmpDatabase,&pDatabase.p);
  530. if (!SUCCEEDED(hrRes)) {
  531. return (hrRes);
  532. }
  533. pTmpDatabase.Release();
  534. return (S_OK);
  535. }
  536. static HRESULT NextOfUnknown(IUnknown *pUnkEnum,
  537. IEventPropertyBag *pCollection,
  538. IUnknown **apunkElt,
  539. BSTR *astrNames,
  540. ULONG celt,
  541. ULONG *pceltFetched,
  542. REFIID riidDesired) {
  543. CComQIPtr<IEnumString,&IID_IEnumString> pEnumString;
  544. CComQIPtr<IEnumVARIANT,&IID_IEnumVARIANT> pEnumVARIANT;
  545. DWORD dwIdx;
  546. VARIANT *pvarTmp;
  547. DWORD dwTmpStored;
  548. HRESULT hrRes;
  549. if (pceltFetched) {
  550. *pceltFetched = 0;
  551. }
  552. if (apunkElt) {
  553. memset(apunkElt,0,sizeof(IUnknown *)*celt);
  554. }
  555. if (astrNames) {
  556. memset(astrNames,0,sizeof(BSTR)*celt);
  557. }
  558. if (!apunkElt || !astrNames) {
  559. _ASSERTE(FALSE);
  560. return (E_OUTOFMEMORY);
  561. }
  562. if (!pUnkEnum || !pCollection) {
  563. _ASSERTE(FALSE);
  564. return (E_POINTER);
  565. }
  566. if (!celt) {
  567. return (S_OK);
  568. }
  569. dwTmpStored = 0;
  570. pEnumString = pUnkEnum;
  571. if (!pEnumString) {
  572. pEnumVARIANT = pUnkEnum;
  573. if (!pEnumVARIANT) {
  574. return (E_NOINTERFACE);
  575. }
  576. pvarTmp = (VARIANT *) _alloca(sizeof(VARIANT)*celt);
  577. if (!pvarTmp) {
  578. return (E_OUTOFMEMORY);
  579. }
  580. memset(pvarTmp,0,sizeof(pvarTmp[0])*celt);
  581. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  582. VariantInit(&pvarTmp[dwIdx]);
  583. }
  584. }
  585. while (dwTmpStored < celt) {
  586. DWORD dwTmpFetched;
  587. DWORD dwInnerTmpStored;
  588. HRESULT hrInnerRes;
  589. if (pEnumString) {
  590. hrRes = pEnumString->Next(celt-dwTmpStored,(LPWSTR *) &astrNames[dwTmpStored],&dwTmpFetched);
  591. if (SUCCEEDED(hrRes)) {
  592. for (dwIdx=0;dwIdx<dwTmpFetched;dwIdx++) {
  593. BSTR strTmp;
  594. strTmp = SysAllocString(astrNames[dwIdx]);
  595. if (astrNames[dwIdx] && !strTmp) {
  596. hrRes = E_OUTOFMEMORY;
  597. }
  598. CoTaskMemFree(astrNames[dwIdx]);
  599. astrNames[dwIdx] = strTmp;
  600. }
  601. }
  602. } else {
  603. hrRes = pEnumVARIANT->Next(celt-dwTmpStored,&pvarTmp[dwTmpStored],&dwTmpFetched);
  604. if (SUCCEEDED(hrRes)) {
  605. for (dwIdx=0;dwIdx<dwTmpFetched;dwIdx++) {
  606. hrInnerRes = VariantChangeType(&pvarTmp[dwTmpStored+dwIdx],
  607. &pvarTmp[dwTmpStored+dwIdx],
  608. 0,
  609. VT_BSTR);
  610. if (!SUCCEEDED(hrInnerRes)) {
  611. hrRes = hrInnerRes;
  612. break;
  613. }
  614. _ASSERTE(pvarTmp[dwTmpStored+dwIdx].bstrVal);
  615. astrNames[dwTmpStored+dwIdx] = pvarTmp[dwTmpStored+dwIdx].bstrVal;
  616. VariantInit(&pvarTmp[dwTmpStored+dwIdx]);
  617. }
  618. for (dwIdx=0;dwIdx<dwTmpFetched;dwIdx++) {
  619. VariantClear(&pvarTmp[dwIdx]);
  620. }
  621. }
  622. }
  623. if (!SUCCEEDED(hrRes) || !dwTmpFetched) {
  624. break;
  625. }
  626. dwInnerTmpStored = 0;
  627. for (dwIdx=0;dwIdx<dwTmpFetched;dwIdx++) {
  628. CComVariant varTmp;
  629. varTmp.Clear();
  630. hrRes = pCollection->Item(&CComVariant(astrNames[dwTmpStored+dwIdx]),&varTmp);
  631. if (!SUCCEEDED(hrRes)) {
  632. break;
  633. }
  634. hrInnerRes = varTmp.ChangeType(VT_UNKNOWN);
  635. if (SUCCEEDED(hrInnerRes)) {
  636. _ASSERTE(varTmp.punkVal);
  637. hrInnerRes = varTmp.punkVal->QueryInterface(riidDesired,
  638. (LPVOID *) &apunkElt[dwTmpStored+dwInnerTmpStored]);
  639. }
  640. _ASSERTE(!SUCCEEDED(hrInnerRes)||apunkElt[dwTmpStored+dwInnerTmpStored]);
  641. if (!SUCCEEDED(hrInnerRes)) {
  642. SysFreeString(astrNames[dwTmpStored+dwIdx]);
  643. memcpy(&astrNames[dwTmpStored+dwIdx],
  644. &astrNames[dwTmpStored+dwIdx+1],
  645. (dwTmpFetched-dwIdx-1)*sizeof(BSTR));
  646. memset(astrNames[dwTmpStored+dwTmpFetched-1],0,sizeof(BSTR));
  647. dwTmpFetched--;
  648. dwIdx--;
  649. dwInnerTmpStored--;
  650. }
  651. dwInnerTmpStored++;
  652. }
  653. dwTmpStored += dwInnerTmpStored;
  654. }
  655. if (!SUCCEEDED(hrRes)) {
  656. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  657. SysFreeString(astrNames[dwIdx]);
  658. if (apunkElt[dwIdx]) {
  659. apunkElt[dwIdx]->Release();
  660. apunkElt[dwIdx] = NULL;
  661. }
  662. }
  663. return (hrRes);
  664. }
  665. if (pceltFetched) {
  666. *pceltFetched = dwTmpStored;
  667. }
  668. return ((dwTmpStored==celt)?S_OK:S_FALSE);
  669. }
  670. /////////////////////////////////////////////////////////////////////////////
  671. // IEventEnumBase
  672. class ATL_NO_VTABLE IEventEnumBase
  673. {
  674. public:
  675. virtual HRESULT SetEnum(IUnknown *punkEnum, IEventPropertyBag *pCollection) = 0;
  676. virtual IUnknown *GetEnum() = 0;
  677. virtual IEventPropertyBag *GetCollection() = 0;
  678. virtual HRESULT MakeNewObject(REFIID iidDesired, LPVOID *ppvObject) = 0;
  679. HRESULT BaseSkip(ULONG celt);
  680. HRESULT BaseReset();
  681. };
  682. HRESULT IEventEnumBase::BaseSkip(ULONG celt) {
  683. CComQIPtr<IEnumUnknown,&IID_IEnumUnknown> pEnumUnknown;
  684. CComQIPtr<IEnumVARIANT,&IID_IEnumVARIANT> pEnumVARIANT;
  685. pEnumUnknown = GetEnum();
  686. if (pEnumUnknown) {
  687. return (pEnumUnknown->Skip(celt));
  688. }
  689. pEnumVARIANT = GetEnum();
  690. if (!pEnumVARIANT) {
  691. return (pEnumVARIANT->Skip(celt));
  692. }
  693. _ASSERTE(FALSE);
  694. return (E_NOINTERFACE);
  695. }
  696. HRESULT IEventEnumBase::BaseReset() {
  697. CComQIPtr<IEnumUnknown,&IID_IEnumUnknown> pEnumUnknown;
  698. CComQIPtr<IEnumVARIANT,&IID_IEnumVARIANT> pEnumVARIANT;
  699. pEnumUnknown = GetEnum();
  700. if (pEnumUnknown) {
  701. return (pEnumUnknown->Reset());
  702. }
  703. pEnumVARIANT = GetEnum();
  704. if (!pEnumVARIANT) {
  705. return (pEnumVARIANT->Reset());
  706. }
  707. _ASSERTE(FALSE);
  708. return (E_NOINTERFACE);
  709. }
  710. /////////////////////////////////////////////////////////////////////////////
  711. // CEventEnumUnknownBase
  712. class ATL_NO_VTABLE CEventEnumUnknownBase :
  713. public IEventEnumBase,
  714. public IEnumUnknown
  715. {
  716. public:
  717. HRESULT STDMETHODCALLTYPE Next(ULONG celt, IUnknown **apunkElt, ULONG *pceltFetched);
  718. HRESULT STDMETHODCALLTYPE Skip(ULONG celt);
  719. HRESULT STDMETHODCALLTYPE Reset();
  720. HRESULT STDMETHODCALLTYPE Clone(IEnumUnknown **ppEnum);
  721. protected:
  722. virtual HRESULT MakeNewEnumUnknown(IUnknown *pContained,
  723. IEventPropertyBag *pCollection,
  724. IEnumUnknown **ppNewEnum) = 0;
  725. };
  726. /////////////////////////////////////////////////////////////////////////////
  727. // CEventEnumUnknownBase
  728. HRESULT STDMETHODCALLTYPE CEventEnumUnknownBase::Next(ULONG celt, IUnknown **apunkElt, ULONG *pceltFetched) {
  729. HRESULT hrRes;
  730. IEventPropertyBag **ppTmp;
  731. BSTR *pstrTmp;
  732. DWORD dwTmpFetched;
  733. DWORD dwIdx;
  734. if (pceltFetched) {
  735. *pceltFetched = 0;
  736. }
  737. if (apunkElt) {
  738. memset(apunkElt,0,sizeof(IUnknown *)*celt);
  739. }
  740. if (!apunkElt) {
  741. _ASSERTE(FALSE);
  742. return (E_POINTER);
  743. }
  744. if (!celt) {
  745. return (S_OK);
  746. }
  747. ppTmp = (IEventPropertyBag **) _alloca(sizeof(IEventPropertyBag *)*celt);
  748. pstrTmp = (BSTR *) _alloca(sizeof(BSTR)*celt);
  749. hrRes = NextOfUnknown(GetEnum(),
  750. GetCollection(),
  751. (IUnknown **) ppTmp,
  752. pstrTmp,
  753. celt,
  754. &dwTmpFetched,
  755. IID_IEventPropertyBag);
  756. if (!SUCCEEDED(hrRes)) {
  757. return (hrRes);
  758. }
  759. for (dwIdx=0;dwIdx<dwTmpFetched;dwIdx++) {
  760. hrRes = MakeNewObject(IID_IEventDatabasePlugin,(LPVOID *) &apunkElt[dwIdx]);
  761. if (SUCCEEDED(hrRes)) {
  762. _ASSERTE(apunkElt[dwIdx]);
  763. hrRes = ((IEventDatabasePlugin *) apunkElt[dwIdx])->put_Database(ppTmp[dwIdx]);
  764. if (SUCCEEDED(hrRes)) {
  765. hrRes = ((IEventDatabasePlugin *) apunkElt[dwIdx])->put_Name(pstrTmp[dwIdx]);
  766. }
  767. }
  768. if (!SUCCEEDED(hrRes)) {
  769. for (dwIdx=0;dwIdx<dwTmpFetched;dwIdx++) {
  770. if (apunkElt[dwIdx]) {
  771. apunkElt[dwIdx]->Release();
  772. apunkElt[dwIdx] = NULL;
  773. }
  774. }
  775. break;
  776. }
  777. }
  778. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  779. SysFreeString(pstrTmp[dwIdx]);
  780. if (ppTmp[dwIdx]) {
  781. ppTmp[dwIdx]->Release();
  782. }
  783. }
  784. if (!SUCCEEDED(hrRes)) {
  785. return (hrRes);
  786. }
  787. if (pceltFetched) {
  788. *pceltFetched = dwTmpFetched;
  789. }
  790. return ((dwTmpFetched<celt)?S_FALSE:S_OK);
  791. }
  792. HRESULT STDMETHODCALLTYPE CEventEnumUnknownBase::Skip(ULONG celt) {
  793. return (BaseSkip(celt));
  794. }
  795. HRESULT STDMETHODCALLTYPE CEventEnumUnknownBase::Reset() {
  796. return (BaseReset());
  797. }
  798. HRESULT STDMETHODCALLTYPE CEventEnumUnknownBase::Clone(IEnumUnknown **ppEnum) {
  799. HRESULT hrRes;
  800. CComQIPtr<IEnumUnknown,&IID_IEnumUnknown> pThisEnumUnknown;
  801. CComQIPtr<IEnumVARIANT,&IID_IEnumVARIANT> pThisEnumVARIANT;
  802. CComPtr<IUnknown> pClone;
  803. if (ppEnum) {
  804. *ppEnum = NULL;
  805. }
  806. if (!ppEnum) {
  807. _ASSERTE(FALSE);
  808. return (E_POINTER);
  809. }
  810. pThisEnumUnknown = GetEnum();
  811. if (pThisEnumUnknown) {
  812. hrRes = pThisEnumUnknown->Clone((IEnumUnknown **) &pClone);
  813. } else {
  814. pThisEnumVARIANT = GetEnum();
  815. if (pThisEnumVARIANT) {
  816. hrRes = pThisEnumVARIANT->Clone((IEnumVARIANT **) &pClone);
  817. } else {
  818. _ASSERTE(FALSE);
  819. hrRes = E_NOINTERFACE;
  820. }
  821. }
  822. if (!SUCCEEDED(hrRes)) {
  823. return (hrRes);
  824. }
  825. _ASSERTE(pClone);
  826. hrRes = MakeNewEnumUnknown(pClone,GetCollection(),ppEnum);
  827. if (!SUCCEEDED(hrRes)) {
  828. return (hrRes);
  829. }
  830. return (S_OK);
  831. }
  832. /////////////////////////////////////////////////////////////////////////////
  833. // CEventEnumUnknownBaseImpl
  834. template <class ObjectClass, class EnumClass>
  835. class ATL_NO_VTABLE CEventEnumUnknownBaseImpl :
  836. public CEventEnumUnknownBase
  837. {
  838. protected:
  839. virtual HRESULT MakeNewObject(REFIID iidDesired, LPVOID *ppvObject) {
  840. return (CComObject<ObjectClass>::_CreatorClass::CreateInstance(NULL,iidDesired,ppvObject));
  841. }
  842. virtual HRESULT MakeNewEnumUnknown(IUnknown *pContained,
  843. IEventPropertyBag *pCollection,
  844. IEnumUnknown **ppNewEnum) {
  845. HRESULT hrRes;
  846. CComObject<EnumClass> *pTmp;
  847. if (ppNewEnum) {
  848. *ppNewEnum = NULL;
  849. }
  850. if (!ppNewEnum || !pContained || !pCollection) {
  851. _ASSERTE(FALSE);
  852. return (E_POINTER);
  853. }
  854. hrRes = CComObject<EnumClass>::CreateInstance(&pTmp);
  855. if (!SUCCEEDED(hrRes)) {
  856. return (hrRes);
  857. }
  858. _ASSERTE(pTmp);
  859. pTmp->AddRef();
  860. hrRes = pTmp->SetEnum(pContained,pCollection);
  861. if (SUCCEEDED(hrRes)) {
  862. hrRes = pTmp->QueryInterface(IID_IEnumUnknown,(LPVOID *) ppNewEnum);
  863. _ASSERTE(!SUCCEEDED(hrRes)||*ppNewEnum);
  864. }
  865. pTmp->Release();
  866. return (hrRes);
  867. };
  868. };
  869. /////////////////////////////////////////////////////////////////////////////
  870. // CEventEnumVARIANTBase
  871. class ATL_NO_VTABLE CEventEnumVARIANTBase :
  872. public IEventEnumBase,
  873. public IEnumVARIANT
  874. {
  875. public:
  876. HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT *avarElt, ULONG *pceltFetched);
  877. HRESULT STDMETHODCALLTYPE Skip(ULONG celt);
  878. HRESULT STDMETHODCALLTYPE Reset();
  879. HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT **ppEnum);
  880. protected:
  881. virtual HRESULT MakeNewEnumVARIANT(IUnknown *pContained,
  882. IEventPropertyBag *pCollection,
  883. IEnumVARIANT **ppNewEnum) = 0;
  884. };
  885. /////////////////////////////////////////////////////////////////////////////
  886. // CEventEnumVARIANTBase
  887. HRESULT STDMETHODCALLTYPE CEventEnumVARIANTBase::Next(ULONG celt, VARIANT *avarElt, ULONG *pceltFetched) {
  888. HRESULT hrRes;
  889. IEventPropertyBag **ppTmp;
  890. BSTR *pstrTmp;
  891. DWORD dwTmpFetched;
  892. DWORD dwIdx;
  893. if (pceltFetched) {
  894. *pceltFetched = 0;
  895. }
  896. if (avarElt) {
  897. memset(avarElt,0,sizeof(avarElt[0])*celt);
  898. }
  899. if (!avarElt) {
  900. return (E_POINTER);
  901. }
  902. #if 0
  903. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  904. VariantInit(&avarElt[dwIdx]);
  905. }
  906. #endif
  907. if (!celt) {
  908. return (S_OK);
  909. }
  910. ppTmp = (IEventPropertyBag **) _alloca(sizeof(IEventPropertyBag *)*celt);
  911. pstrTmp = (BSTR *) _alloca(sizeof(BSTR)*celt);
  912. hrRes = NextOfUnknown(GetEnum(),
  913. GetCollection(),
  914. (IUnknown **) ppTmp,
  915. pstrTmp,
  916. celt,
  917. &dwTmpFetched,
  918. IID_IEventPropertyBag);
  919. if (!SUCCEEDED(hrRes)) {
  920. return (hrRes);
  921. }
  922. for (dwIdx=0;dwIdx<dwTmpFetched;dwIdx++) {
  923. hrRes = MakeNewObject(IID_IEventDatabasePlugin,(LPVOID *) &avarElt[dwIdx].punkVal);
  924. if (SUCCEEDED(hrRes)) {
  925. _ASSERTE(avarElt[dwIdx].punkVal);
  926. avarElt[dwIdx].vt = VT_UNKNOWN;
  927. hrRes = ((IEventDatabasePlugin *) avarElt[dwIdx].punkVal)->put_Database(ppTmp[dwIdx]);
  928. if (SUCCEEDED(hrRes)) {
  929. hrRes = ((IEventDatabasePlugin *) avarElt[dwIdx].punkVal)->put_Name(pstrTmp[dwIdx]);
  930. }
  931. }
  932. if (!SUCCEEDED(hrRes)) {
  933. for (dwIdx=0;dwIdx<dwTmpFetched;dwIdx++) {
  934. VariantClear(&avarElt[dwIdx]);
  935. }
  936. break;
  937. }
  938. if (SUCCEEDED(hrRes)) {
  939. hrRes = VariantChangeType(&avarElt[dwIdx],&avarElt[dwIdx],0,VT_DISPATCH);
  940. _ASSERTE(SUCCEEDED(hrRes));
  941. }
  942. }
  943. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  944. SysFreeString(pstrTmp[dwIdx]);
  945. if (ppTmp[dwIdx]) {
  946. ppTmp[dwIdx]->Release();
  947. }
  948. }
  949. if (!SUCCEEDED(hrRes)) {
  950. return (hrRes);
  951. }
  952. if (pceltFetched) {
  953. *pceltFetched = dwTmpFetched;
  954. }
  955. return ((dwTmpFetched<celt)?S_FALSE:S_OK);
  956. }
  957. HRESULT STDMETHODCALLTYPE CEventEnumVARIANTBase::Skip(ULONG celt) {
  958. return (BaseSkip(celt));
  959. }
  960. HRESULT STDMETHODCALLTYPE CEventEnumVARIANTBase::Reset() {
  961. return (BaseReset());
  962. }
  963. HRESULT STDMETHODCALLTYPE CEventEnumVARIANTBase::Clone(IEnumVARIANT **ppEnum) {
  964. HRESULT hrRes;
  965. CComQIPtr<IEnumUnknown,&IID_IEnumUnknown> pThisEnumUnknown;
  966. CComQIPtr<IEnumVARIANT,&IID_IEnumVARIANT> pThisEnumVARIANT;
  967. CComPtr<IUnknown> pClone;
  968. if (ppEnum) {
  969. *ppEnum = NULL;
  970. }
  971. if (!ppEnum) {
  972. return (E_POINTER);
  973. }
  974. pThisEnumUnknown = GetEnum();
  975. if (pThisEnumUnknown) {
  976. hrRes = pThisEnumUnknown->Clone((IEnumUnknown **) &pClone);
  977. } else {
  978. pThisEnumVARIANT = GetEnum();
  979. if (pThisEnumVARIANT) {
  980. hrRes = pThisEnumVARIANT->Clone((IEnumVARIANT **) &pClone);
  981. } else {
  982. _ASSERTE(FALSE);
  983. hrRes = E_NOINTERFACE;
  984. }
  985. }
  986. if (!SUCCEEDED(hrRes)) {
  987. return (hrRes);
  988. }
  989. _ASSERTE(pClone);
  990. hrRes = MakeNewEnumVARIANT(pClone,GetCollection(),ppEnum);
  991. if (!SUCCEEDED(hrRes)) {
  992. return (hrRes);
  993. }
  994. _ASSERTE(*ppEnum);
  995. return (S_OK);
  996. }
  997. /////////////////////////////////////////////////////////////////////////////
  998. // CEventEnumVARIANTBaseImpl
  999. template <class ObjectClass, class EnumClass>
  1000. class ATL_NO_VTABLE CEventEnumVARIANTBaseImpl :
  1001. public CEventEnumVARIANTBase
  1002. {
  1003. protected:
  1004. virtual HRESULT MakeNewObject(REFIID iidDesired, LPVOID *ppvObject) {
  1005. return (CComObject<ObjectClass>::_CreatorClass::CreateInstance(NULL,iidDesired,ppvObject));
  1006. }
  1007. virtual HRESULT MakeNewEnumVARIANT(IUnknown *pContained,
  1008. IEventPropertyBag *pCollection,
  1009. IEnumVARIANT **ppNewEnum) {
  1010. HRESULT hrRes;
  1011. CComObject<EnumClass> *pTmp;
  1012. if (ppNewEnum) {
  1013. *ppNewEnum = NULL;
  1014. }
  1015. if (!ppNewEnum || !pContained || !pCollection) {
  1016. _ASSERTE(FALSE);
  1017. return (E_POINTER);
  1018. }
  1019. hrRes = CComObject<EnumClass>::CreateInstance(&pTmp);
  1020. if (!SUCCEEDED(hrRes)) {
  1021. return (hrRes);
  1022. }
  1023. _ASSERTE(pTmp);
  1024. pTmp->AddRef();
  1025. hrRes = pTmp->SetEnum(pContained,pCollection);
  1026. if (SUCCEEDED(hrRes)) {
  1027. hrRes = pTmp->QueryInterface(IID_IEnumVARIANT,(LPVOID *) ppNewEnum);
  1028. _ASSERTE(!SUCCEEDED(hrRes)||*ppNewEnum);
  1029. }
  1030. pTmp->Release();
  1031. return (hrRes);
  1032. };
  1033. };
  1034. /////////////////////////////////////////////////////////////////////////////
  1035. // CEventTypeSinksEnum
  1036. class ATL_NO_VTABLE CEventTypeSinksEnum :
  1037. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  1038. public IEnumVARIANT,
  1039. public IEnumString
  1040. {
  1041. DEBUG_OBJECT_DEF(CEventTypeSinksEnum)
  1042. public:
  1043. HRESULT FinalConstruct();
  1044. void FinalRelease();
  1045. HRESULT Load(IEventTypeSinks *pSinks, DWORD dwIdx);
  1046. static HRESULT Create(IEventTypeSinks *pSinks,
  1047. DWORD dwIdx,
  1048. REFIID iidDesired,
  1049. LPVOID *ppvResult);
  1050. DECLARE_PROTECT_FINAL_CONSTRUCT();
  1051. DECLARE_NOT_AGGREGATABLE(CEventTypeSinksEnum);
  1052. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  1053. // L"EventTypeSinksEnum Class",
  1054. // L"Event.TypeSinksEnum.1",
  1055. // L"Event.TypeSinksEnum");
  1056. DECLARE_GET_CONTROLLING_UNKNOWN();
  1057. BEGIN_COM_MAP(CEventTypeSinksEnum)
  1058. COM_INTERFACE_ENTRY(IEnumVARIANT)
  1059. COM_INTERFACE_ENTRY(IEnumString)
  1060. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  1061. END_COM_MAP()
  1062. // IEnumXXXX
  1063. public:
  1064. HRESULT STDMETHODCALLTYPE Skip(ULONG celt);
  1065. HRESULT STDMETHODCALLTYPE Reset();
  1066. // IEnumVARIANT
  1067. public:
  1068. HRESULT STDMETHODCALLTYPE Next(ULONG celt, VARIANT *avarElt, ULONG *pceltFetched);
  1069. HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT **ppEnum);
  1070. // IEnumString
  1071. public:
  1072. HRESULT STDMETHODCALLTYPE Next(ULONG celt, LPWSTR *apszElt, ULONG *pceltFetched);
  1073. HRESULT STDMETHODCALLTYPE Clone(IEnumString **ppEnum);
  1074. private:
  1075. DWORD m_dwIdx;
  1076. CComPtr<IEventTypeSinks> m_pSinks;
  1077. CComPtr<IUnknown> m_pUnkMarshaler;
  1078. };
  1079. /////////////////////////////////////////////////////////////////////////////
  1080. // CEventTypeSinksEnum
  1081. HRESULT CEventTypeSinksEnum::FinalConstruct() {
  1082. DEBUG_OBJECT_CHECK
  1083. TraceFunctEnter("CEventTypeSinksEnum::FinalConstruct");
  1084. HRESULT hrRes = S_OK;
  1085. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  1086. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  1087. ADD_DEBUG_OBJECT("CEventTypeSinksEnum")
  1088. TraceFunctLeave();
  1089. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  1090. }
  1091. void CEventTypeSinksEnum::FinalRelease() {
  1092. DEBUG_OBJECT_CHECK
  1093. TraceFunctEnter("CEventTypeSinksEnum::FinalRelease");
  1094. m_pSinks.Release();
  1095. m_pUnkMarshaler.Release();
  1096. REMOVE_DEBUG_OBJECT
  1097. TraceFunctLeave();
  1098. }
  1099. HRESULT CEventTypeSinksEnum::Load(IEventTypeSinks *pSinks, DWORD dwIdx) {
  1100. DEBUG_OBJECT_CHECK
  1101. if (!pSinks) {
  1102. return (E_POINTER);
  1103. }
  1104. m_pSinks = pSinks;
  1105. m_dwIdx = dwIdx;
  1106. return (S_OK);
  1107. }
  1108. HRESULT CEventTypeSinksEnum::Create(IEventTypeSinks *pSinks,
  1109. DWORD dwIdx,
  1110. REFIID iidDesired,
  1111. LPVOID *ppvResult) {
  1112. HRESULT hrRes;
  1113. CComObject<CEventTypeSinksEnum> *pEnum;
  1114. if (ppvResult) {
  1115. *ppvResult = NULL;
  1116. }
  1117. if (!pSinks) {
  1118. return (E_FAIL);
  1119. }
  1120. if (!ppvResult) {
  1121. return (E_POINTER);
  1122. }
  1123. hrRes = CComObject<CEventTypeSinksEnum>::CreateInstance(&pEnum);
  1124. if (!SUCCEEDED(hrRes)) {
  1125. return (hrRes);
  1126. }
  1127. pEnum->AddRef();
  1128. hrRes = pEnum->Load(pSinks,dwIdx);
  1129. if (SUCCEEDED(hrRes)) {
  1130. hrRes = pEnum->QueryInterface(IID_IEnumVARIANT,ppvResult);
  1131. }
  1132. pEnum->Release();
  1133. if (!SUCCEEDED(hrRes)) {
  1134. return (hrRes);
  1135. }
  1136. return (S_OK);
  1137. }
  1138. HRESULT STDMETHODCALLTYPE CEventTypeSinksEnum::Skip(ULONG celt) {
  1139. DEBUG_OBJECT_CHECK
  1140. HRESULT hrRes;
  1141. long lCount;
  1142. _ASSERTE(m_pSinks);
  1143. if (!m_pSinks) {
  1144. return (E_FAIL);
  1145. }
  1146. hrRes = m_pSinks->get_Count(&lCount);
  1147. if (!SUCCEEDED(hrRes)) {
  1148. return (hrRes);
  1149. }
  1150. _ASSERTE(lCount>=0);
  1151. if (lCount < 0) {
  1152. return (E_FAIL);
  1153. }
  1154. m_dwIdx += celt;
  1155. if (m_dwIdx > (DWORD) lCount) {
  1156. m_dwIdx = lCount;
  1157. return (S_FALSE);
  1158. }
  1159. return (S_OK);
  1160. }
  1161. HRESULT STDMETHODCALLTYPE CEventTypeSinksEnum::Reset() {
  1162. DEBUG_OBJECT_CHECK
  1163. _ASSERTE(m_pSinks);
  1164. if (!m_pSinks) {
  1165. return (E_FAIL);
  1166. }
  1167. m_dwIdx = 0;
  1168. return (S_OK);
  1169. }
  1170. HRESULT STDMETHODCALLTYPE CEventTypeSinksEnum::Next(ULONG celt, VARIANT *avarElt, ULONG *pceltFetched) {
  1171. DEBUG_OBJECT_CHECK
  1172. HRESULT hrRes;
  1173. DWORD dwIdx;
  1174. if (avarElt) {
  1175. memset(avarElt,0,sizeof(avarElt[0])*celt);
  1176. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  1177. VariantInit(&avarElt[dwIdx]);
  1178. }
  1179. }
  1180. if (pceltFetched) {
  1181. *pceltFetched = 0;
  1182. }
  1183. _ASSERTE(m_pSinks);
  1184. if (!m_pSinks) {
  1185. return (E_FAIL);
  1186. }
  1187. if (!avarElt) {
  1188. return (E_POINTER);
  1189. }
  1190. if (!celt) {
  1191. return (S_OK);
  1192. }
  1193. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  1194. hrRes = m_pSinks->Item(m_dwIdx+dwIdx+1,&avarElt[dwIdx].bstrVal);
  1195. if (!SUCCEEDED(hrRes)) {
  1196. break;
  1197. }
  1198. if (hrRes == S_FALSE) {
  1199. break;
  1200. }
  1201. avarElt[dwIdx].vt = VT_BSTR;
  1202. }
  1203. if (!SUCCEEDED(hrRes)) {
  1204. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  1205. VariantClear(&avarElt[dwIdx]);
  1206. }
  1207. return (hrRes);
  1208. }
  1209. m_dwIdx += dwIdx;
  1210. if (pceltFetched) {
  1211. *pceltFetched = dwIdx;
  1212. }
  1213. if (hrRes == S_FALSE) {
  1214. return (S_FALSE);
  1215. }
  1216. return (S_OK);
  1217. }
  1218. HRESULT STDMETHODCALLTYPE CEventTypeSinksEnum::Clone(IEnumVARIANT **ppEnum) {
  1219. DEBUG_OBJECT_CHECK
  1220. return (Create(m_pSinks,m_dwIdx,IID_IEnumVARIANT,(LPVOID *) ppEnum));
  1221. }
  1222. HRESULT STDMETHODCALLTYPE CEventTypeSinksEnum::Next(ULONG celt, LPWSTR *apszElt, ULONG *pceltFetched) {
  1223. DEBUG_OBJECT_CHECK
  1224. HRESULT hrRes;
  1225. DWORD dwIdx;
  1226. if (apszElt) {
  1227. memset(apszElt,0,sizeof(*apszElt)*celt);
  1228. }
  1229. if (pceltFetched) {
  1230. *pceltFetched = 0;
  1231. }
  1232. _ASSERTE(m_pSinks);
  1233. if (!m_pSinks) {
  1234. return (E_FAIL);
  1235. }
  1236. if (!apszElt) {
  1237. return (E_POINTER);
  1238. }
  1239. if (!celt) {
  1240. return (S_OK);
  1241. }
  1242. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  1243. CComBSTR bstrVal;
  1244. bstrVal.Empty();
  1245. hrRes = m_pSinks->Item(m_dwIdx+dwIdx+1,&bstrVal);
  1246. if (!SUCCEEDED(hrRes)) {
  1247. break;
  1248. }
  1249. if (hrRes == S_FALSE) {
  1250. break;
  1251. }
  1252. apszElt[dwIdx] = (LPWSTR) CoTaskMemAlloc(sizeof(WCHAR)*(wcslen(bstrVal)+1));
  1253. if (!apszElt[dwIdx]) {
  1254. hrRes = E_OUTOFMEMORY;
  1255. break;
  1256. }
  1257. wcscpy(apszElt[dwIdx],bstrVal);
  1258. }
  1259. if (!SUCCEEDED(hrRes)) {
  1260. for (dwIdx=0;dwIdx<celt;dwIdx++) {
  1261. CoTaskMemFree(apszElt[dwIdx]);
  1262. apszElt[dwIdx] = NULL;
  1263. }
  1264. return (hrRes);
  1265. }
  1266. m_dwIdx += dwIdx;
  1267. if (pceltFetched) {
  1268. *pceltFetched = dwIdx;
  1269. }
  1270. if (hrRes == S_FALSE) {
  1271. return (S_FALSE);
  1272. }
  1273. return (S_OK);
  1274. }
  1275. HRESULT STDMETHODCALLTYPE CEventTypeSinksEnum::Clone(IEnumString **ppEnum) {
  1276. DEBUG_OBJECT_CHECK
  1277. return (Create(m_pSinks,m_dwIdx,IID_IEnumString,(LPVOID *) ppEnum));
  1278. }
  1279. /////////////////////////////////////////////////////////////////////////////
  1280. // CEventTypeSinks
  1281. class ATL_NO_VTABLE CEventTypeSinks :
  1282. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  1283. // public CComCoClass<CEventTypeSinks, &CLSID_CEventTypeSinks>,
  1284. public IDispatchImpl<IEventTypeSinks, &IID_IEventTypeSinks, &LIBID_SEOLib>
  1285. {
  1286. DEBUG_OBJECT_DEF(CEventTypeSinks)
  1287. public:
  1288. HRESULT FinalConstruct();
  1289. void FinalRelease();
  1290. HRESULT Load(CATID catid);
  1291. DECLARE_PROTECT_FINAL_CONSTRUCT();
  1292. DECLARE_NOT_AGGREGATABLE(CEventTypeSinks);
  1293. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  1294. // L"EventTypeSinks Class",
  1295. // L"Event.TypeSinks.1",
  1296. // L"Event.TypeSinks");
  1297. DECLARE_GET_CONTROLLING_UNKNOWN();
  1298. BEGIN_COM_MAP(CEventTypeSinks)
  1299. COM_INTERFACE_ENTRY(IEventTypeSinks)
  1300. COM_INTERFACE_ENTRY_IID(IID_IDispatch, IEventTypeSinks)
  1301. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  1302. END_COM_MAP()
  1303. // IEventTypeSinks
  1304. public:
  1305. HRESULT STDMETHODCALLTYPE Item(long lIndex, BSTR *pstrTypeSink);
  1306. HRESULT STDMETHODCALLTYPE Add(BSTR pszTypeSink);
  1307. HRESULT STDMETHODCALLTYPE Remove(BSTR pszTypeSink);
  1308. HRESULT STDMETHODCALLTYPE get_Count(long *plCount);
  1309. HRESULT STDMETHODCALLTYPE get__NewEnum(IUnknown **ppUnkEnum);
  1310. private:
  1311. CATID m_catid;
  1312. DWORD m_dwProgID;
  1313. CComBSTR *m_astrProgID;
  1314. CComPtr<IUnknown> m_pUnkMarshaler;
  1315. };
  1316. /////////////////////////////////////////////////////////////////////////////
  1317. // CEventTypeSinks
  1318. HRESULT CEventTypeSinks::FinalConstruct() {
  1319. DEBUG_OBJECT_CHECK
  1320. TraceFunctEnter("CEventTypeSinks::FinalConstruct");
  1321. HRESULT hrRes = S_OK;
  1322. m_dwProgID = 0;
  1323. m_astrProgID = NULL;
  1324. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  1325. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  1326. ADD_DEBUG_OBJECT("CEventTypeSinks")
  1327. TraceFunctLeave();
  1328. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  1329. }
  1330. void CEventTypeSinks::FinalRelease() {
  1331. DEBUG_OBJECT_CHECK
  1332. TraceFunctEnter("CEventTypeSinks::FinalRelease");
  1333. _ASSERTE((!m_dwProgID&&!m_astrProgID)||(m_dwProgID&&m_astrProgID));
  1334. delete[] m_astrProgID;
  1335. m_dwProgID = 0;
  1336. m_astrProgID = NULL;
  1337. m_pUnkMarshaler.Release();
  1338. REMOVE_DEBUG_OBJECT
  1339. TraceFunctLeave();
  1340. }
  1341. HRESULT CEventTypeSinks::Load(CATID catid) {
  1342. DEBUG_OBJECT_CHECK
  1343. HRESULT hrRes;
  1344. CComPtr<ICatInformation> pCatInfo;
  1345. CComPtr<IEnumCLSID> pEnum;
  1346. DWORD dwAlloc = 0;
  1347. CLSID *pclsid = NULL;
  1348. DWORD dwTmp;
  1349. m_catid = GUID_NULL;
  1350. delete[] m_astrProgID;
  1351. m_dwProgID = 0;
  1352. m_astrProgID = NULL;
  1353. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  1354. NULL,
  1355. CLSCTX_ALL,
  1356. IID_ICatInformation,
  1357. (LPVOID *) &pCatInfo);
  1358. if (!SUCCEEDED(hrRes)) {
  1359. return (hrRes);
  1360. }
  1361. hrRes = pCatInfo->EnumClassesOfCategories(1,(GUID *) &catid,-1,NULL,&pEnum);
  1362. if (!SUCCEEDED(hrRes)) {
  1363. return (hrRes);
  1364. }
  1365. hrRes = S_FALSE;
  1366. while (1) {
  1367. dwTmp = (hrRes==S_FALSE) ? 1 : dwAlloc;
  1368. if (!MyReallocInPlace(&pclsid,sizeof(*pclsid)*(dwAlloc+dwTmp))) {
  1369. if (pclsid) MyFree(pclsid);
  1370. return (E_OUTOFMEMORY);
  1371. }
  1372. hrRes = pEnum->Next(dwTmp,&pclsid[dwAlloc],&dwTmp);
  1373. // Do not alter hrRes between here and the bottom of the loop! The first statement
  1374. // in the loop relies on hrRes having the result from this call to IEnumCLSID::Next.
  1375. if (!SUCCEEDED(hrRes)) {
  1376. MyFree(pclsid);
  1377. return (hrRes);
  1378. }
  1379. if (!dwTmp) {
  1380. break;
  1381. }
  1382. dwAlloc += dwTmp;
  1383. }
  1384. m_astrProgID = new CComBSTR[dwAlloc];
  1385. if (!m_astrProgID) {
  1386. MyFree(pclsid);
  1387. return (E_OUTOFMEMORY);
  1388. }
  1389. for (dwTmp=0,m_dwProgID=0;dwTmp<dwAlloc;dwTmp++) {
  1390. LPOLESTR pszTmp;
  1391. hrRes = ProgIDFromCLSID(pclsid[dwTmp],&pszTmp);
  1392. if (SUCCEEDED(hrRes)) {
  1393. m_astrProgID[m_dwProgID] = pszTmp;
  1394. CoTaskMemFree(pszTmp);
  1395. m_dwProgID++;
  1396. }
  1397. }
  1398. MyFree(pclsid);
  1399. m_catid = catid;
  1400. return (S_OK);
  1401. }
  1402. HRESULT STDMETHODCALLTYPE CEventTypeSinks::Item(long lIndex, BSTR *pstrTypeSink) {
  1403. DEBUG_OBJECT_CHECK
  1404. if (pstrTypeSink) {
  1405. *pstrTypeSink = NULL;
  1406. }
  1407. if (!pstrTypeSink) {
  1408. return (E_POINTER);
  1409. }
  1410. _ASSERTE(m_catid!=GUID_NULL);
  1411. if (m_catid == GUID_NULL) {
  1412. return (E_FAIL);
  1413. }
  1414. if (lIndex < 1) {
  1415. return (E_INVALIDARG);
  1416. }
  1417. if ((DWORD) lIndex > m_dwProgID) {
  1418. return (S_FALSE);
  1419. }
  1420. *pstrTypeSink = SysAllocString(m_astrProgID[lIndex]);
  1421. if (!pstrTypeSink) {
  1422. return (E_OUTOFMEMORY);
  1423. }
  1424. return (S_OK);
  1425. }
  1426. HRESULT STDMETHODCALLTYPE CEventTypeSinks::Add(BSTR pszTypeSink) {
  1427. DEBUG_OBJECT_CHECK
  1428. HRESULT hrRes;
  1429. CStringGUID objGuid;
  1430. CComPtr<ICatRegister> pCatReg;
  1431. if (!pszTypeSink) {
  1432. return (E_POINTER);
  1433. }
  1434. _ASSERTE(m_catid!=GUID_NULL);
  1435. if (m_catid == GUID_NULL) {
  1436. return (E_FAIL);
  1437. }
  1438. objGuid.CalcFromProgID(pszTypeSink);
  1439. if (!objGuid) {
  1440. return (CO_E_CLASSSTRING);
  1441. }
  1442. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  1443. NULL,
  1444. CLSCTX_ALL,
  1445. IID_ICatRegister,
  1446. (LPVOID *) &pCatReg);
  1447. if (!SUCCEEDED(hrRes)) {
  1448. return (hrRes);
  1449. }
  1450. hrRes = pCatReg->RegisterClassImplCategories(objGuid,1,&m_catid);
  1451. if (!SUCCEEDED(hrRes)) {
  1452. return (hrRes);
  1453. }
  1454. hrRes = Load(m_catid);
  1455. if (!SUCCEEDED(hrRes)) {
  1456. return (hrRes);
  1457. }
  1458. return (S_OK);
  1459. }
  1460. HRESULT STDMETHODCALLTYPE CEventTypeSinks::Remove(BSTR pszTypeSink) {
  1461. DEBUG_OBJECT_CHECK
  1462. HRESULT hrRes;
  1463. CStringGUID objGuid;
  1464. CComPtr<ICatRegister> pCatReg;
  1465. if (!pszTypeSink) {
  1466. return (E_POINTER);
  1467. }
  1468. _ASSERTE(m_catid!=GUID_NULL);
  1469. if (m_catid == GUID_NULL) {
  1470. return (E_FAIL);
  1471. }
  1472. objGuid.CalcFromProgID(pszTypeSink);
  1473. if (!objGuid) {
  1474. return (CO_E_CLASSSTRING);
  1475. }
  1476. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  1477. NULL,
  1478. CLSCTX_ALL,
  1479. IID_ICatRegister,
  1480. (LPVOID *) &pCatReg);
  1481. if (!SUCCEEDED(hrRes)) {
  1482. return (hrRes);
  1483. }
  1484. hrRes = pCatReg->UnRegisterClassImplCategories(objGuid,1,&m_catid);
  1485. if (!SUCCEEDED(hrRes)) {
  1486. return (hrRes);
  1487. }
  1488. hrRes = Load(m_catid);
  1489. if (!SUCCEEDED(hrRes)) {
  1490. return (hrRes);
  1491. }
  1492. return (S_OK);
  1493. }
  1494. HRESULT STDMETHODCALLTYPE CEventTypeSinks::get_Count(long *plCount) {
  1495. DEBUG_OBJECT_CHECK
  1496. if (plCount) {
  1497. *plCount = 0;
  1498. }
  1499. if (!plCount) {
  1500. return (E_POINTER);
  1501. }
  1502. _ASSERTE(m_catid!=GUID_NULL);
  1503. if (m_catid == GUID_NULL) {
  1504. return (E_FAIL);
  1505. }
  1506. *plCount = m_dwProgID;
  1507. return (S_OK);
  1508. }
  1509. HRESULT STDMETHODCALLTYPE CEventTypeSinks::get__NewEnum(IUnknown **ppUnkEnum) {
  1510. DEBUG_OBJECT_CHECK
  1511. if (ppUnkEnum) {
  1512. *ppUnkEnum = NULL;
  1513. }
  1514. if (!ppUnkEnum) {
  1515. return (E_POINTER);
  1516. }
  1517. _ASSERTE(m_catid!=GUID_NULL);
  1518. if (m_catid == GUID_NULL) {
  1519. return (E_FAIL);
  1520. }
  1521. return (CEventTypeSinksEnum::Create(this,0,IID_IEnumVARIANT,(LPVOID *) ppUnkEnum));
  1522. }
  1523. /////////////////////////////////////////////////////////////////////////////
  1524. // CEventType
  1525. class ATL_NO_VTABLE CEventType :
  1526. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  1527. // public CComCoClass<CEventType, &CLSID_CEventType>,
  1528. public IDispatchImpl<IEventType, &IID_IEventType, &LIBID_SEOLib>,
  1529. public CEventDatabasePlugin
  1530. {
  1531. DEBUG_OBJECT_DEF(CEventType)
  1532. public:
  1533. HRESULT FinalConstruct();
  1534. void FinalRelease();
  1535. DECLARE_PROTECT_FINAL_CONSTRUCT();
  1536. DECLARE_NOT_AGGREGATABLE(CEventType);
  1537. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  1538. // L"EventType Class",
  1539. // L"Event.Type.1",
  1540. // L"Event.Type");
  1541. DECLARE_GET_CONTROLLING_UNKNOWN();
  1542. BEGIN_COM_MAP(CEventType)
  1543. COM_INTERFACE_ENTRY(IEventType)
  1544. COM_INTERFACE_ENTRY_IID(IID_IDispatch, IEventType)
  1545. COM_INTERFACE_ENTRY(IEventDatabasePlugin)
  1546. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  1547. END_COM_MAP()
  1548. // IEventType
  1549. public:
  1550. HRESULT STDMETHODCALLTYPE get_ID(BSTR *pstrID);
  1551. HRESULT STDMETHODCALLTYPE get_DisplayName(BSTR *pstrDisplayName);
  1552. HRESULT STDMETHODCALLTYPE get_Sinks(IEventTypeSinks **ppTypeSinks);
  1553. private:
  1554. CComPtr<ICatInformation> m_pCatInfo;
  1555. CComPtr<IUnknown> m_pUnkMarshaler;
  1556. };
  1557. /////////////////////////////////////////////////////////////////////////////
  1558. // CEventType
  1559. HRESULT CEventType::FinalConstruct() {
  1560. DEBUG_OBJECT_CHECK
  1561. TraceFunctEnter("CEventType::FinalConstruct");
  1562. HRESULT hrRes = S_OK;
  1563. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  1564. NULL,
  1565. CLSCTX_ALL,
  1566. IID_ICatInformation,
  1567. (LPVOID *) &m_pCatInfo);
  1568. _ASSERTE(!SUCCEEDED(hrRes)||m_pCatInfo);
  1569. if (SUCCEEDED(hrRes)) {
  1570. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  1571. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  1572. }
  1573. ADD_DEBUG_OBJECT("CEventType")
  1574. TraceFunctLeave();
  1575. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  1576. }
  1577. void CEventType::FinalRelease() {
  1578. DEBUG_OBJECT_CHECK
  1579. TraceFunctEnter("CEventType::FinalRelease");
  1580. m_pCatInfo.Release();
  1581. m_pUnkMarshaler.Release();
  1582. REMOVE_DEBUG_OBJECT
  1583. TraceFunctLeave();
  1584. }
  1585. HRESULT STDMETHODCALLTYPE CEventType::get_ID(BSTR *pstrID) {
  1586. DEBUG_OBJECT_CHECK
  1587. _ASSERTE(m_strName);
  1588. if (!pstrID) {
  1589. return (E_POINTER);
  1590. }
  1591. *pstrID = SysAllocString(m_strName);
  1592. if (!*pstrID) {
  1593. return (E_OUTOFMEMORY);
  1594. }
  1595. return (S_OK);
  1596. }
  1597. HRESULT STDMETHODCALLTYPE CEventType::get_DisplayName(BSTR *pstrDisplayName) {
  1598. DEBUG_OBJECT_CHECK
  1599. HRESULT hrRes;
  1600. LPOLESTR pszDesc;
  1601. if (pstrDisplayName) {
  1602. *pstrDisplayName = NULL;
  1603. }
  1604. if (!pstrDisplayName) {
  1605. return (E_POINTER);
  1606. }
  1607. hrRes = m_pCatInfo->GetCategoryDesc(CStringGUID(m_strName),LOCALE_USER_DEFAULT,&pszDesc);
  1608. if (!SUCCEEDED(hrRes)) {
  1609. return (hrRes);
  1610. }
  1611. *pstrDisplayName = SysAllocString(pszDesc);
  1612. CoTaskMemFree(pszDesc);
  1613. if (!pstrDisplayName) {
  1614. return (E_OUTOFMEMORY);
  1615. }
  1616. return (S_OK);
  1617. }
  1618. HRESULT STDMETHODCALLTYPE CEventType::get_Sinks(IEventTypeSinks **ppTypeSinks) {
  1619. DEBUG_OBJECT_CHECK
  1620. HRESULT hrRes;
  1621. CComObject<CEventTypeSinks> *pSinks;
  1622. if (ppTypeSinks) {
  1623. *ppTypeSinks = NULL;
  1624. }
  1625. if (!ppTypeSinks) {
  1626. return (E_POINTER);
  1627. }
  1628. hrRes = CComObject<CEventTypeSinks>::CreateInstance(&pSinks);
  1629. if (!SUCCEEDED(hrRes)) {
  1630. return (hrRes);
  1631. }
  1632. pSinks->AddRef();
  1633. hrRes = pSinks->Load(CStringGUID(m_strName));
  1634. if (SUCCEEDED(hrRes)) {
  1635. hrRes = pSinks->QueryInterface(IID_IEventTypeSinks,(LPVOID *) ppTypeSinks);
  1636. }
  1637. pSinks->Release();
  1638. if (!SUCCEEDED(hrRes)) {
  1639. return (hrRes);
  1640. }
  1641. return (S_OK);
  1642. }
  1643. /////////////////////////////////////////////////////////////////////////////
  1644. // CEventTypesEnum
  1645. class ATL_NO_VTABLE CEventTypesEnum :
  1646. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  1647. // public CComCoClass<CEventTypesEnum, &CLSID_CEventTypesEnum>,
  1648. public CEventEnumVARIANTBaseImpl<CEventType,CEventTypesEnum>,
  1649. public CEventEnumUnknownBaseImpl<CEventType,CEventTypesEnum>
  1650. {
  1651. DEBUG_OBJECT_DEF(CEventTypesEnum)
  1652. public:
  1653. HRESULT FinalConstruct();
  1654. void FinalRelease();
  1655. DECLARE_PROTECT_FINAL_CONSTRUCT();
  1656. DECLARE_NOT_AGGREGATABLE(CEventTypesEnum);
  1657. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  1658. // L"EventTypesEnum Class",
  1659. // L"Event.EventTypesEnum.1",
  1660. // L"Event.EventTypesEnum");
  1661. DECLARE_GET_CONTROLLING_UNKNOWN();
  1662. BEGIN_COM_MAP(CEventTypesEnum)
  1663. COM_INTERFACE_ENTRY(IEnumVARIANT)
  1664. COM_INTERFACE_ENTRY(IEnumUnknown)
  1665. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  1666. END_COM_MAP()
  1667. // IEventEnumBase
  1668. public:
  1669. virtual HRESULT SetEnum(IUnknown *pEnum, IEventPropertyBag *pCollection);
  1670. virtual IUnknown *GetEnum() { _ASSERTE(m_pEnum); return (m_pEnum); };
  1671. virtual IEventPropertyBag *GetCollection() { _ASSERTE(m_pCollection); return (m_pCollection); };
  1672. private:
  1673. CComPtr<IUnknown> m_pEnum;
  1674. CComPtr<IEventPropertyBag> m_pCollection;
  1675. CComPtr<IUnknown> m_pUnkMarshaler;
  1676. };
  1677. /////////////////////////////////////////////////////////////////////////////
  1678. // CEventTypesEnum
  1679. HRESULT CEventTypesEnum::FinalConstruct() {
  1680. DEBUG_OBJECT_CHECK
  1681. TraceFunctEnter("CEventTypesEnum::FinalConstruct");
  1682. HRESULT hrRes = S_OK;
  1683. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  1684. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  1685. ADD_DEBUG_OBJECT("CEventTypesEnum")
  1686. TraceFunctLeave();
  1687. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  1688. }
  1689. void CEventTypesEnum::FinalRelease() {
  1690. DEBUG_OBJECT_CHECK
  1691. TraceFunctEnter("CEventTypesEnum::FinalRelease");
  1692. m_pUnkMarshaler.Release();
  1693. REMOVE_DEBUG_OBJECT
  1694. TraceFunctLeave();
  1695. }
  1696. HRESULT CEventTypesEnum::SetEnum(IUnknown *pEnum, IEventPropertyBag *pCollection) {
  1697. DEBUG_OBJECT_CHECK
  1698. if (!pEnum || !pCollection) {
  1699. _ASSERTE(FALSE);
  1700. return (E_POINTER);
  1701. }
  1702. m_pEnum = pEnum;
  1703. m_pCollection = pCollection;
  1704. return (S_OK);
  1705. }
  1706. /////////////////////////////////////////////////////////////////////////////
  1707. // CEventTypes
  1708. class ATL_NO_VTABLE CEventTypes :
  1709. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  1710. // public CComCoClass<CEventTypes, &CLSID_CEventTypes>,
  1711. public IDispatchImpl<IEventTypes, &IID_IEventTypes, &LIBID_SEOLib>,
  1712. public CEventDatabasePlugin
  1713. {
  1714. DEBUG_OBJECT_DEF(CEventTypes)
  1715. public:
  1716. HRESULT FinalConstruct();
  1717. void FinalRelease();
  1718. DECLARE_PROTECT_FINAL_CONSTRUCT();
  1719. DECLARE_NOT_AGGREGATABLE(CEventTypes);
  1720. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  1721. // L"EventTypes Class",
  1722. // L"Event.EventTypes.1",
  1723. // L"Event.EventTypes");
  1724. DECLARE_GET_CONTROLLING_UNKNOWN();
  1725. BEGIN_COM_MAP(CEventTypes)
  1726. COM_INTERFACE_ENTRY(IEventTypes)
  1727. COM_INTERFACE_ENTRY_IID(IID_IDispatch, IEventTypes)
  1728. COM_INTERFACE_ENTRY(IEventDatabasePlugin)
  1729. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  1730. END_COM_MAP()
  1731. // IEventTypes
  1732. public:
  1733. HRESULT STDMETHODCALLTYPE Item(VARIANT *pvarDesired, IEventType **ppEventType);
  1734. HRESULT STDMETHODCALLTYPE Add(BSTR pszEventType);
  1735. HRESULT STDMETHODCALLTYPE Remove(BSTR pszEventType);
  1736. HRESULT STDMETHODCALLTYPE get_Count(long *plCount);
  1737. HRESULT STDMETHODCALLTYPE get__NewEnum(IUnknown **ppUnkEnum);
  1738. private:
  1739. CComPtr<ICatInformation> m_pCatInfo;
  1740. CComPtr<IUnknown> m_pUnkMarshaler;
  1741. };
  1742. /////////////////////////////////////////////////////////////////////////////
  1743. // CEventTypes
  1744. HRESULT CEventTypes::FinalConstruct() {
  1745. DEBUG_OBJECT_CHECK
  1746. TraceFunctEnter("CEventTypes::FinalConstruct");
  1747. HRESULT hrRes = S_OK;
  1748. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  1749. NULL,
  1750. CLSCTX_ALL,
  1751. IID_ICatInformation,
  1752. (LPVOID *) &m_pCatInfo);
  1753. _ASSERTE(!SUCCEEDED(hrRes)||m_pCatInfo);
  1754. if (SUCCEEDED(hrRes)) {
  1755. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  1756. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  1757. }
  1758. ADD_DEBUG_OBJECT("CEventTypes")
  1759. TraceFunctLeave();
  1760. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  1761. }
  1762. void CEventTypes::FinalRelease() {
  1763. DEBUG_OBJECT_CHECK
  1764. TraceFunctEnter("CEventTypes::FinalRelease");
  1765. m_pCatInfo.Release();
  1766. m_pUnkMarshaler.Release();
  1767. REMOVE_DEBUG_OBJECT
  1768. TraceFunctLeave();
  1769. }
  1770. HRESULT STDMETHODCALLTYPE CEventTypes::Item(VARIANT *pvarDesired, IEventType **ppEventType) {
  1771. DEBUG_OBJECT_CHECK
  1772. return (CreatePluggedInObject(CComObject<CEventType>::_CreatorClass::CreateInstance,
  1773. m_pDatabase,
  1774. pvarDesired,
  1775. IID_IEventType,
  1776. (IUnknown **) ppEventType,
  1777. FALSE));
  1778. }
  1779. HRESULT STDMETHODCALLTYPE CEventTypes::Add(BSTR pszEventType) {
  1780. DEBUG_OBJECT_CHECK
  1781. HRESULT hrRes;
  1782. CStringGUID objGuid;
  1783. LPOLESTR pszDesc;
  1784. CComPtr<IEventPropertyBag> pdictTmp;
  1785. if (!m_pCatInfo) {
  1786. _ASSERTE(FALSE);
  1787. return (E_FAIL);
  1788. }
  1789. if (!m_pDatabase) {
  1790. _ASSERTE(FALSE);
  1791. return (E_FAIL);
  1792. }
  1793. if (!pszEventType) {
  1794. return (E_POINTER);
  1795. }
  1796. objGuid = pszEventType;
  1797. if (!objGuid) {
  1798. return (CO_E_CLASSSTRING);
  1799. }
  1800. hrRes = m_pCatInfo->GetCategoryDesc(objGuid,LOCALE_USER_DEFAULT,&pszDesc);
  1801. if (!SUCCEEDED(hrRes)) {
  1802. return (hrRes);
  1803. }
  1804. CoTaskMemFree(pszDesc);
  1805. hrRes = CoCreateInstance(CLSID_CSEOMemDictionary,
  1806. NULL,
  1807. CLSCTX_ALL,
  1808. IID_IEventPropertyBag,
  1809. (LPVOID *) &pdictTmp);
  1810. if (!SUCCEEDED(hrRes)) {
  1811. return (hrRes);
  1812. }
  1813. hrRes = m_pDatabase->Add((LPOLESTR) ((LPCOLESTR) objGuid),&CComVariant(pdictTmp));
  1814. if (!SUCCEEDED(hrRes)) {
  1815. return (hrRes);
  1816. }
  1817. if (hrRes == S_FALSE) {
  1818. return (S_FALSE);
  1819. }
  1820. return (S_OK);
  1821. }
  1822. HRESULT STDMETHODCALLTYPE CEventTypes::Remove(BSTR pszEventType) {
  1823. DEBUG_OBJECT_CHECK
  1824. if (!m_pDatabase) {
  1825. _ASSERTE(FALSE);
  1826. return (E_FAIL);
  1827. }
  1828. return (m_pDatabase->Remove(&CComVariant(pszEventType)));
  1829. }
  1830. HRESULT STDMETHODCALLTYPE CEventTypes::get_Count(long *plCount) {
  1831. DEBUG_OBJECT_CHECK
  1832. if (plCount) {
  1833. *plCount = 0;
  1834. }
  1835. if (!plCount) {
  1836. return (E_POINTER);
  1837. }
  1838. if (!m_pDatabase) {
  1839. _ASSERTE(FALSE);
  1840. return (E_FAIL);
  1841. }
  1842. return (m_pDatabase->get_Count(plCount));
  1843. }
  1844. HRESULT STDMETHODCALLTYPE CEventTypes::get__NewEnum(IUnknown **ppUnkEnum) {
  1845. DEBUG_OBJECT_CHECK
  1846. HRESULT hrRes;
  1847. CComPtr<IUnknown> pUnkTmp;
  1848. CComObject<CEventTypesEnum> *pNewEnum;
  1849. if (ppUnkEnum) {
  1850. *ppUnkEnum = NULL;
  1851. }
  1852. if (!ppUnkEnum) {
  1853. return (E_POINTER);
  1854. }
  1855. if (!m_pDatabase) {
  1856. _ASSERTE(FALSE);
  1857. return (E_FAIL);
  1858. }
  1859. hrRes = m_pDatabase->get__NewEnum(&pUnkTmp);
  1860. if (!SUCCEEDED(hrRes)) {
  1861. return (hrRes);
  1862. }
  1863. _ASSERTE(pUnkTmp);
  1864. hrRes = CComObject<CEventTypesEnum>::CreateInstance(&pNewEnum);
  1865. if (!SUCCEEDED(hrRes)) {
  1866. return (hrRes);
  1867. }
  1868. _ASSERTE(pNewEnum);
  1869. pNewEnum->AddRef();
  1870. hrRes = pNewEnum->SetEnum(pUnkTmp,m_pDatabase);
  1871. if (!SUCCEEDED(hrRes)) {
  1872. pNewEnum->Release();
  1873. return (hrRes);
  1874. }
  1875. hrRes = pNewEnum->QueryInterface(IID_IEnumVARIANT,(LPVOID *) ppUnkEnum);
  1876. pNewEnum->Release();
  1877. if (!SUCCEEDED(hrRes)) {
  1878. return (hrRes);
  1879. }
  1880. _ASSERTE(*ppUnkEnum);
  1881. return (S_OK);
  1882. }
  1883. /////////////////////////////////////////////////////////////////////////////
  1884. // CEventSource
  1885. class ATL_NO_VTABLE CEventSource :
  1886. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  1887. // public CComCoClass<CEventSource, &CLSID_CEventSource>,
  1888. public IDispatchImpl<IEventSource, &IID_IEventSource, &LIBID_SEOLib>,
  1889. public CEventDatabasePlugin
  1890. {
  1891. DEBUG_OBJECT_DEF(CEventSource)
  1892. public:
  1893. HRESULT FinalConstruct();
  1894. void FinalRelease();
  1895. DECLARE_PROTECT_FINAL_CONSTRUCT();
  1896. DECLARE_NOT_AGGREGATABLE(CEventSource);
  1897. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  1898. // L"EventSource Class",
  1899. // L"Event.Source.1",
  1900. // L"Event.Source");
  1901. DECLARE_GET_CONTROLLING_UNKNOWN();
  1902. BEGIN_COM_MAP(CEventSource)
  1903. COM_INTERFACE_ENTRY(IEventSource)
  1904. COM_INTERFACE_ENTRY_IID(IID_IDispatch, IEventSource)
  1905. COM_INTERFACE_ENTRY(IEventDatabasePlugin)
  1906. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  1907. END_COM_MAP()
  1908. // IEventSource
  1909. public:
  1910. HRESULT STDMETHODCALLTYPE get_ID(BSTR *pstrID);
  1911. HRESULT STDMETHODCALLTYPE get_DisplayName(BSTR *pstrDisplayName);
  1912. HRESULT STDMETHODCALLTYPE put_DisplayName(BSTR pszDisplayName);
  1913. HRESULT STDMETHODCALLTYPE putref_DisplayName(BSTR *ppszDisplayName);
  1914. HRESULT STDMETHODCALLTYPE get_BindingManagerMoniker(IUnknown **ppUnkMoniker);
  1915. HRESULT STDMETHODCALLTYPE put_BindingManagerMoniker(IUnknown *pUnkMoniker);
  1916. HRESULT STDMETHODCALLTYPE putref_BindingManagerMoniker(IUnknown **ppUnkMoniker);
  1917. HRESULT STDMETHODCALLTYPE GetBindingManager(IEventBindingManager **ppBindingManager);
  1918. HRESULT STDMETHODCALLTYPE get_Properties(IEventPropertyBag **ppProperties);
  1919. HRESULT STDMETHODCALLTYPE Save();
  1920. private:
  1921. CComPtr<IEventPropertyBag> m_pTmpDatabase;
  1922. CComPtr<IUnknown> m_pUnkMarshaler;
  1923. };
  1924. /////////////////////////////////////////////////////////////////////////////
  1925. // CEventSource
  1926. HRESULT CEventSource::FinalConstruct() {
  1927. DEBUG_OBJECT_CHECK
  1928. TraceFunctEnter("CEventSource::FinalConstruct");
  1929. HRESULT hrRes = S_OK;
  1930. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  1931. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  1932. ADD_DEBUG_OBJECT("CEventSource")
  1933. TraceFunctLeave();
  1934. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  1935. }
  1936. void CEventSource::FinalRelease() {
  1937. DEBUG_OBJECT_CHECK
  1938. TraceFunctEnter("CEventSource::FinalRelease");
  1939. m_pUnkMarshaler.Release();
  1940. REMOVE_DEBUG_OBJECT
  1941. TraceFunctLeave();
  1942. }
  1943. HRESULT STDMETHODCALLTYPE CEventSource::get_ID(BSTR *pstrID) {
  1944. DEBUG_OBJECT_CHECK
  1945. _ASSERTE(m_strName);
  1946. if (!pstrID) {
  1947. return (E_POINTER);
  1948. }
  1949. *pstrID = SysAllocString(m_strName);
  1950. if (!*pstrID) {
  1951. return (E_OUTOFMEMORY);
  1952. }
  1953. return (S_OK);
  1954. }
  1955. HRESULT STDMETHODCALLTYPE CEventSource::get_DisplayName(BSTR *pstrDisplayName) {
  1956. DEBUG_OBJECT_CHECK
  1957. CComPtr<IEventPropertyBag> pTmp = m_pTmpDatabase ? m_pTmpDatabase : m_pDatabase;
  1958. HRESULT hrRes;
  1959. CComVariant varPropValue;
  1960. if (pstrDisplayName) {
  1961. *pstrDisplayName = NULL;
  1962. }
  1963. if (!pstrDisplayName) {
  1964. return (E_POINTER);
  1965. }
  1966. if (!m_pDatabase) {
  1967. _ASSERTE(FALSE);
  1968. return (E_FAIL);
  1969. }
  1970. hrRes = pTmp->Item(&CComVariant(BD_DISPLAYNAME),&varPropValue);
  1971. if (!SUCCEEDED(hrRes)) {
  1972. return (hrRes);
  1973. }
  1974. if (hrRes == S_FALSE) {
  1975. *pstrDisplayName = SysAllocString(L"");
  1976. } else {
  1977. hrRes = varPropValue.ChangeType(VT_BSTR);
  1978. if (!SUCCEEDED(hrRes)) {
  1979. return (hrRes);
  1980. }
  1981. *pstrDisplayName = SysAllocString(varPropValue.bstrVal);
  1982. }
  1983. if (!*pstrDisplayName) {
  1984. return (E_OUTOFMEMORY);
  1985. }
  1986. return (S_OK);
  1987. }
  1988. HRESULT STDMETHODCALLTYPE CEventSource::put_DisplayName(BSTR pszDisplayName) {
  1989. DEBUG_OBJECT_CHECK
  1990. HRESULT hrRes;
  1991. CComVariant varPropValue;
  1992. if (!m_pDatabase) {
  1993. _ASSERTE(FALSE);
  1994. return (E_FAIL);
  1995. }
  1996. if (!m_pTmpDatabase) {
  1997. hrRes = CopyPropertyBag(m_pDatabase,&m_pTmpDatabase);
  1998. if (!SUCCEEDED(hrRes)) {
  1999. return (hrRes);
  2000. }
  2001. }
  2002. if (pszDisplayName) {
  2003. varPropValue = pszDisplayName;
  2004. }
  2005. hrRes = m_pTmpDatabase->Add(BD_DISPLAYNAME,&varPropValue);
  2006. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2007. }
  2008. HRESULT STDMETHODCALLTYPE CEventSource::putref_DisplayName(BSTR *ppszDisplayName) {
  2009. DEBUG_OBJECT_CHECK
  2010. if (!ppszDisplayName) {
  2011. return (E_POINTER);
  2012. }
  2013. return (put_DisplayName(*ppszDisplayName));
  2014. }
  2015. HRESULT STDMETHODCALLTYPE CEventSource::get_BindingManagerMoniker(IUnknown **ppUnkMoniker) {
  2016. DEBUG_OBJECT_CHECK
  2017. CComPtr<IEventPropertyBag> pTmp = m_pTmpDatabase ? m_pTmpDatabase : m_pDatabase;
  2018. HRESULT hrRes;
  2019. CComVariant varPropValue;
  2020. CComPtr<IBindCtx> pBindCtx;
  2021. DWORD dwEaten;
  2022. if (ppUnkMoniker) {
  2023. *ppUnkMoniker = NULL;
  2024. }
  2025. if (!ppUnkMoniker) {
  2026. return (E_POINTER);
  2027. }
  2028. if (!m_pDatabase) {
  2029. _ASSERTE(FALSE);
  2030. return (E_FAIL);
  2031. }
  2032. hrRes = pTmp->Item(&CComVariant(BD_BINDINGMANAGERMONIKER),&varPropValue);
  2033. if (!SUCCEEDED(hrRes)) {
  2034. return (hrRes);
  2035. }
  2036. if (hrRes == S_FALSE) {
  2037. return (EVENTS_E_BADDATA);
  2038. }
  2039. hrRes = varPropValue.ChangeType(VT_BSTR);
  2040. if (!SUCCEEDED(hrRes)) {
  2041. return (hrRes);
  2042. }
  2043. hrRes = CreateBindCtx(0,&pBindCtx);
  2044. if (!SUCCEEDED(hrRes)) {
  2045. return (hrRes);
  2046. }
  2047. hrRes = MkParseDisplayName(pBindCtx,varPropValue.bstrVal,&dwEaten,(IMoniker **) ppUnkMoniker);
  2048. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2049. }
  2050. HRESULT STDMETHODCALLTYPE CEventSource::put_BindingManagerMoniker(IUnknown *pUnkMoniker) {
  2051. DEBUG_OBJECT_CHECK
  2052. HRESULT hrRes;
  2053. CComVariant varPropName;
  2054. CComVariant varPropValue;
  2055. if (!m_pDatabase) {
  2056. _ASSERTE(FALSE);
  2057. return (E_FAIL);
  2058. }
  2059. if (!m_pTmpDatabase) {
  2060. hrRes = CopyPropertyBag(m_pDatabase,&m_pTmpDatabase);
  2061. if (!SUCCEEDED(hrRes)) {
  2062. return (hrRes);
  2063. }
  2064. }
  2065. if (pUnkMoniker) {
  2066. CComBSTR strString;
  2067. CComPtr<IBindCtx> pBindCtx;
  2068. CComQIPtr<IMoniker,&IID_IMoniker> pMoniker = pUnkMoniker;
  2069. LPOLESTR pszDisplayName;
  2070. if (!pMoniker) {
  2071. return (E_NOINTERFACE);
  2072. }
  2073. hrRes = CreateBindCtx(0,&pBindCtx);
  2074. if (!SUCCEEDED(hrRes)) {
  2075. return (hrRes);
  2076. }
  2077. hrRes = pMoniker->GetDisplayName(pBindCtx,NULL,&pszDisplayName);
  2078. if (!SUCCEEDED(hrRes)) {
  2079. CoTaskMemFree(pszDisplayName);
  2080. return (hrRes);
  2081. }
  2082. varPropValue = pszDisplayName;
  2083. CoTaskMemFree(pszDisplayName);
  2084. } else {
  2085. varPropValue = L"";
  2086. }
  2087. varPropName = BD_BINDINGMANAGERMONIKER;
  2088. hrRes = m_pTmpDatabase->Add(BD_BINDINGMANAGERMONIKER,&varPropValue);
  2089. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2090. }
  2091. HRESULT STDMETHODCALLTYPE CEventSource::putref_BindingManagerMoniker(IUnknown **ppUnkMoniker) {
  2092. DEBUG_OBJECT_CHECK
  2093. if (!ppUnkMoniker) {
  2094. return (E_POINTER);
  2095. }
  2096. return (put_BindingManagerMoniker(*ppUnkMoniker));
  2097. }
  2098. HRESULT STDMETHODCALLTYPE CEventSource::GetBindingManager(IEventBindingManager **ppBindingManager) {
  2099. DEBUG_OBJECT_CHECK
  2100. HRESULT hrRes;
  2101. CComPtr<IUnknown> pUnkMon;
  2102. CComQIPtr<IMoniker,&IID_IMoniker> pMon;
  2103. CComPtr<IBindCtx> pBindCtx;
  2104. if (ppBindingManager) {
  2105. *ppBindingManager = NULL;
  2106. }
  2107. if (!ppBindingManager) {
  2108. return (E_POINTER);
  2109. }
  2110. hrRes = get_BindingManagerMoniker(&pUnkMon);
  2111. if (!SUCCEEDED(hrRes)) {
  2112. return (hrRes);
  2113. }
  2114. pMon = pUnkMon;
  2115. if (!pMon) {
  2116. return (E_NOINTERFACE);
  2117. }
  2118. hrRes = CreateBindCtx(0,&pBindCtx);
  2119. if (!SUCCEEDED(hrRes)) {
  2120. return (hrRes);
  2121. }
  2122. hrRes = pMon->BindToObject(pBindCtx,NULL,IID_IEventBindingManager,(LPVOID *) ppBindingManager);
  2123. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2124. }
  2125. HRESULT STDMETHODCALLTYPE CEventSource::get_Properties(IEventPropertyBag **ppProperties) {
  2126. DEBUG_OBJECT_CHECK
  2127. HRESULT hrRes;
  2128. if (ppProperties) {
  2129. *ppProperties = NULL;
  2130. }
  2131. if (!ppProperties) {
  2132. return (E_POINTER);
  2133. }
  2134. if (!m_pDatabase) {
  2135. _ASSERTE(FALSE);
  2136. return (E_FAIL);
  2137. }
  2138. if (!m_pTmpDatabase) {
  2139. hrRes = CopyPropertyBag(m_pDatabase,&m_pTmpDatabase);
  2140. if (!SUCCEEDED(hrRes)) {
  2141. return (hrRes);
  2142. }
  2143. }
  2144. *ppProperties = m_pTmpDatabase;
  2145. (*ppProperties)->AddRef();
  2146. return (S_OK);
  2147. }
  2148. HRESULT STDMETHODCALLTYPE CEventSource::Save() {
  2149. DEBUG_OBJECT_CHECK
  2150. return (SaveImpl(m_strName,m_pDatabase,m_pTmpDatabase,m_pParent));
  2151. }
  2152. /////////////////////////////////////////////////////////////////////////////
  2153. // CEventSourcesEnum
  2154. class ATL_NO_VTABLE CEventSourcesEnum :
  2155. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  2156. // public CComCoClass<CEventSourcesEnum, &CLSID_CEventSourcesEnum>,
  2157. public CEventEnumVARIANTBaseImpl<CEventSource,CEventSourcesEnum>,
  2158. public CEventEnumUnknownBaseImpl<CEventSource,CEventSourcesEnum>
  2159. {
  2160. DEBUG_OBJECT_DEF(CEventSourcesEnum)
  2161. public:
  2162. HRESULT FinalConstruct();
  2163. void FinalRelease();
  2164. DECLARE_PROTECT_FINAL_CONSTRUCT();
  2165. DECLARE_NOT_AGGREGATABLE(CEventSourcesEnum);
  2166. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  2167. // L"EventSourcesEnum Class",
  2168. // L"Event.SourcesEnum.1",
  2169. // L"Event.SourcesEnum");
  2170. DECLARE_GET_CONTROLLING_UNKNOWN();
  2171. BEGIN_COM_MAP(CEventSourcesEnum)
  2172. COM_INTERFACE_ENTRY(IEnumVARIANT)
  2173. COM_INTERFACE_ENTRY(IEnumUnknown)
  2174. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  2175. END_COM_MAP()
  2176. // IEventEnumBase
  2177. public:
  2178. virtual HRESULT SetEnum(IUnknown *pEnum, IEventPropertyBag *pCollection);
  2179. virtual IUnknown *GetEnum() { _ASSERTE(m_pEnum); return (m_pEnum); };
  2180. virtual IEventPropertyBag *GetCollection() { _ASSERTE(m_pCollection); return (m_pCollection); };
  2181. private:
  2182. CComPtr<IUnknown> m_pEnum;
  2183. CComPtr<IEventPropertyBag> m_pCollection;
  2184. CComPtr<IUnknown> m_pUnkMarshaler;
  2185. };
  2186. /////////////////////////////////////////////////////////////////////////////
  2187. // CEventSourcesEnum
  2188. HRESULT CEventSourcesEnum::FinalConstruct() {
  2189. DEBUG_OBJECT_CHECK
  2190. TraceFunctEnter("CEventSourcesEnum::FinalConstruct");
  2191. HRESULT hrRes = S_OK;
  2192. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  2193. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  2194. ADD_DEBUG_OBJECT("CEventSourcesEnum")
  2195. TraceFunctLeave();
  2196. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2197. }
  2198. void CEventSourcesEnum::FinalRelease() {
  2199. DEBUG_OBJECT_CHECK
  2200. TraceFunctEnter("CEventSourcesEnum::FinalRelease");
  2201. m_pUnkMarshaler.Release();
  2202. REMOVE_DEBUG_OBJECT
  2203. TraceFunctLeave();
  2204. }
  2205. HRESULT CEventSourcesEnum::SetEnum(IUnknown *pEnum, IEventPropertyBag *pCollection) {
  2206. DEBUG_OBJECT_CHECK
  2207. if (!pEnum || !pCollection) {
  2208. _ASSERTE(FALSE);
  2209. return (E_POINTER);
  2210. }
  2211. m_pEnum = pEnum;
  2212. m_pCollection = pCollection;
  2213. return (S_OK);
  2214. }
  2215. /////////////////////////////////////////////////////////////////////////////
  2216. // CEventSources
  2217. class ATL_NO_VTABLE CEventSources :
  2218. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  2219. // public CComCoClass<CEventSources, &CLSID_CEventSources>,
  2220. public IDispatchImpl<IEventSources, &IID_IEventSources, &LIBID_SEOLib>,
  2221. public CEventDatabasePlugin
  2222. {
  2223. DEBUG_OBJECT_DEF(CEventSources)
  2224. public:
  2225. HRESULT FinalConstruct();
  2226. void FinalRelease();
  2227. DECLARE_PROTECT_FINAL_CONSTRUCT();
  2228. DECLARE_NOT_AGGREGATABLE(CEventSources);
  2229. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  2230. // L"EventSources Class",
  2231. // L"Event.Sources.1",
  2232. // L"Event.Sources");
  2233. DECLARE_GET_CONTROLLING_UNKNOWN();
  2234. BEGIN_COM_MAP(CEventSources)
  2235. COM_INTERFACE_ENTRY(IEventSources)
  2236. COM_INTERFACE_ENTRY_IID(IID_IDispatch, IEventSources)
  2237. COM_INTERFACE_ENTRY(IEventDatabasePlugin)
  2238. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  2239. END_COM_MAP()
  2240. // IEventSources
  2241. public:
  2242. HRESULT STDMETHODCALLTYPE Item(VARIANT *pvarDesired, IEventSource **ppSource);
  2243. HRESULT STDMETHODCALLTYPE Add(BSTR pszSource, IEventSource **ppSource);
  2244. HRESULT STDMETHODCALLTYPE Remove(VARIANT *pvarDesired);
  2245. HRESULT STDMETHODCALLTYPE get_Count(long *plCount);
  2246. HRESULT STDMETHODCALLTYPE get__NewEnum(IUnknown **ppUnkEnum);
  2247. private:
  2248. CComPtr<IUnknown> m_pUnkMarshaler;
  2249. };
  2250. /////////////////////////////////////////////////////////////////////////////
  2251. // CEventSources
  2252. HRESULT CEventSources::FinalConstruct() {
  2253. DEBUG_OBJECT_CHECK
  2254. TraceFunctEnter("CEventSources::FinalConstruct");
  2255. HRESULT hrRes = S_OK;
  2256. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  2257. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  2258. ADD_DEBUG_OBJECT("CEventSources")
  2259. TraceFunctLeave();
  2260. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2261. }
  2262. void CEventSources::FinalRelease() {
  2263. DEBUG_OBJECT_CHECK
  2264. TraceFunctEnter("CEventSources::FinalRelease");
  2265. m_pUnkMarshaler.Release();
  2266. REMOVE_DEBUG_OBJECT
  2267. TraceFunctLeave();
  2268. }
  2269. HRESULT STDMETHODCALLTYPE CEventSources::Item(VARIANT *pvarDesired, IEventSource **ppSource) {
  2270. DEBUG_OBJECT_CHECK
  2271. return (CreatePluggedInObject(CComObject<CEventSource>::_CreatorClass::CreateInstance,
  2272. m_pDatabase,
  2273. pvarDesired,
  2274. IID_IEventSource,
  2275. (IUnknown **) ppSource,
  2276. FALSE));
  2277. }
  2278. HRESULT STDMETHODCALLTYPE CEventSources::Add(BSTR pszSource, IEventSource **ppSource) {
  2279. DEBUG_OBJECT_CHECK
  2280. HRESULT hrRes;
  2281. CComVariant varName;
  2282. CStringGUID objGuid;
  2283. if (ppSource) {
  2284. *ppSource = NULL;
  2285. }
  2286. hrRes = AddImpl1(pszSource,objGuid,&varName);
  2287. if (!SUCCEEDED(hrRes)) {
  2288. return (hrRes);
  2289. }
  2290. _ASSERTE(varName.vt==VT_BSTR);
  2291. hrRes = Item(&varName,ppSource);
  2292. if (!SUCCEEDED(hrRes)) {
  2293. return (hrRes);
  2294. }
  2295. if (hrRes != S_FALSE) {
  2296. return (S_FALSE);
  2297. }
  2298. hrRes = AddImpl2(m_pDatabase,
  2299. CComObject<CEventSource>::_CreatorClass::CreateInstance,
  2300. IID_IEventSource,
  2301. &varName,
  2302. (IUnknown **) ppSource);
  2303. _ASSERTE(!SUCCEEDED(hrRes)||*ppSource);
  2304. return (hrRes);
  2305. }
  2306. HRESULT STDMETHODCALLTYPE CEventSources::Remove(VARIANT *pvarDesired) {
  2307. DEBUG_OBJECT_CHECK
  2308. if (!m_pDatabase) {
  2309. _ASSERTE(FALSE);
  2310. return (E_FAIL);
  2311. }
  2312. return (m_pDatabase->Remove(pvarDesired));
  2313. }
  2314. HRESULT STDMETHODCALLTYPE CEventSources::get_Count(long *plCount) {
  2315. DEBUG_OBJECT_CHECK
  2316. if (plCount) {
  2317. *plCount = 0;
  2318. }
  2319. if (!plCount) {
  2320. return (E_POINTER);
  2321. }
  2322. if (!m_pDatabase) {
  2323. _ASSERTE(FALSE);
  2324. return (E_FAIL);
  2325. }
  2326. return (m_pDatabase->get_Count(plCount));
  2327. }
  2328. HRESULT STDMETHODCALLTYPE CEventSources::get__NewEnum(IUnknown **ppUnkEnum) {
  2329. DEBUG_OBJECT_CHECK
  2330. HRESULT hrRes;
  2331. CComPtr<IUnknown> pUnkTmp;
  2332. CComObject<CEventSourcesEnum> *pNewEnum;
  2333. if (ppUnkEnum) {
  2334. *ppUnkEnum = NULL;
  2335. }
  2336. if (!ppUnkEnum) {
  2337. return (E_POINTER);
  2338. }
  2339. if (!m_pDatabase) {
  2340. _ASSERTE(FALSE);
  2341. return (E_FAIL);
  2342. }
  2343. hrRes = m_pDatabase->get__NewEnum(&pUnkTmp);
  2344. if (!SUCCEEDED(hrRes)) {
  2345. return (hrRes);
  2346. }
  2347. _ASSERTE(pUnkTmp);
  2348. hrRes = CComObject<CEventSourcesEnum>::CreateInstance(&pNewEnum);
  2349. if (!SUCCEEDED(hrRes)) {
  2350. return (hrRes);
  2351. }
  2352. _ASSERTE(pNewEnum);
  2353. pNewEnum->AddRef();
  2354. hrRes = pNewEnum->SetEnum(pUnkTmp,m_pDatabase);
  2355. if (!SUCCEEDED(hrRes)) {
  2356. pNewEnum->Release();
  2357. return (hrRes);
  2358. }
  2359. hrRes = pNewEnum->QueryInterface(IID_IEnumVARIANT,(LPVOID *) ppUnkEnum);
  2360. pNewEnum->Release();
  2361. if (!SUCCEEDED(hrRes)) {
  2362. return (hrRes);
  2363. }
  2364. _ASSERTE(*ppUnkEnum);
  2365. return (S_OK);
  2366. }
  2367. /////////////////////////////////////////////////////////////////////////////
  2368. // CEventSourceType
  2369. class ATL_NO_VTABLE CEventSourceType :
  2370. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  2371. // public CComCoClass<CEventSourceType, &CLSID_CEventSourceType>,
  2372. public IDispatchImpl<IEventSourceType, &IID_IEventSourceType, &LIBID_SEOLib>,
  2373. public CEventDatabasePlugin
  2374. {
  2375. DEBUG_OBJECT_DEF(CEventSourceType)
  2376. public:
  2377. HRESULT FinalConstruct();
  2378. void FinalRelease();
  2379. DECLARE_PROTECT_FINAL_CONSTRUCT();
  2380. DECLARE_NOT_AGGREGATABLE(CEventSourceType);
  2381. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  2382. // L"EventSourceType Class",
  2383. // L"Event.Source.1",
  2384. // L"Event.Source");
  2385. DECLARE_GET_CONTROLLING_UNKNOWN();
  2386. BEGIN_COM_MAP(CEventSourceType)
  2387. COM_INTERFACE_ENTRY(IEventSourceType)
  2388. COM_INTERFACE_ENTRY_IID(IID_IDispatch, IEventSourceType)
  2389. COM_INTERFACE_ENTRY(IEventDatabasePlugin)
  2390. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  2391. END_COM_MAP()
  2392. // IEventSourceType
  2393. public:
  2394. HRESULT STDMETHODCALLTYPE get_ID(BSTR *pstrID);
  2395. HRESULT STDMETHODCALLTYPE get_DisplayName(BSTR *pstrDisplayName);
  2396. HRESULT STDMETHODCALLTYPE put_DisplayName(BSTR pszDisplayName);
  2397. HRESULT STDMETHODCALLTYPE putref_DisplayName(BSTR *ppszDisplayName);
  2398. HRESULT STDMETHODCALLTYPE get_EventTypes(IEventTypes **ppEventTypes);
  2399. HRESULT STDMETHODCALLTYPE get_Sources(IEventSources **ppSources);
  2400. HRESULT STDMETHODCALLTYPE Save();
  2401. private:
  2402. CComPtr<IEventPropertyBag> m_pTmpDatabase;
  2403. CComPtr<IUnknown> m_pUnkMarshaler;
  2404. };
  2405. /////////////////////////////////////////////////////////////////////////////
  2406. // CEventSourceType
  2407. HRESULT CEventSourceType::FinalConstruct() {
  2408. DEBUG_OBJECT_CHECK
  2409. TraceFunctEnter("CEventSourceType::FinalConstruct");
  2410. HRESULT hrRes = S_OK;
  2411. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  2412. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  2413. ADD_DEBUG_OBJECT("CEventSourceType")
  2414. TraceFunctLeave();
  2415. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2416. }
  2417. void CEventSourceType::FinalRelease() {
  2418. DEBUG_OBJECT_CHECK
  2419. TraceFunctEnter("CEventSourceType::FinalRelease");
  2420. m_pUnkMarshaler.Release();
  2421. REMOVE_DEBUG_OBJECT
  2422. TraceFunctLeave();
  2423. }
  2424. HRESULT STDMETHODCALLTYPE CEventSourceType::get_ID(BSTR *pstrID) {
  2425. DEBUG_OBJECT_CHECK
  2426. _ASSERTE(m_strName);
  2427. if (!pstrID) {
  2428. return (E_POINTER);
  2429. }
  2430. *pstrID = SysAllocString(m_strName);
  2431. if (!*pstrID) {
  2432. return (E_OUTOFMEMORY);
  2433. }
  2434. return (S_OK);
  2435. }
  2436. HRESULT STDMETHODCALLTYPE CEventSourceType::get_DisplayName(BSTR *pstrDisplayName) {
  2437. DEBUG_OBJECT_CHECK
  2438. CComPtr<IEventPropertyBag> pTmp = m_pTmpDatabase ? m_pTmpDatabase : m_pDatabase;
  2439. HRESULT hrRes;
  2440. CComVariant varPropValue;
  2441. if (pstrDisplayName) {
  2442. *pstrDisplayName = NULL;
  2443. }
  2444. if (!pstrDisplayName) {
  2445. return (E_POINTER);
  2446. }
  2447. if (!m_pDatabase) {
  2448. _ASSERTE(FALSE);
  2449. return (E_FAIL);
  2450. }
  2451. hrRes = pTmp->Item(&CComVariant(BD_DISPLAYNAME),&varPropValue);
  2452. if (!SUCCEEDED(hrRes)) {
  2453. return (hrRes);
  2454. }
  2455. if (hrRes == S_FALSE) {
  2456. *pstrDisplayName = SysAllocString(L"");
  2457. } else {
  2458. hrRes = varPropValue.ChangeType(VT_BSTR);
  2459. if (!SUCCEEDED(hrRes)) {
  2460. return (hrRes);
  2461. }
  2462. *pstrDisplayName = SysAllocString(varPropValue.bstrVal);
  2463. }
  2464. if (!*pstrDisplayName) {
  2465. return (E_OUTOFMEMORY);
  2466. }
  2467. return (S_OK);
  2468. }
  2469. HRESULT STDMETHODCALLTYPE CEventSourceType::put_DisplayName(BSTR pszDisplayName) {
  2470. DEBUG_OBJECT_CHECK
  2471. HRESULT hrRes;
  2472. CComVariant varPropValue;
  2473. if (!m_pDatabase) {
  2474. _ASSERTE(FALSE);
  2475. return (E_FAIL);
  2476. }
  2477. if (!m_pTmpDatabase) {
  2478. hrRes = CopyPropertyBag(m_pDatabase,&m_pTmpDatabase);
  2479. if (!SUCCEEDED(hrRes)) {
  2480. return (hrRes);
  2481. }
  2482. _ASSERTE(m_pTmpDatabase);
  2483. }
  2484. if (pszDisplayName) {
  2485. varPropValue = pszDisplayName;
  2486. } else {
  2487. varPropValue = L"";
  2488. }
  2489. hrRes = m_pTmpDatabase->Add(BD_DISPLAYNAME,&varPropValue);
  2490. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2491. }
  2492. HRESULT STDMETHODCALLTYPE CEventSourceType::putref_DisplayName(BSTR *ppszDisplayName) {
  2493. DEBUG_OBJECT_CHECK
  2494. if (!ppszDisplayName) {
  2495. return (E_POINTER);
  2496. }
  2497. return (put_DisplayName(*ppszDisplayName));
  2498. }
  2499. HRESULT STDMETHODCALLTYPE CEventSourceType::get_EventTypes(IEventTypes **ppEventTypes) {
  2500. DEBUG_OBJECT_CHECK
  2501. if (!m_pDatabase) {
  2502. _ASSERTE(FALSE);
  2503. return (E_FAIL);
  2504. }
  2505. return (CreatePluggedInObject(CComObject<CEventTypes>::_CreatorClass::CreateInstance,
  2506. m_pTmpDatabase?m_pTmpDatabase:m_pDatabase,
  2507. &CComVariant(BD_EVENTTYPES),
  2508. IID_IEventTypes,
  2509. (IUnknown **) ppEventTypes,
  2510. TRUE));
  2511. }
  2512. HRESULT STDMETHODCALLTYPE CEventSourceType::get_Sources(IEventSources **ppSources) {
  2513. DEBUG_OBJECT_CHECK
  2514. if (!m_pDatabase) {
  2515. _ASSERTE(FALSE);
  2516. return (E_FAIL);
  2517. }
  2518. return (CreatePluggedInObject(CComObject<CEventSources>::_CreatorClass::CreateInstance,
  2519. m_pTmpDatabase?m_pTmpDatabase:m_pDatabase,
  2520. &CComVariant(BD_SOURCES),
  2521. IID_IEventSources,
  2522. (IUnknown **) ppSources,
  2523. TRUE));
  2524. }
  2525. HRESULT STDMETHODCALLTYPE CEventSourceType::Save() {
  2526. DEBUG_OBJECT_CHECK
  2527. return (SaveImpl(m_strName,m_pDatabase,m_pTmpDatabase,m_pParent));
  2528. }
  2529. /////////////////////////////////////////////////////////////////////////////
  2530. // CEventSourceTypesEnum
  2531. class ATL_NO_VTABLE CEventSourceTypesEnum :
  2532. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  2533. // public CComCoClass<CEventSourceTypesEnum, &CLSID_CEventSourceTypesEnum>,
  2534. public CEventEnumVARIANTBaseImpl<CEventSourceType,CEventSourceTypesEnum>,
  2535. public CEventEnumUnknownBaseImpl<CEventSourceType,CEventSourceTypesEnum>
  2536. {
  2537. DEBUG_OBJECT_DEF(CEventSourceTypesEnum)
  2538. public:
  2539. HRESULT FinalConstruct();
  2540. void FinalRelease();
  2541. DECLARE_PROTECT_FINAL_CONSTRUCT();
  2542. DECLARE_NOT_AGGREGATABLE(CEventSourceTypesEnum);
  2543. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  2544. // L"EventSourceTypesEnum Class",
  2545. // L"Event.SourcesEnum.1",
  2546. // L"Event.SourcesEnum");
  2547. DECLARE_GET_CONTROLLING_UNKNOWN();
  2548. BEGIN_COM_MAP(CEventSourceTypesEnum)
  2549. COM_INTERFACE_ENTRY(IEnumVARIANT)
  2550. COM_INTERFACE_ENTRY(IEnumUnknown)
  2551. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  2552. END_COM_MAP()
  2553. // IEventEnumBase
  2554. public:
  2555. virtual HRESULT SetEnum(IUnknown *pEnum, IEventPropertyBag *pCollection);
  2556. virtual IUnknown *GetEnum() { _ASSERTE(m_pEnum); return (m_pEnum); };
  2557. virtual IEventPropertyBag *GetCollection() { _ASSERTE(m_pCollection); return (m_pCollection); };
  2558. private:
  2559. CComPtr<IUnknown> m_pEnum;
  2560. CComPtr<IEventPropertyBag> m_pCollection;
  2561. CComPtr<IUnknown> m_pUnkMarshaler;
  2562. };
  2563. /////////////////////////////////////////////////////////////////////////////
  2564. // CEventSourceTypesEnum
  2565. HRESULT CEventSourceTypesEnum::FinalConstruct() {
  2566. DEBUG_OBJECT_CHECK
  2567. TraceFunctEnter("CEventSourceTypesEnum::FinalConstruct");
  2568. HRESULT hrRes = S_OK;
  2569. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  2570. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  2571. ADD_DEBUG_OBJECT("CEventSourceTypesEnum")
  2572. TraceFunctLeave();
  2573. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2574. }
  2575. void CEventSourceTypesEnum::FinalRelease() {
  2576. DEBUG_OBJECT_CHECK
  2577. TraceFunctEnter("CEventSourceTypesEnum::FinalRelease");
  2578. m_pUnkMarshaler.Release();
  2579. REMOVE_DEBUG_OBJECT
  2580. TraceFunctLeave();
  2581. }
  2582. HRESULT CEventSourceTypesEnum::SetEnum(IUnknown *pEnum, IEventPropertyBag *pCollection) {
  2583. DEBUG_OBJECT_CHECK
  2584. if (!pEnum || !pCollection) {
  2585. _ASSERTE(FALSE);
  2586. return (E_POINTER);
  2587. }
  2588. m_pEnum = pEnum;
  2589. m_pCollection = pCollection;
  2590. return (S_OK);
  2591. }
  2592. /////////////////////////////////////////////////////////////////////////////
  2593. // CEventSourceTypes
  2594. class ATL_NO_VTABLE CEventSourceTypes :
  2595. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  2596. // public CComCoClass<CEventSourceTypes, &CLSID_CEventSourceTypes>,
  2597. public IDispatchImpl<IEventSourceTypes, &IID_IEventSourceTypes, &LIBID_SEOLib>,
  2598. public CEventDatabasePlugin
  2599. {
  2600. DEBUG_OBJECT_DEF(CEventSourceTypes)
  2601. public:
  2602. HRESULT FinalConstruct();
  2603. void FinalRelease();
  2604. DECLARE_PROTECT_FINAL_CONSTRUCT();
  2605. DECLARE_NOT_AGGREGATABLE(CEventSourceTypes);
  2606. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  2607. // L"EventSourceTypes Class",
  2608. // L"Event.SourceTypes.1",
  2609. // L"Event.SourceTypes");
  2610. DECLARE_GET_CONTROLLING_UNKNOWN();
  2611. BEGIN_COM_MAP(CEventSourceTypes)
  2612. COM_INTERFACE_ENTRY(IEventSourceTypes)
  2613. COM_INTERFACE_ENTRY_IID(IID_IDispatch, IEventSourceTypes)
  2614. COM_INTERFACE_ENTRY(IEventDatabasePlugin)
  2615. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  2616. END_COM_MAP()
  2617. // IEventSourceTypes
  2618. public:
  2619. HRESULT STDMETHODCALLTYPE Item(VARIANT *pvarDesired, IEventSourceType **ppSourceType);
  2620. HRESULT STDMETHODCALLTYPE Add(BSTR pszSourceType, IEventSourceType **ppSourceType);
  2621. HRESULT STDMETHODCALLTYPE Remove(VARIANT *pvarDesired);
  2622. HRESULT STDMETHODCALLTYPE get_Count(long *plCount);
  2623. HRESULT STDMETHODCALLTYPE get__NewEnum(IUnknown **ppUnkEnum);
  2624. private:
  2625. CComPtr<IUnknown> m_pUnkMarshaler;
  2626. };
  2627. /////////////////////////////////////////////////////////////////////////////
  2628. // CEventSourceTypes
  2629. HRESULT CEventSourceTypes::FinalConstruct() {
  2630. DEBUG_OBJECT_CHECK
  2631. TraceFunctEnter("CEventSourceTypes::FinalConstruct");
  2632. HRESULT hrRes = S_OK;
  2633. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  2634. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  2635. ADD_DEBUG_OBJECT("CEventSourceTypes")
  2636. TraceFunctLeave();
  2637. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2638. }
  2639. void CEventSourceTypes::FinalRelease() {
  2640. DEBUG_OBJECT_CHECK
  2641. TraceFunctEnter("CEventSourceTypes::FinalRelease");
  2642. m_pUnkMarshaler.Release();
  2643. REMOVE_DEBUG_OBJECT
  2644. TraceFunctLeave();
  2645. }
  2646. HRESULT STDMETHODCALLTYPE CEventSourceTypes::Item(VARIANT *pvarDesired, IEventSourceType **ppSourceType) {
  2647. DEBUG_OBJECT_CHECK
  2648. return (CreatePluggedInObject(CComObject<CEventSourceType>::_CreatorClass::CreateInstance,
  2649. m_pDatabase,
  2650. pvarDesired,
  2651. IID_IEventSourceType,
  2652. (IUnknown **) ppSourceType,
  2653. FALSE));
  2654. }
  2655. HRESULT STDMETHODCALLTYPE CEventSourceTypes::Add(BSTR pszSourceType, IEventSourceType **ppSourceType) {
  2656. DEBUG_OBJECT_CHECK
  2657. HRESULT hrRes;
  2658. CComVariant varName;
  2659. CStringGUID objGuid;
  2660. if (ppSourceType) {
  2661. *ppSourceType = NULL;
  2662. }
  2663. hrRes = AddImpl1(pszSourceType,objGuid,&varName);
  2664. if (!SUCCEEDED(hrRes)) {
  2665. return (hrRes);
  2666. }
  2667. _ASSERTE(varName.vt==VT_BSTR);
  2668. hrRes = Item(&varName,ppSourceType);
  2669. if (!SUCCEEDED(hrRes)) {
  2670. return (hrRes);
  2671. }
  2672. if (hrRes != S_FALSE) {
  2673. return (S_FALSE);
  2674. }
  2675. hrRes = AddImpl2(m_pDatabase,
  2676. CComObject<CEventSourceType>::_CreatorClass::CreateInstance,
  2677. IID_IEventSourceType,
  2678. &varName,
  2679. (IUnknown **) ppSourceType);
  2680. _ASSERTE(!SUCCEEDED(hrRes)||*ppSourceType);
  2681. return (hrRes);
  2682. }
  2683. HRESULT STDMETHODCALLTYPE CEventSourceTypes::Remove(VARIANT *pvarDesired) {
  2684. DEBUG_OBJECT_CHECK
  2685. if (!m_pDatabase) {
  2686. _ASSERTE(FALSE);
  2687. return (E_FAIL);
  2688. }
  2689. return (m_pDatabase->Remove(pvarDesired));
  2690. }
  2691. HRESULT STDMETHODCALLTYPE CEventSourceTypes::get_Count(long *plCount) {
  2692. DEBUG_OBJECT_CHECK
  2693. if (plCount) {
  2694. *plCount = 0;
  2695. }
  2696. if (!plCount) {
  2697. return (E_POINTER);
  2698. }
  2699. if (!m_pDatabase) {
  2700. _ASSERTE(FALSE);
  2701. return (E_FAIL);
  2702. }
  2703. return (m_pDatabase->get_Count(plCount));
  2704. }
  2705. HRESULT STDMETHODCALLTYPE CEventSourceTypes::get__NewEnum(IUnknown **ppUnkEnum) {
  2706. DEBUG_OBJECT_CHECK
  2707. HRESULT hrRes;
  2708. CComPtr<IUnknown> pUnkTmp;
  2709. CComObject<CEventSourceTypesEnum> *pNewEnum;
  2710. if (ppUnkEnum) {
  2711. *ppUnkEnum = NULL;
  2712. }
  2713. if (!ppUnkEnum) {
  2714. return (E_POINTER);
  2715. }
  2716. if (!m_pDatabase) {
  2717. _ASSERTE(FALSE);
  2718. return (E_FAIL);
  2719. }
  2720. hrRes = m_pDatabase->get__NewEnum(&pUnkTmp);
  2721. if (!SUCCEEDED(hrRes)) {
  2722. return (hrRes);
  2723. }
  2724. hrRes = CComObject<CEventSourceTypesEnum>::CreateInstance(&pNewEnum);
  2725. if (!SUCCEEDED(hrRes)) {
  2726. return (hrRes);
  2727. }
  2728. _ASSERTE(pNewEnum);
  2729. pNewEnum->AddRef();
  2730. hrRes = pNewEnum->SetEnum(pUnkTmp,m_pDatabase);
  2731. if (!SUCCEEDED(hrRes)) {
  2732. pNewEnum->Release();
  2733. return (hrRes);
  2734. }
  2735. hrRes = pNewEnum->QueryInterface(IID_IEnumVARIANT,(LPVOID *) ppUnkEnum);
  2736. pNewEnum->Release();
  2737. if (!SUCCEEDED(hrRes)) {
  2738. return (hrRes);
  2739. }
  2740. _ASSERTE(*ppUnkEnum);
  2741. return (S_OK);
  2742. }
  2743. /////////////////////////////////////////////////////////////////////////////
  2744. // CEventManager
  2745. HRESULT CEventManager::FinalConstruct() {
  2746. DEBUG_OBJECT_CHECK
  2747. TraceFunctEnter("CEventManager::FinalConstruct");
  2748. HRESULT hrRes = S_OK;
  2749. CComPtr<IEventPropertyBag> pDatabaseRoot;
  2750. CComPtr<IEventPropertyBag> pDatabase;
  2751. ADD_DEBUG_OBJECT("CEventManager")
  2752. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  2753. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  2754. if (!SUCCEEDED(hrRes)) {
  2755. TraceFunctLeave();
  2756. return (hrRes);
  2757. }
  2758. _ASSERTE(m_pUnkMarshaler);
  2759. hrRes = CoCreateInstance(CLSID_CSEOMetaDictionary,
  2760. NULL,
  2761. CLSCTX_ALL,
  2762. IID_IEventPropertyBag,
  2763. (LPVOID *) &pDatabaseRoot);
  2764. if (!SUCCEEDED(hrRes)) {
  2765. TraceFunctLeave();
  2766. return (hrRes);
  2767. }
  2768. _ASSERTE(pDatabaseRoot);
  2769. hrRes = CreateSubPropertyBag(pDatabaseRoot,&CComVariant(L"LM/EventManager"),&pDatabase,TRUE);
  2770. if (!SUCCEEDED(hrRes)) {
  2771. TraceFunctLeave();
  2772. return (hrRes);
  2773. }
  2774. _ASSERTE(pDatabase);
  2775. hrRes = put_Database(pDatabase);
  2776. if (!SUCCEEDED(hrRes)) {
  2777. TraceFunctLeave();
  2778. return (hrRes);
  2779. }
  2780. hrRes = CoCreateInstance(CLSID_CEventLock,NULL,CLSCTX_ALL,IID_IEventLock,(LPVOID *) &m_pLock);
  2781. if (!SUCCEEDED(hrRes)) {
  2782. TraceFunctLeave();
  2783. return (hrRes);
  2784. }
  2785. TraceFunctLeave();
  2786. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  2787. }
  2788. void CEventManager::FinalRelease() {
  2789. DEBUG_OBJECT_CHECK
  2790. TraceFunctEnter("CEventManager::FinalRelease");
  2791. m_pUnkMarshaler.Release();
  2792. REMOVE_DEBUG_OBJECT
  2793. TraceFunctLeave();
  2794. }
  2795. HRESULT STDMETHODCALLTYPE CEventManager::get_SourceTypes(IEventSourceTypes **ppSourceTypes) {
  2796. DEBUG_OBJECT_CHECK
  2797. return (CreatePluggedInObject(CComObject<CEventSourceTypes>::_CreatorClass::CreateInstance,
  2798. m_pDatabase,
  2799. &CComVariant(BD_SOURCETYPES),
  2800. IID_IEventSourceTypes,
  2801. (IUnknown **) ppSourceTypes,
  2802. TRUE));
  2803. }
  2804. HRESULT STDMETHODCALLTYPE CEventManager::CreateSink(IEventBinding *pEventBinding,
  2805. IEventDeliveryOptions *pDeliveryOptions,
  2806. IUnknown **ppUnkSink) {
  2807. DEBUG_OBJECT_CHECK
  2808. HRESULT hrRes;
  2809. CComBSTR strSinkClass;
  2810. CComPtr<IEventPropertyBag> pSinkProperties;
  2811. CComQIPtr<CCreateSinkInfo,&IID_ICreateSinkInfo> pInfo;
  2812. CLocker lck(LOCK_TIMEOUT);
  2813. CComPtr<IUnknown> pSink;
  2814. CComQIPtr<IEventIsCacheable,&IID_IEventIsCacheable> pCache;
  2815. VARIANT varSinkClass;
  2816. VARIANT_BOOL bEnabled;
  2817. if (ppUnkSink) {
  2818. *ppUnkSink = NULL;
  2819. }
  2820. _ASSERTE(m_pLock);
  2821. if (!ppUnkSink || !pEventBinding) {
  2822. return (E_POINTER);
  2823. }
  2824. hrRes = lck.LockRead(m_pLock);
  2825. if (!SUCCEEDED(hrRes)) {
  2826. return (hrRes);
  2827. }
  2828. pInfo = pEventBinding;
  2829. if (pInfo && pInfo->m_bInit) {
  2830. again:
  2831. lck.Unlock();
  2832. if (!pInfo->m_bEnabled) {
  2833. return (EVENTS_E_DISABLED);
  2834. }
  2835. if (pInfo->m_pSink) {
  2836. *ppUnkSink = pInfo->m_pSink;
  2837. (*ppUnkSink)->AddRef();
  2838. return (S_OK);
  2839. }
  2840. if (pSink) {
  2841. *ppUnkSink = pSink;
  2842. (*ppUnkSink)->AddRef();
  2843. return (S_OK);
  2844. }
  2845. varSinkClass.vt = VT_BYREF|VT_BSTR;
  2846. varSinkClass.pbstrVal = &pInfo->m_strSinkClass;
  2847. hrRes = SEOCreateObjectEx(&varSinkClass,
  2848. pEventBinding,
  2849. pInfo->m_pSinkProperties,
  2850. IID_IUnknown,
  2851. pDeliveryOptions,
  2852. ppUnkSink);
  2853. return (hrRes);
  2854. }
  2855. lck.Unlock();
  2856. hrRes = pEventBinding->get_SinkProperties(&pSinkProperties);
  2857. if (!SUCCEEDED(hrRes)) {
  2858. return (hrRes);
  2859. }
  2860. hrRes = pEventBinding->get_SinkClass(&strSinkClass);
  2861. if (!SUCCEEDED(hrRes)) {
  2862. return (hrRes);
  2863. }
  2864. hrRes = pEventBinding->get_Enabled(&bEnabled);
  2865. if (!SUCCEEDED(hrRes)) {
  2866. return (hrRes);
  2867. }
  2868. if (bEnabled) {
  2869. varSinkClass.vt = VT_BYREF|VT_BSTR;
  2870. varSinkClass.pbstrVal = &strSinkClass;
  2871. hrRes = SEOCreateObjectEx(&varSinkClass,
  2872. pEventBinding,
  2873. pSinkProperties,
  2874. IID_IUnknown,
  2875. pDeliveryOptions,
  2876. &pSink);
  2877. if (!SUCCEEDED(hrRes)) {
  2878. return (hrRes);
  2879. }
  2880. }
  2881. if (!pInfo) {
  2882. if (!bEnabled) {
  2883. return (EVENTS_E_DISABLED);
  2884. }
  2885. *ppUnkSink = pSink;
  2886. (*ppUnkSink)->AddRef();
  2887. return (hrRes);
  2888. }
  2889. hrRes = lck.LockWrite(m_pLock);
  2890. if (!SUCCEEDED(hrRes)) {
  2891. return (hrRes);
  2892. }
  2893. if (pInfo->m_bInit) {
  2894. pSink.Release();
  2895. goto again;
  2896. }
  2897. pInfo->m_bInit = TRUE;
  2898. pInfo->m_strSinkClass.Attach(strSinkClass.Detach());
  2899. pInfo->m_bEnabled = bEnabled ? TRUE : FALSE;
  2900. if (pInfo->m_bEnabled) {
  2901. pCache = pSink;
  2902. if (pCache && (pCache->IsCacheable() == S_OK)) {
  2903. pInfo->m_pSink = pSink;
  2904. }
  2905. }
  2906. pInfo->m_pSinkProperties = pSinkProperties;
  2907. goto again;
  2908. }
  2909. #if 0
  2910. HRESULT STDMETHODCALLTYPE CEventManager::CreateSink(IEventBinding *pEventBinding,
  2911. IEventDeliveryOptions *pDeliveryOptions,
  2912. IUnknown **ppUnkSink) {
  2913. DEBUG_OBJECT_CHECK
  2914. HRESULT hrRes;
  2915. CComBSTR strProgID;
  2916. CComPtr<IEventPropertyBag> pProperties;
  2917. if (ppUnkSink) {
  2918. *ppUnkSink = NULL;
  2919. }
  2920. if (!ppUnkSink || !pEventBinding) {
  2921. return (E_POINTER);
  2922. }
  2923. hrRes = pEventBinding->get_SinkProperties(&pProperties);
  2924. if (!SUCCEEDED(hrRes)) {
  2925. return (hrRes);
  2926. }
  2927. hrRes = pEventBinding->get_SinkClass(&strProgID);
  2928. if (!SUCCEEDED(hrRes)) {
  2929. return (hrRes);
  2930. }
  2931. hrRes = SEOCreateObject(&CComVariant(strProgID),pEventBinding,pProperties,IID_IUnknown,ppUnkSink);
  2932. return (hrRes);
  2933. }
  2934. #endif
  2935. /////////////////////////////////////////////////////////////////////////////
  2936. // CEventBinding
  2937. class ATL_NO_VTABLE CEventBinding :
  2938. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  2939. // public CComCoClass<CEventBinding, &CLSID_CEventBinding>,
  2940. public IDispatchImpl<IEventBinding, &IID_IEventBinding, &LIBID_SEOLib>,
  2941. public CEventDatabasePlugin,
  2942. public CCreateSinkInfo
  2943. {
  2944. DEBUG_OBJECT_DEF(CEventBinding)
  2945. public:
  2946. HRESULT FinalConstruct();
  2947. void FinalRelease();
  2948. HRESULT GetProperties(LPCOLESTR pszPropName, IEventPropertyBag **ppProperties);
  2949. HRESULT CopyForWrite();
  2950. DECLARE_PROTECT_FINAL_CONSTRUCT();
  2951. DECLARE_NOT_AGGREGATABLE(CEventBinding);
  2952. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  2953. // L"EventBinding Class",
  2954. // L"Event.Binding.1",
  2955. // L"Event.Binding");
  2956. DECLARE_GET_CONTROLLING_UNKNOWN();
  2957. BEGIN_COM_MAP(CEventBinding)
  2958. COM_INTERFACE_ENTRY(IEventBinding)
  2959. COM_INTERFACE_ENTRY_IID(IID_IDispatch, IEventBinding)
  2960. COM_INTERFACE_ENTRY(IEventDatabasePlugin)
  2961. COM_INTERFACE_ENTRY_IID(IID_ICreateSinkInfo, CCreateSinkInfo)
  2962. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  2963. END_COM_MAP()
  2964. // IEventBinding
  2965. public:
  2966. HRESULT STDMETHODCALLTYPE get_ID(BSTR *pstrID);
  2967. HRESULT STDMETHODCALLTYPE get_DisplayName(BSTR *pstrDisplayName);
  2968. HRESULT STDMETHODCALLTYPE put_DisplayName(BSTR pszDisplayName);
  2969. HRESULT STDMETHODCALLTYPE putref_DisplayName(BSTR *ppszDisplayName);
  2970. HRESULT STDMETHODCALLTYPE get_SinkClass(BSTR *pstrSinkClass);
  2971. HRESULT STDMETHODCALLTYPE put_SinkClass(BSTR pszSinkClass);
  2972. HRESULT STDMETHODCALLTYPE putref_SinkClass(BSTR *ppszSinkClass);
  2973. HRESULT STDMETHODCALLTYPE get_SinkProperties(IEventPropertyBag **ppSinkProperties);
  2974. HRESULT STDMETHODCALLTYPE get_SourceProperties(IEventPropertyBag **ppSourceProperties);
  2975. HRESULT STDMETHODCALLTYPE get_EventBindingProperties(IEventPropertyBag **ppBindingProperties);
  2976. HRESULT STDMETHODCALLTYPE get_Enabled(VARIANT_BOOL *pbEnabled);
  2977. HRESULT STDMETHODCALLTYPE put_Enabled(VARIANT_BOOL bEnabled);
  2978. HRESULT STDMETHODCALLTYPE putref_Enabled(VARIANT_BOOL *pbEnabled);
  2979. HRESULT STDMETHODCALLTYPE get_Expiration(DATE *pdateExpiration);
  2980. HRESULT STDMETHODCALLTYPE put_Expiration(DATE dateExpiration);
  2981. HRESULT STDMETHODCALLTYPE putref_Expiration(DATE *pdateExpiration);
  2982. HRESULT STDMETHODCALLTYPE get_MaxFirings(long *plMaxFirings);
  2983. HRESULT STDMETHODCALLTYPE put_MaxFirings(long lMaxFirings);
  2984. HRESULT STDMETHODCALLTYPE putref_MaxFirings(long *plMaxFirings);
  2985. HRESULT STDMETHODCALLTYPE Save();
  2986. private:
  2987. CComPtr<IEventPropertyBag> m_pTmpDatabase;
  2988. CComPtr<IUnknown> m_pUnkMarshaler;
  2989. };
  2990. /////////////////////////////////////////////////////////////////////////////
  2991. // CEventBinding
  2992. HRESULT CEventBinding::FinalConstruct() {
  2993. DEBUG_OBJECT_CHECK
  2994. TraceFunctEnter("CEventBinding::FinalConstruct");
  2995. HRESULT hrRes = S_OK;
  2996. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  2997. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  2998. m_bInit = FALSE;
  2999. ADD_DEBUG_OBJECT("CEventBinding")
  3000. TraceFunctLeave();
  3001. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  3002. }
  3003. void CEventBinding::FinalRelease() {
  3004. DEBUG_OBJECT_CHECK
  3005. TraceFunctEnter("CEventBinding::FinalRelease");
  3006. m_pUnkMarshaler.Release();
  3007. REMOVE_DEBUG_OBJECT
  3008. TraceFunctLeave();
  3009. }
  3010. HRESULT STDMETHODCALLTYPE CEventBinding::get_ID(BSTR *pstrID) {
  3011. DEBUG_OBJECT_CHECK
  3012. if (pstrID) {
  3013. *pstrID = NULL;
  3014. }
  3015. if (!pstrID) {
  3016. return (E_POINTER);
  3017. }
  3018. *pstrID = SysAllocString(m_strName);
  3019. if (!*pstrID) {
  3020. return (E_OUTOFMEMORY);
  3021. }
  3022. return (S_OK);
  3023. }
  3024. HRESULT STDMETHODCALLTYPE CEventBinding::get_DisplayName(BSTR *pstrDisplayName) {
  3025. DEBUG_OBJECT_CHECK
  3026. CComPtr<IEventPropertyBag> pTmp = m_pTmpDatabase ? m_pTmpDatabase : m_pDatabase;
  3027. HRESULT hrRes;
  3028. CComVariant varPropValue;
  3029. if (pstrDisplayName) {
  3030. *pstrDisplayName = NULL;
  3031. }
  3032. if (!pstrDisplayName) {
  3033. return (E_POINTER);
  3034. }
  3035. if (!m_pDatabase) {
  3036. _ASSERTE(FALSE);
  3037. return (E_FAIL);
  3038. }
  3039. hrRes = pTmp->Item(&CComVariant(BD_DISPLAYNAME),&varPropValue);
  3040. if (!SUCCEEDED(hrRes)) {
  3041. return (hrRes);
  3042. }
  3043. if (hrRes == S_FALSE) {
  3044. *pstrDisplayName = SysAllocString(L"");
  3045. } else {
  3046. hrRes = varPropValue.ChangeType(VT_BSTR);
  3047. if (!SUCCEEDED(hrRes)) {
  3048. return (hrRes);
  3049. }
  3050. *pstrDisplayName = SysAllocString(varPropValue.bstrVal);
  3051. }
  3052. if (!*pstrDisplayName) {
  3053. return (E_OUTOFMEMORY);
  3054. }
  3055. return (S_OK);
  3056. }
  3057. HRESULT CEventBinding::CopyForWrite() {
  3058. DEBUG_OBJECT_CHECK
  3059. HRESULT hrRes;
  3060. if (!m_pTmpDatabase) {
  3061. hrRes = CopyPropertyBag(m_pDatabase,&m_pTmpDatabase);
  3062. if (!SUCCEEDED(hrRes)) {
  3063. return (hrRes);
  3064. }
  3065. }
  3066. return (S_OK);
  3067. }
  3068. HRESULT STDMETHODCALLTYPE CEventBinding::put_DisplayName(BSTR pszDisplayName) {
  3069. DEBUG_OBJECT_CHECK
  3070. HRESULT hrRes;
  3071. CComVariant varPropValue;
  3072. if (!m_pDatabase) {
  3073. _ASSERTE(FALSE);
  3074. return (E_FAIL);
  3075. }
  3076. hrRes = CopyForWrite();
  3077. if (!SUCCEEDED(hrRes)) {
  3078. return (hrRes);
  3079. }
  3080. if (pszDisplayName) {
  3081. varPropValue = pszDisplayName;
  3082. }
  3083. hrRes = m_pTmpDatabase->Add(BD_DISPLAYNAME,&varPropValue);
  3084. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  3085. }
  3086. HRESULT STDMETHODCALLTYPE CEventBinding::putref_DisplayName(BSTR *ppszDisplayName) {
  3087. DEBUG_OBJECT_CHECK
  3088. if (!ppszDisplayName) {
  3089. return (E_POINTER);
  3090. }
  3091. return (put_DisplayName(*ppszDisplayName));
  3092. }
  3093. HRESULT STDMETHODCALLTYPE CEventBinding::get_SinkClass(BSTR *pstrSinkClass) {
  3094. DEBUG_OBJECT_CHECK
  3095. CComPtr<IEventPropertyBag> pTmp = m_pTmpDatabase ? m_pTmpDatabase : m_pDatabase;
  3096. HRESULT hrRes;
  3097. CComVariant varPropValue;
  3098. if (pstrSinkClass) {
  3099. *pstrSinkClass = NULL;
  3100. }
  3101. if (!pstrSinkClass) {
  3102. return (E_POINTER);
  3103. }
  3104. if (!m_pDatabase) {
  3105. _ASSERTE(FALSE);
  3106. return (E_FAIL);
  3107. }
  3108. hrRes = pTmp->Item(&CComVariant(BD_SINKCLASS),&varPropValue);
  3109. if (!SUCCEEDED(hrRes)) {
  3110. return (hrRes);
  3111. }
  3112. if (hrRes == S_FALSE) {
  3113. *pstrSinkClass = SysAllocString(L"");
  3114. } else {
  3115. hrRes = varPropValue.ChangeType(VT_BSTR);
  3116. if (!SUCCEEDED(hrRes)) {
  3117. return (hrRes);
  3118. }
  3119. *pstrSinkClass = SysAllocString(varPropValue.bstrVal);
  3120. }
  3121. if (!*pstrSinkClass) {
  3122. return (E_OUTOFMEMORY);
  3123. }
  3124. return (S_OK);
  3125. }
  3126. HRESULT STDMETHODCALLTYPE CEventBinding::put_SinkClass(BSTR pszSinkClass) {
  3127. DEBUG_OBJECT_CHECK
  3128. HRESULT hrRes;
  3129. CComVariant varPropValue;
  3130. if (!m_pDatabase) {
  3131. _ASSERTE(FALSE);
  3132. return (E_FAIL);
  3133. }
  3134. hrRes = CopyForWrite();
  3135. if (!SUCCEEDED(hrRes)) {
  3136. return (hrRes);
  3137. }
  3138. if (pszSinkClass) {
  3139. varPropValue = pszSinkClass;
  3140. }
  3141. hrRes = m_pTmpDatabase->Add(BD_SINKCLASS,&varPropValue);
  3142. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  3143. }
  3144. HRESULT STDMETHODCALLTYPE CEventBinding::putref_SinkClass(BSTR *ppszSinkClass) {
  3145. DEBUG_OBJECT_CHECK
  3146. if (!ppszSinkClass) {
  3147. return (E_POINTER);
  3148. }
  3149. return (put_SinkClass(*ppszSinkClass));
  3150. }
  3151. HRESULT CEventBinding::GetProperties(LPCOLESTR pszPropName, IEventPropertyBag **ppProperties) {
  3152. DEBUG_OBJECT_CHECK
  3153. HRESULT hrRes;
  3154. CComVariant varPropValue;
  3155. if (ppProperties) {
  3156. *ppProperties = NULL;
  3157. }
  3158. if (!m_pDatabase) {
  3159. _ASSERTE(FALSE);
  3160. return (E_FAIL);
  3161. }
  3162. if (!ppProperties) {
  3163. return (E_POINTER);
  3164. }
  3165. hrRes = CopyForWrite();
  3166. if (!SUCCEEDED(hrRes)) {
  3167. return (hrRes);
  3168. }
  3169. hrRes = m_pTmpDatabase->Item(&CComVariant(pszPropName),&varPropValue);
  3170. if (!SUCCEEDED(hrRes)) {
  3171. return (hrRes);
  3172. }
  3173. if (hrRes != S_FALSE) {
  3174. hrRes = varPropValue.ChangeType(VT_UNKNOWN);
  3175. if (!SUCCEEDED(hrRes)) {
  3176. varPropValue.Clear();
  3177. hrRes = S_FALSE;
  3178. } else {
  3179. CComQIPtr<IEventPropertyBag,&IID_IEventPropertyBag> pBag;
  3180. CComPtr<IEventPropertyBag> pTmp;
  3181. pBag = varPropValue.punkVal;
  3182. if (!pBag) {
  3183. varPropValue.Clear();
  3184. hrRes = S_FALSE;
  3185. }
  3186. }
  3187. }
  3188. if (hrRes == S_FALSE) {
  3189. hrRes = CoCreateInstance(CLSID_CSEOMemDictionary,
  3190. NULL,
  3191. CLSCTX_ALL,
  3192. IID_IEventPropertyBag,
  3193. (LPVOID *) &varPropValue.punkVal);
  3194. if (!SUCCEEDED(hrRes)) {
  3195. return (hrRes);
  3196. }
  3197. varPropValue.vt = VT_UNKNOWN;
  3198. hrRes = m_pTmpDatabase->Add((LPOLESTR) pszPropName,&varPropValue);
  3199. if (!SUCCEEDED(hrRes)) {
  3200. return (hrRes);
  3201. }
  3202. }
  3203. hrRes = varPropValue.punkVal->QueryInterface(IID_IEventPropertyBag,(LPVOID *) ppProperties);
  3204. _ASSERTE(SUCCEEDED(hrRes));
  3205. return (hrRes);
  3206. }
  3207. HRESULT STDMETHODCALLTYPE CEventBinding::get_SinkProperties(IEventPropertyBag **ppSinkProperties) {
  3208. DEBUG_OBJECT_CHECK
  3209. return (GetProperties(BD_SINKPROPERTIES,ppSinkProperties));
  3210. }
  3211. HRESULT STDMETHODCALLTYPE CEventBinding::get_SourceProperties(IEventPropertyBag **ppSourceProperties) {
  3212. DEBUG_OBJECT_CHECK
  3213. return (GetProperties(BD_SOURCEPROPERTIES,ppSourceProperties));
  3214. }
  3215. HRESULT STDMETHODCALLTYPE CEventBinding::get_EventBindingProperties(IEventPropertyBag **ppBindingProperties) {
  3216. DEBUG_OBJECT_CHECK
  3217. HRESULT hrRes;
  3218. if (!m_pDatabase) {
  3219. _ASSERTE(FALSE);
  3220. return (E_FAIL);
  3221. }
  3222. if (!ppBindingProperties) {
  3223. return (E_POINTER);
  3224. }
  3225. if (!m_pTmpDatabase) {
  3226. hrRes = CopyPropertyBagShallow(m_pDatabase,&m_pTmpDatabase);
  3227. if (!SUCCEEDED(hrRes)) {
  3228. return (hrRes);
  3229. }
  3230. }
  3231. *ppBindingProperties = m_pTmpDatabase;
  3232. (*ppBindingProperties)->AddRef();
  3233. return (S_OK);
  3234. }
  3235. HRESULT STDMETHODCALLTYPE CEventBinding::get_Enabled(VARIANT_BOOL *pbEnabled) {
  3236. DEBUG_OBJECT_CHECK
  3237. CComPtr<IEventPropertyBag> pTmp = m_pTmpDatabase ? m_pTmpDatabase : m_pDatabase;
  3238. HRESULT hrRes;
  3239. CComVariant varPropValue;
  3240. if (pbEnabled) {
  3241. *pbEnabled = VARIANT_TRUE;
  3242. }
  3243. if (!pbEnabled) {
  3244. return (E_POINTER);
  3245. }
  3246. if (!m_pDatabase) {
  3247. _ASSERTE(FALSE);
  3248. return (E_FAIL);
  3249. }
  3250. hrRes = pTmp->Item(&CComVariant(BD_ENABLED),&varPropValue);
  3251. if (!SUCCEEDED(hrRes)) {
  3252. return (hrRes);
  3253. }
  3254. if (hrRes != S_FALSE) {
  3255. hrRes = varPropValue.ChangeType(VT_BOOL);
  3256. if (!SUCCEEDED(hrRes)) {
  3257. return (hrRes);
  3258. }
  3259. *pbEnabled = varPropValue.boolVal;
  3260. }
  3261. return (S_OK);
  3262. }
  3263. HRESULT STDMETHODCALLTYPE CEventBinding::put_Enabled(VARIANT_BOOL bEnabled) {
  3264. DEBUG_OBJECT_CHECK
  3265. HRESULT hrRes;
  3266. CComVariant varPropValue;
  3267. if (!m_pDatabase) {
  3268. _ASSERTE(FALSE);
  3269. return (E_FAIL);
  3270. }
  3271. hrRes = CopyForWrite();
  3272. if (!SUCCEEDED(hrRes)) {
  3273. return (hrRes);
  3274. }
  3275. varPropValue = bEnabled;
  3276. hrRes = m_pTmpDatabase->Add(BD_ENABLED,&varPropValue);
  3277. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  3278. }
  3279. HRESULT STDMETHODCALLTYPE CEventBinding::putref_Enabled(VARIANT_BOOL *pbEnabled) {
  3280. DEBUG_OBJECT_CHECK
  3281. if (!pbEnabled) {
  3282. return (E_POINTER);
  3283. }
  3284. return (put_Enabled(*pbEnabled));
  3285. }
  3286. HRESULT STDMETHODCALLTYPE CEventBinding::get_Expiration(DATE *pdateExpiration) {
  3287. DEBUG_OBJECT_CHECK
  3288. CComPtr<IEventPropertyBag> pTmp = m_pTmpDatabase ? m_pTmpDatabase : m_pDatabase;
  3289. HRESULT hrRes;
  3290. CComVariant varPropValue;
  3291. if (pdateExpiration) {
  3292. *pdateExpiration = 0.0;
  3293. }
  3294. if (!pdateExpiration) {
  3295. return (E_POINTER);
  3296. }
  3297. if (!m_pDatabase) {
  3298. _ASSERTE(FALSE);
  3299. return (E_FAIL);
  3300. }
  3301. hrRes = pTmp->Item(&CComVariant(BD_EXPIRATION),&varPropValue);
  3302. if (!SUCCEEDED(hrRes)) {
  3303. return (hrRes);
  3304. }
  3305. if (hrRes == S_FALSE) {
  3306. return (S_FALSE);
  3307. }
  3308. hrRes = varPropValue.ChangeType(VT_DATE);
  3309. if (!SUCCEEDED(hrRes)) {
  3310. return (hrRes);
  3311. }
  3312. *pdateExpiration = varPropValue.date;
  3313. return (S_OK);
  3314. }
  3315. HRESULT STDMETHODCALLTYPE CEventBinding::put_Expiration(DATE dateExpiration) {
  3316. DEBUG_OBJECT_CHECK
  3317. HRESULT hrRes;
  3318. CComVariant varPropValue;
  3319. if (!m_pDatabase) {
  3320. _ASSERTE(FALSE);
  3321. return (E_FAIL);
  3322. }
  3323. hrRes = CopyForWrite();
  3324. if (!SUCCEEDED(hrRes)) {
  3325. return (hrRes);
  3326. }
  3327. if (dateExpiration != 0.0) {
  3328. varPropValue = dateExpiration;
  3329. }
  3330. hrRes = m_pTmpDatabase->Add(BD_EXPIRATION,&varPropValue);
  3331. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  3332. }
  3333. HRESULT STDMETHODCALLTYPE CEventBinding::putref_Expiration(DATE *pdateExpiration) {
  3334. DEBUG_OBJECT_CHECK
  3335. if (!pdateExpiration) {
  3336. return (E_POINTER);
  3337. }
  3338. return (put_Expiration(*pdateExpiration));
  3339. }
  3340. HRESULT STDMETHODCALLTYPE CEventBinding::get_MaxFirings(long *plMaxFirings) {
  3341. DEBUG_OBJECT_CHECK
  3342. CComPtr<IEventPropertyBag> pTmp = m_pTmpDatabase ? m_pTmpDatabase : m_pDatabase;
  3343. HRESULT hrRes;
  3344. CComVariant varPropValue;
  3345. if (plMaxFirings) {
  3346. *plMaxFirings = 0;
  3347. }
  3348. if (!plMaxFirings) {
  3349. return (E_POINTER);
  3350. }
  3351. if (!m_pDatabase) {
  3352. _ASSERTE(FALSE);
  3353. return (E_FAIL);
  3354. }
  3355. hrRes = pTmp->Item(&CComVariant(BD_MAXFIRINGS),&varPropValue);
  3356. if (!SUCCEEDED(hrRes)) {
  3357. return (hrRes);
  3358. }
  3359. if (hrRes == S_FALSE) {
  3360. return (S_FALSE);
  3361. }
  3362. hrRes = varPropValue.ChangeType(VT_I4);
  3363. if (!SUCCEEDED(hrRes)) {
  3364. return (hrRes);
  3365. }
  3366. *plMaxFirings = varPropValue.lVal;
  3367. return (S_OK);
  3368. }
  3369. HRESULT STDMETHODCALLTYPE CEventBinding::put_MaxFirings(long lMaxFirings) {
  3370. DEBUG_OBJECT_CHECK
  3371. HRESULT hrRes;
  3372. CComVariant varPropValue;
  3373. if (!m_pDatabase) {
  3374. _ASSERTE(FALSE);
  3375. return (E_FAIL);
  3376. }
  3377. hrRes = CopyForWrite();
  3378. if (!SUCCEEDED(hrRes)) {
  3379. return (hrRes);
  3380. }
  3381. if (lMaxFirings != -1) {
  3382. varPropValue = lMaxFirings;
  3383. }
  3384. hrRes = m_pTmpDatabase->Add(BD_MAXFIRINGS,&varPropValue);
  3385. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  3386. }
  3387. HRESULT STDMETHODCALLTYPE CEventBinding::putref_MaxFirings(long *plMaxFirings) {
  3388. DEBUG_OBJECT_CHECK
  3389. if (!plMaxFirings) {
  3390. return (E_POINTER);
  3391. }
  3392. return (put_MaxFirings(*plMaxFirings));
  3393. }
  3394. HRESULT STDMETHODCALLTYPE CEventBinding::Save() {
  3395. DEBUG_OBJECT_CHECK
  3396. return (SaveImpl(m_strName,m_pDatabase,m_pTmpDatabase,m_pParent));
  3397. }
  3398. /////////////////////////////////////////////////////////////////////////////
  3399. // CEventBindingsEnum
  3400. class ATL_NO_VTABLE CEventBindingsEnum :
  3401. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  3402. // public CComCoClass<CEventBindingsEnum, &CLSID_CEventBindingsEnum>,
  3403. public CEventEnumVARIANTBaseImpl<CEventBinding,CEventBindingsEnum>,
  3404. public CEventEnumUnknownBaseImpl<CEventBinding,CEventBindingsEnum>
  3405. {
  3406. DEBUG_OBJECT_DEF(CEventBindingsEnum)
  3407. public:
  3408. HRESULT FinalConstruct();
  3409. void FinalRelease();
  3410. DECLARE_PROTECT_FINAL_CONSTRUCT();
  3411. DECLARE_NOT_AGGREGATABLE(CEventBindingsEnum);
  3412. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  3413. // L"EventBindingsEnum Class",
  3414. // L"Event.BindingsEnum.1",
  3415. // L"Event.BindingsEnum");
  3416. DECLARE_GET_CONTROLLING_UNKNOWN();
  3417. BEGIN_COM_MAP(CEventBindingsEnum)
  3418. COM_INTERFACE_ENTRY(IEnumVARIANT)
  3419. COM_INTERFACE_ENTRY(IEnumUnknown)
  3420. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  3421. END_COM_MAP()
  3422. // IEventEnumBase
  3423. public:
  3424. virtual HRESULT SetEnum(IUnknown *pEnum, IEventPropertyBag *pCollection);
  3425. virtual IUnknown *GetEnum() { _ASSERTE(m_pEnum); return (m_pEnum); };
  3426. virtual IEventPropertyBag *GetCollection() { _ASSERTE(m_pCollection); return (m_pCollection); };
  3427. private:
  3428. CComPtr<IUnknown> m_pEnum;
  3429. CComPtr<IEventPropertyBag> m_pCollection;
  3430. CComPtr<IUnknown> m_pUnkMarshaler;
  3431. };
  3432. /////////////////////////////////////////////////////////////////////////////
  3433. // CEventBindingsEnum
  3434. HRESULT CEventBindingsEnum::FinalConstruct() {
  3435. DEBUG_OBJECT_CHECK
  3436. TraceFunctEnter("CEventBindingsEnum::FinalConstruct");
  3437. HRESULT hrRes = S_OK;
  3438. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  3439. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  3440. ADD_DEBUG_OBJECT("CEventBindingsEnum")
  3441. TraceFunctLeave();
  3442. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  3443. }
  3444. void CEventBindingsEnum::FinalRelease() {
  3445. DEBUG_OBJECT_CHECK
  3446. TraceFunctEnter("CEventBindingsEnum::FinalRelease");
  3447. m_pUnkMarshaler.Release();
  3448. REMOVE_DEBUG_OBJECT
  3449. TraceFunctLeave();
  3450. }
  3451. HRESULT CEventBindingsEnum::SetEnum(IUnknown *pEnum, IEventPropertyBag *pCollection) {
  3452. DEBUG_OBJECT_CHECK
  3453. if (!pEnum || !pCollection) {
  3454. _ASSERTE(FALSE);
  3455. return (E_POINTER);
  3456. }
  3457. m_pEnum = pEnum;
  3458. m_pCollection = pCollection;
  3459. return (S_OK);
  3460. }
  3461. /////////////////////////////////////////////////////////////////////////////
  3462. // CEventBindings
  3463. class ATL_NO_VTABLE CEventBindings :
  3464. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  3465. // public CComCoClass<CEventBindings, &CLSID_CEventBindings>,
  3466. public IDispatchImpl<IEventBindings, &IID_IEventBindings, &LIBID_SEOLib>,
  3467. public CEventDatabasePlugin
  3468. {
  3469. DEBUG_OBJECT_DEF(CEventBindings)
  3470. public:
  3471. HRESULT FinalConstruct();
  3472. void FinalRelease();
  3473. DECLARE_PROTECT_FINAL_CONSTRUCT();
  3474. DECLARE_NOT_AGGREGATABLE(CEventBindings);
  3475. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  3476. // L"EventBindings Class",
  3477. // L"Event.Bindings.1",
  3478. // L"Event.Bindings");
  3479. DECLARE_GET_CONTROLLING_UNKNOWN();
  3480. BEGIN_COM_MAP(CEventBindings)
  3481. COM_INTERFACE_ENTRY(IEventBindings)
  3482. COM_INTERFACE_ENTRY_IID(IID_IDispatch, IEventBindings)
  3483. COM_INTERFACE_ENTRY(IEventDatabasePlugin)
  3484. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  3485. END_COM_MAP()
  3486. // IEventBindings
  3487. public:
  3488. HRESULT STDMETHODCALLTYPE Item(VARIANT *pvarDesired, IEventBinding **ppBinding);
  3489. HRESULT STDMETHODCALLTYPE Add(BSTR strBinding, IEventBinding **ppBinding);
  3490. HRESULT STDMETHODCALLTYPE Remove(VARIANT *pvarDesired);
  3491. HRESULT STDMETHODCALLTYPE get_Count(long *plCount);
  3492. HRESULT STDMETHODCALLTYPE get__NewEnum(IUnknown **ppUnkEnum);
  3493. private:
  3494. CComPtr<IUnknown> m_pUnkMarshaler;
  3495. };
  3496. /////////////////////////////////////////////////////////////////////////////
  3497. // CEventBindings
  3498. HRESULT CEventBindings::FinalConstruct() {
  3499. DEBUG_OBJECT_CHECK
  3500. TraceFunctEnter("CEventBindings::FinalConstruct");
  3501. HRESULT hrRes = S_OK;
  3502. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  3503. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  3504. ADD_DEBUG_OBJECT("CEventBindings")
  3505. TraceFunctLeave();
  3506. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  3507. }
  3508. void CEventBindings::FinalRelease() {
  3509. DEBUG_OBJECT_CHECK
  3510. TraceFunctEnter("CEventBindings::FinalRelease");
  3511. m_pUnkMarshaler.Release();
  3512. REMOVE_DEBUG_OBJECT
  3513. TraceFunctLeave();
  3514. }
  3515. HRESULT STDMETHODCALLTYPE CEventBindings::Item(VARIANT *pvarDesired, IEventBinding **ppBinding) {
  3516. DEBUG_OBJECT_CHECK
  3517. return (CreatePluggedInObject(CComObject<CEventBinding>::_CreatorClass::CreateInstance,
  3518. m_pDatabase,
  3519. pvarDesired,
  3520. IID_IEventBinding,
  3521. (IUnknown **) ppBinding,
  3522. FALSE));
  3523. }
  3524. HRESULT STDMETHODCALLTYPE CEventBindings::Add(BSTR strBinding, IEventBinding **ppBinding) {
  3525. DEBUG_OBJECT_CHECK
  3526. HRESULT hrRes;
  3527. CComVariant varName;
  3528. CStringGUID objGuid;
  3529. if (ppBinding) {
  3530. *ppBinding = NULL;
  3531. }
  3532. hrRes = AddImpl1(strBinding,objGuid,&varName);
  3533. if (!SUCCEEDED(hrRes)) {
  3534. return (hrRes);
  3535. }
  3536. _ASSERTE(varName.vt==VT_BSTR);
  3537. hrRes = Item(&varName,ppBinding);
  3538. if (!SUCCEEDED(hrRes)) {
  3539. return (hrRes);
  3540. }
  3541. if (hrRes != S_FALSE) {
  3542. return (S_FALSE);
  3543. }
  3544. hrRes = AddImpl2(m_pDatabase,
  3545. CComObject<CEventBinding>::_CreatorClass::CreateInstance,
  3546. IID_IEventBinding,
  3547. &varName,
  3548. (IUnknown **) ppBinding);
  3549. _ASSERTE(!SUCCEEDED(hrRes)||*ppBinding);
  3550. return (hrRes);
  3551. }
  3552. HRESULT STDMETHODCALLTYPE CEventBindings::Remove(VARIANT *pvarDesired) {
  3553. DEBUG_OBJECT_CHECK
  3554. if (!m_pDatabase) {
  3555. _ASSERTE(FALSE);
  3556. return (E_FAIL);
  3557. }
  3558. return (m_pDatabase->Remove(pvarDesired));
  3559. }
  3560. HRESULT STDMETHODCALLTYPE CEventBindings::get_Count(long *plCount) {
  3561. DEBUG_OBJECT_CHECK
  3562. if (plCount) {
  3563. *plCount = 0;
  3564. }
  3565. if (!plCount) {
  3566. return (E_POINTER);
  3567. }
  3568. if (!m_pDatabase) {
  3569. _ASSERTE(FALSE);
  3570. return (E_FAIL);
  3571. }
  3572. return (m_pDatabase->get_Count(plCount));
  3573. }
  3574. HRESULT STDMETHODCALLTYPE CEventBindings::get__NewEnum(IUnknown **ppUnkEnum) {
  3575. DEBUG_OBJECT_CHECK
  3576. HRESULT hrRes;
  3577. CComPtr<IUnknown> pUnkTmp;
  3578. CComObject<CEventBindingsEnum> *pNewEnum;
  3579. if (ppUnkEnum) {
  3580. *ppUnkEnum = NULL;
  3581. }
  3582. if (!ppUnkEnum) {
  3583. return (E_POINTER);
  3584. }
  3585. if (!m_pDatabase) {
  3586. _ASSERTE(FALSE);
  3587. return (E_FAIL);
  3588. }
  3589. hrRes = m_pDatabase->get__NewEnum(&pUnkTmp);
  3590. if (!SUCCEEDED(hrRes)) {
  3591. return (hrRes);
  3592. }
  3593. hrRes = CComObject<CEventBindingsEnum>::CreateInstance(&pNewEnum);
  3594. if (!SUCCEEDED(hrRes)) {
  3595. return (hrRes);
  3596. }
  3597. _ASSERTE(pNewEnum);
  3598. pNewEnum->AddRef();
  3599. hrRes = pNewEnum->SetEnum(pUnkTmp,m_pDatabase);
  3600. if (!SUCCEEDED(hrRes)) {
  3601. pNewEnum->Release();
  3602. return (hrRes);
  3603. }
  3604. hrRes = pNewEnum->QueryInterface(IID_IEnumVARIANT,(LPVOID *) ppUnkEnum);
  3605. pNewEnum->Release();
  3606. if (!SUCCEEDED(hrRes)) {
  3607. return (hrRes);
  3608. }
  3609. _ASSERTE(*ppUnkEnum);
  3610. return (S_OK);
  3611. }
  3612. /////////////////////////////////////////////////////////////////////////////
  3613. // CEventBindingManager
  3614. HRESULT CEventBindingManager::FinalConstruct() {
  3615. DEBUG_OBJECT_CHECK
  3616. TraceFunctEnter("CEventBindingManager::FinalConstruct");
  3617. HRESULT hrRes = S_OK;
  3618. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  3619. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  3620. ADD_DEBUG_OBJECT("CEventBindingManager")
  3621. TraceFunctLeave();
  3622. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  3623. }
  3624. void CEventBindingManager::FinalRelease() {
  3625. DEBUG_OBJECT_CHECK
  3626. TraceFunctEnter("CEventBindingManager::FinalRelease");
  3627. m_pUnkMarshaler.Release();
  3628. REMOVE_DEBUG_OBJECT
  3629. TraceFunctLeave();
  3630. }
  3631. HRESULT STDMETHODCALLTYPE CEventBindingManager::get_Bindings(BSTR pszEventType, IEventBindings **ppBindings) {
  3632. DEBUG_OBJECT_CHECK
  3633. HRESULT hrRes;
  3634. CComBSTR strTmp;
  3635. CComPtr<IEventPropertyBag> pEventTypes;
  3636. CComPtr<IEventPropertyBag> pEventType;
  3637. if (ppBindings) {
  3638. *ppBindings = NULL;
  3639. }
  3640. if (!pszEventType || !ppBindings) {
  3641. return (E_POINTER);
  3642. }
  3643. // tbd - verify that pszEventType is a valid event type
  3644. hrRes = CreateSubPropertyBag(m_pDatabase,&CComVariant(BD_EVENTTYPES),&pEventTypes,TRUE);
  3645. if (!SUCCEEDED(hrRes)) {
  3646. return (hrRes);
  3647. }
  3648. hrRes = CreateSubPropertyBag(pEventTypes,&CComVariant(pszEventType),&pEventType,TRUE);
  3649. if (!SUCCEEDED(hrRes)) {
  3650. return (hrRes);
  3651. }
  3652. return (CreatePluggedInObject(CComObject<CEventBindings>::_CreatorClass::CreateInstance,
  3653. pEventType,
  3654. &CComVariant(BD_BINDINGS),
  3655. IID_IEventBindings,
  3656. (IUnknown **) ppBindings,
  3657. TRUE));
  3658. }
  3659. HRESULT STDMETHODCALLTYPE CEventBindingManager::get__NewEnum(IUnknown **ppUnkEnum) {
  3660. DEBUG_OBJECT_CHECK
  3661. HRESULT hrRes;
  3662. CComPtr<IEventPropertyBag> pSubKey;
  3663. if (ppUnkEnum) {
  3664. *ppUnkEnum = NULL;
  3665. }
  3666. if (!ppUnkEnum) {
  3667. return (E_POINTER);
  3668. }
  3669. if (!m_pDatabase) {
  3670. return (E_FAIL);
  3671. }
  3672. hrRes = CreateSubPropertyBag(m_pDatabase,&CComVariant(BD_EVENTTYPES),&pSubKey,TRUE);
  3673. _ASSERTE(!SUCCEEDED(hrRes)||pSubKey);
  3674. if (!SUCCEEDED(hrRes)) {
  3675. return (hrRes);
  3676. }
  3677. return (pSubKey->get__NewEnum(ppUnkEnum));
  3678. }
  3679. #if 0
  3680. HRESULT STDMETHODCALLTYPE CEventBindingManager::get__NewEnum(IUnknown **ppUnkEnum) {
  3681. DEBUG_OBJECT_CHECK
  3682. HRESULT hrRes;
  3683. CComVariant varValue;
  3684. CLocker lck;
  3685. CComQIPtr<IEventPropertyBag,&IID_IEventPropertyBag> pSubKey;
  3686. if (ppUnkEnum) {
  3687. *ppUnkEnum = NULL;
  3688. }
  3689. if (!ppUnkEnum) {
  3690. return (E_POINTER);
  3691. }
  3692. if (!m_pDatabase) {
  3693. return (E_FAIL);
  3694. }
  3695. hrRes = lck.LockRead(m_pDatabase);
  3696. if (!SUCCEEDED(hrRes)) {
  3697. return (hrRes);
  3698. }
  3699. hrRes = m_pDatabase->Item(&CComVariant(BD_EVENTTYPES),&varValue);
  3700. if (!SUCCEEDED(hrRes)) {
  3701. return (hrRes);
  3702. }
  3703. if (hrRes == S_FALSE) {
  3704. lck.Unlock();
  3705. hrRes = lck.LockWrite(m_pDatabase);
  3706. if (!SUCCEEDED(hrRes)) {
  3707. return (hrRes);
  3708. }
  3709. hrRes = m_pDatabase->Item(&CComVariant(BD_EVENTTYPES),&varValue);
  3710. if (!SUCCEEDED(hrRes)) {
  3711. return (hrRes);
  3712. }
  3713. if (hrRes == S_FALSE) {
  3714. hrRes = CoCreateInstance(CLSID_CSEOMemDictionary,
  3715. NULL,
  3716. CLSCTX_ALL,
  3717. IID_IUnknown,
  3718. (LPVOID *) &varValue.punkVal);
  3719. if (!SUCCEEDED(hrRes)) {
  3720. return (hrRes);
  3721. }
  3722. varValue.vt = VT_UNKNOWN;
  3723. hrRes = m_pDatabase->Add(BD_EVENTTYPES,&varValue);
  3724. if (!SUCCEEDED(hrRes)) {
  3725. return (hrRes);
  3726. }
  3727. varValue.Clear();
  3728. hrRes = m_pDatabase->Item(&CComVariant(BD_EVENTTYPES),&varValue);
  3729. if (!SUCCEEDED(hrRes)) {
  3730. return (hrRes);
  3731. }
  3732. _ASSERTE(hrRes!=S_FALSE);
  3733. if (hrRes == S_FALSE) {
  3734. return (E_FAIL);
  3735. }
  3736. }
  3737. }
  3738. lck.Unlock();
  3739. pSubKey = varValue.punkVal;
  3740. if (!pSubKey) {
  3741. return (E_NOINTERFACE);
  3742. }
  3743. return (pSubKey->get__NewEnum(ppUnkEnum));
  3744. }
  3745. #endif
  3746. HRESULT STDMETHODCALLTYPE CEventBindingManager::GetClassID(CLSID *pClassID) {
  3747. DEBUG_OBJECT_CHECK
  3748. if (!pClassID) {
  3749. return (E_POINTER);
  3750. }
  3751. *pClassID = CLSID_CEventBindingManager;
  3752. return (S_OK);
  3753. }
  3754. HRESULT STDMETHODCALLTYPE CEventBindingManager::InitNew(void) {
  3755. DEBUG_OBJECT_CHECK
  3756. m_strDatabaseManager.Empty();
  3757. m_pDatabase.Release();
  3758. return (S_OK);
  3759. }
  3760. HRESULT STDMETHODCALLTYPE CEventBindingManager::Load(IPropertyBag *pPropBag, IErrorLog *pErrorLog) {
  3761. DEBUG_OBJECT_CHECK
  3762. HRESULT hrRes;
  3763. CComVariant varDictionary;
  3764. CStringGUID objGuid;
  3765. CComPtr<ISEOInitObject> pInit;
  3766. CComQIPtr<IEventPropertyBag,&IID_IEventPropertyBag> pTmp;
  3767. EXCEPINFO ei = {0,0,L"Event.BindingManager",NULL,NULL,0,NULL,NULL,0};
  3768. if (!pPropBag) {
  3769. return (E_POINTER);
  3770. }
  3771. hrRes = pPropBag->Read(L"DatabaseManager",&varDictionary,pErrorLog);
  3772. if (!SUCCEEDED(hrRes)) {
  3773. return (hrRes);
  3774. }
  3775. hrRes = varDictionary.ChangeType(VT_BSTR);
  3776. if (!SUCCEEDED(hrRes)) {
  3777. if (pErrorLog) {
  3778. ei.scode = hrRes;
  3779. pErrorLog->AddError(L"DatabaseManager",&ei);
  3780. }
  3781. return (hrRes);
  3782. }
  3783. objGuid.CalcFromProgID(varDictionary.bstrVal);
  3784. if (!objGuid) {
  3785. objGuid = varDictionary.bstrVal;
  3786. }
  3787. if (!objGuid) {
  3788. if (pErrorLog) {
  3789. ei.scode = CO_E_CLASSSTRING;
  3790. pErrorLog->AddError(L"DatabaseManager",&ei);
  3791. }
  3792. return (CO_E_CLASSSTRING);
  3793. }
  3794. hrRes = CoCreateInstance(objGuid,NULL,CLSCTX_ALL,IID_ISEOInitObject,(LPVOID *) &pInit);
  3795. _ASSERTE(!SUCCEEDED(hrRes)||pInit);
  3796. if (!SUCCEEDED(hrRes)) {
  3797. if (pErrorLog) {
  3798. ei.scode = hrRes;
  3799. pErrorLog->AddError(L"DatabaseManager",&ei);
  3800. }
  3801. return (hrRes);
  3802. }
  3803. pTmp = pInit;
  3804. if (!pTmp) {
  3805. if (pErrorLog) {
  3806. ei.scode = hrRes;
  3807. pErrorLog->AddError(L"DatabaseManager",&ei);
  3808. }
  3809. return (E_NOINTERFACE);
  3810. }
  3811. hrRes = pInit->Load(pPropBag,pErrorLog);
  3812. if (!SUCCEEDED(hrRes)) {
  3813. return (hrRes);
  3814. }
  3815. hrRes = put_Database(pTmp);
  3816. if (!SUCCEEDED(hrRes)) {
  3817. if (pErrorLog) {
  3818. ei.scode = hrRes;
  3819. pErrorLog->AddError(L"DatabaseManager",&ei);
  3820. }
  3821. return (hrRes);
  3822. }
  3823. m_strDatabaseManager = varDictionary.bstrVal;
  3824. return (S_OK);
  3825. }
  3826. HRESULT STDMETHODCALLTYPE CEventBindingManager::Save(IPropertyBag *pPropBag,
  3827. BOOL fClearDirty,
  3828. BOOL fSaveAllProperties) {
  3829. DEBUG_OBJECT_CHECK
  3830. HRESULT hrRes;
  3831. CComQIPtr<ISEOInitObject,&IID_ISEOInitObject> pInit;
  3832. if (!m_pDatabase) {
  3833. _ASSERTE(FALSE);
  3834. return (E_FAIL);
  3835. }
  3836. if (!pPropBag) {
  3837. return (E_POINTER);
  3838. }
  3839. pInit = m_pDatabase;
  3840. if (!pInit) {
  3841. return (E_NOINTERFACE);
  3842. }
  3843. hrRes = pInit->Save(pPropBag,fClearDirty,fSaveAllProperties);
  3844. if (!SUCCEEDED(hrRes)) {
  3845. return (hrRes);
  3846. }
  3847. hrRes = pPropBag->Write(L"DatabaseManager",&CComVariant(m_strDatabaseManager));
  3848. if (!SUCCEEDED(hrRes)) {
  3849. return (hrRes);
  3850. }
  3851. return (S_OK);
  3852. }
  3853. HRESULT STDMETHODCALLTYPE CEventBindingManager::OnChange() {
  3854. DEBUG_OBJECT_CHECK
  3855. HRESULT hrRes;
  3856. CComPtr<IConnectionPoint> pCP;
  3857. CComPtr<IEnumConnections> pEnum;
  3858. hrRes = FindConnectionPoint(IID_IEventNotifyBindingChange,&pCP);
  3859. if (!SUCCEEDED(hrRes)) {
  3860. _ASSERTE(FALSE);
  3861. return (S_OK);
  3862. }
  3863. hrRes = pCP->EnumConnections(&pEnum);
  3864. if (!SUCCEEDED(hrRes)) {
  3865. _ASSERTE(FALSE);
  3866. return (S_OK);
  3867. }
  3868. while (1) {
  3869. CONNECTDATA cdNotify;
  3870. hrRes = pEnum->Next(1,&cdNotify,NULL);
  3871. if (!SUCCEEDED(hrRes)) {
  3872. _ASSERTE(FALSE);
  3873. return (S_OK);
  3874. }
  3875. if (hrRes == S_FALSE) {
  3876. break;
  3877. }
  3878. _ASSERTE(cdNotify.pUnk);
  3879. hrRes = ((IEventNotifyBindingChange *) cdNotify.pUnk)->OnChange();
  3880. _ASSERTE(SUCCEEDED(hrRes));
  3881. cdNotify.pUnk->Release();
  3882. }
  3883. pCP.Release();
  3884. pEnum.Release();
  3885. hrRes = FindConnectionPoint(IID_IEventNotifyBindingChangeDisp,&pCP);
  3886. if (!SUCCEEDED(hrRes)) {
  3887. _ASSERTE(FALSE);
  3888. return (S_OK);
  3889. }
  3890. hrRes = pCP->EnumConnections(&pEnum);
  3891. if (!SUCCEEDED(hrRes)) {
  3892. _ASSERTE(FALSE);
  3893. return (S_OK);
  3894. }
  3895. while (1) {
  3896. CONNECTDATA cdNotify;
  3897. static DISPPARAMS dpArgs = {NULL,NULL,0,0};
  3898. hrRes = pEnum->Next(1,&cdNotify,NULL);
  3899. if (!SUCCEEDED(hrRes)) {
  3900. _ASSERTE(FALSE);
  3901. return (S_OK);
  3902. }
  3903. if (hrRes == S_FALSE) {
  3904. break;
  3905. }
  3906. _ASSERTE(cdNotify.pUnk);
  3907. hrRes = ((IEventNotifyBindingChangeDisp *) cdNotify.pUnk)->Invoke(1,
  3908. IID_NULL,
  3909. GetUserDefaultLCID(),
  3910. DISPATCH_METHOD,
  3911. &dpArgs,
  3912. NULL,
  3913. NULL,
  3914. NULL);
  3915. _ASSERTE(SUCCEEDED(hrRes));
  3916. cdNotify.pUnk->Release();
  3917. }
  3918. return (S_OK);
  3919. }
  3920. HRESULT STDMETHODCALLTYPE CEventBindingManager::Copy(long lTimeout, IEventBindingManager **ppBindingManager) {
  3921. DEBUG_OBJECT_CHECK
  3922. HRESULT hrRes;
  3923. CComPtr<IEventPropertyBag> pCopy;
  3924. if (!m_pDatabase) {
  3925. _ASSERTE(FALSE);
  3926. return (E_FAIL);
  3927. }
  3928. hrRes = CopyPropertyBag(m_pDatabase,&pCopy,TRUE,lTimeout);
  3929. if (!SUCCEEDED(hrRes)) {
  3930. return (hrRes);
  3931. }
  3932. return (CreatePluggedInObject(CComObject<CEventBindingManager>::_CreatorClass::CreateInstance,
  3933. pCopy,
  3934. &CComVariant(),
  3935. IID_IEventBindingManager,
  3936. (IUnknown **) ppBindingManager,
  3937. TRUE));
  3938. }
  3939. HRESULT STDMETHODCALLTYPE CEventBindingManager::EmptyCopy(IEventBindingManager **ppBindingManager) {
  3940. DEBUG_OBJECT_CHECK
  3941. HRESULT hrRes;
  3942. CComPtr<IEventPropertyBag> pCopy;
  3943. if (!m_pDatabase) {
  3944. _ASSERTE(FALSE);
  3945. return (E_FAIL);
  3946. }
  3947. hrRes = CoCreateInstance(CLSID_CSEOMemDictionary,
  3948. NULL,
  3949. CLSCTX_ALL,
  3950. IID_IEventPropertyBag,
  3951. (LPVOID *) &pCopy);
  3952. if (!SUCCEEDED(hrRes)) {
  3953. return (hrRes);
  3954. }
  3955. return (CreatePluggedInObject(CComObject<CEventBindingManager>::_CreatorClass::CreateInstance,
  3956. pCopy,
  3957. &CComVariant(),
  3958. IID_IEventBindingManager,
  3959. (IUnknown **) ppBindingManager,
  3960. TRUE));
  3961. }
  3962. void CEventBindingManager::AdviseCalled(IUnknown *pUnk, DWORD *pdwCookie, REFIID riid, DWORD dwCount) {
  3963. DEBUG_OBJECT_CHECK
  3964. HRESULT hrRes;
  3965. CComPtr<IConnectionPointContainer> pCPC;
  3966. if (dwCount == 1) {
  3967. if (!m_pDatabase) {
  3968. _ASSERTE(FALSE);
  3969. return;
  3970. }
  3971. if (((CP_ENBC *) this)->GetCount() + ((CP_ENBCD *) this)->GetCount() != 1) {
  3972. return;
  3973. }
  3974. hrRes = m_pDatabase->QueryInterface(IID_IConnectionPointContainer,(LPVOID *) &pCPC);
  3975. if (!SUCCEEDED(hrRes)) {
  3976. return;
  3977. }
  3978. hrRes = pCPC->FindConnectionPoint(IID_IEventNotifyBindingChange,&m_pCP);
  3979. if (!SUCCEEDED(hrRes)) {
  3980. return;
  3981. }
  3982. hrRes = m_pCP->Advise(GetControllingUnknown(),&m_dwCPCookie);
  3983. if (!SUCCEEDED(hrRes)) {
  3984. _ASSERTE(FALSE);
  3985. m_pCP.Release();
  3986. return;
  3987. }
  3988. }
  3989. }
  3990. void CEventBindingManager::UnadviseCalled(DWORD dwCookie, REFIID riid, DWORD dwCount) {
  3991. DEBUG_OBJECT_CHECK
  3992. HRESULT hrRes;
  3993. if (dwCount == 0) {
  3994. if (!m_pDatabase) {
  3995. _ASSERTE(FALSE);
  3996. return;
  3997. }
  3998. if (!m_pCP) {
  3999. return;
  4000. }
  4001. if (((CP_ENBC *) this)->GetCount() + ((CP_ENBCD *) this)->GetCount() != 0) {
  4002. return;
  4003. }
  4004. hrRes = m_pCP->Unadvise(m_dwCPCookie);
  4005. _ASSERTE(SUCCEEDED(hrRes));
  4006. m_pCP.Release();
  4007. }
  4008. }
  4009. /////////////////////////////////////////////////////////////////////////////
  4010. // CEventDatabasePlugin
  4011. HRESULT STDMETHODCALLTYPE CEventDatabasePlugin::get_Database(IEventPropertyBag **ppDatabase) {
  4012. if (!ppDatabase) {
  4013. return (E_POINTER);
  4014. }
  4015. *ppDatabase = m_pDatabase;
  4016. if (*ppDatabase) {
  4017. (*ppDatabase)->AddRef();
  4018. }
  4019. return (S_OK);
  4020. }
  4021. HRESULT STDMETHODCALLTYPE CEventDatabasePlugin::put_Database(IEventPropertyBag *pDatabase) {
  4022. m_pDatabase = pDatabase;
  4023. return (S_OK);
  4024. }
  4025. HRESULT STDMETHODCALLTYPE CEventDatabasePlugin::putref_Database(IEventPropertyBag **ppDatabase) {
  4026. if (!ppDatabase) {
  4027. return (E_POINTER);
  4028. }
  4029. return (put_Database(*ppDatabase));
  4030. }
  4031. HRESULT STDMETHODCALLTYPE CEventDatabasePlugin::get_Name(BSTR *pstrName) {
  4032. if (!pstrName) {
  4033. return (E_POINTER);
  4034. }
  4035. *pstrName = SysAllocString(m_strName);
  4036. if (!*pstrName && m_strName) {
  4037. return (E_OUTOFMEMORY);
  4038. }
  4039. return (S_OK);
  4040. }
  4041. HRESULT STDMETHODCALLTYPE CEventDatabasePlugin::put_Name(BSTR strName) {
  4042. m_strName = strName;
  4043. return (S_OK);
  4044. }
  4045. HRESULT STDMETHODCALLTYPE CEventDatabasePlugin::putref_Name(BSTR *pstrName) {
  4046. if (!pstrName) {
  4047. return (E_POINTER);
  4048. }
  4049. return (put_Name(*pstrName));
  4050. }
  4051. HRESULT STDMETHODCALLTYPE CEventDatabasePlugin::get_Parent(IEventPropertyBag **ppParent) {
  4052. if (!ppParent) {
  4053. return (E_POINTER);
  4054. }
  4055. *ppParent = m_pParent;
  4056. if (*ppParent) {
  4057. (*ppParent)->AddRef();
  4058. }
  4059. return (S_OK);
  4060. }
  4061. HRESULT STDMETHODCALLTYPE CEventDatabasePlugin::put_Parent(IEventPropertyBag *pParent) {
  4062. m_pParent = pParent;
  4063. return (S_OK);
  4064. }
  4065. HRESULT STDMETHODCALLTYPE CEventDatabasePlugin::putref_Parent(IEventPropertyBag **ppParent) {
  4066. if (!ppParent) {
  4067. return (E_POINTER);
  4068. }
  4069. return (put_Parent(*ppParent));
  4070. }
  4071. /////////////////////////////////////////////////////////////////////////////
  4072. // CEventMetabaseDatabaseManager
  4073. HRESULT CEventMetabaseDatabaseManager::FinalConstruct() {
  4074. DEBUG_OBJECT_CHECK
  4075. TraceFunctEnter("CEventMetabaseDatabaseManager::FinalConstruct");
  4076. HRESULT hrRes = S_OK;
  4077. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  4078. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  4079. ADD_DEBUG_OBJECT("CEventMetabaseDatabaseManager")
  4080. TraceFunctLeave();
  4081. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  4082. }
  4083. void CEventMetabaseDatabaseManager::FinalRelease() {
  4084. DEBUG_OBJECT_CHECK
  4085. TraceFunctEnter("CEventMetabaseDatabaseManager::FinalRelease");
  4086. m_pUnkMarshaler.Release();
  4087. REMOVE_DEBUG_OBJECT
  4088. TraceFunctLeave();
  4089. }
  4090. HRESULT STDMETHODCALLTYPE CEventMetabaseDatabaseManager::CreateDatabase(BSTR strPath, IUnknown **ppMonDatabase) {
  4091. DEBUG_OBJECT_CHECK
  4092. HRESULT hrRes;
  4093. CComBSTR strTmp;
  4094. CComPtr<IBindCtx> pBindCtx;
  4095. DWORD dwEaten;
  4096. CComPtr<IEventPropertyBag> pDatabase;
  4097. CComVariant varDatabase;
  4098. BOOL bExisted = FALSE;
  4099. if (ppMonDatabase) {
  4100. *ppMonDatabase = NULL;
  4101. }
  4102. if (!ppMonDatabase) {
  4103. return (E_POINTER);
  4104. }
  4105. hrRes = CoCreateInstance(CLSID_CSEOMetaDictionary,
  4106. NULL,
  4107. CLSCTX_ALL,
  4108. IID_IEventPropertyBag,
  4109. (LPVOID *) &pDatabase);
  4110. if (!SUCCEEDED(hrRes)) {
  4111. return (hrRes);
  4112. }
  4113. hrRes = pDatabase->Item(&CComVariant(strPath),&varDatabase);
  4114. if (!SUCCEEDED(hrRes)) {
  4115. return (hrRes);
  4116. }
  4117. if (hrRes == S_FALSE) {
  4118. CComVariant varTmp;
  4119. hrRes = CoCreateInstance(CLSID_CSEOMemDictionary,
  4120. NULL,
  4121. CLSCTX_ALL,
  4122. IID_IEventPropertyBag,
  4123. (LPVOID *) &varTmp.punkVal);
  4124. if (!SUCCEEDED(hrRes)) {
  4125. return (hrRes);
  4126. }
  4127. varTmp.vt = VT_UNKNOWN;
  4128. hrRes = pDatabase->Add(strPath,&varTmp);
  4129. if (!SUCCEEDED(hrRes)) {
  4130. return (hrRes);
  4131. }
  4132. } else {
  4133. bExisted = TRUE;
  4134. }
  4135. strTmp = L"@SEO.SEOGenericMoniker: MonikerType=Event.BindingManager DatabaseManager=SEO.SEOMetaDictionary MetabasePath=";
  4136. strTmp.Append(strPath);
  4137. hrRes = CreateBindCtx(0,&pBindCtx);
  4138. if (!SUCCEEDED(hrRes)) {
  4139. return (hrRes);
  4140. }
  4141. hrRes = MkParseDisplayName(pBindCtx,strTmp,&dwEaten,(IMoniker **) ppMonDatabase);
  4142. _ASSERTE(!SUCCEEDED(hrRes)||*ppMonDatabase);
  4143. if (!SUCCEEDED(hrRes)) {
  4144. return (hrRes);
  4145. }
  4146. return (bExisted?S_FALSE:S_OK);
  4147. }
  4148. HRESULT STDMETHODCALLTYPE CEventMetabaseDatabaseManager::EraseDatabase(BSTR strPath) {
  4149. DEBUG_OBJECT_CHECK
  4150. HRESULT hrRes;
  4151. CComPtr<IEventPropertyBag> pDatabase;
  4152. hrRes = CoCreateInstance(CLSID_CSEOMetaDictionary,
  4153. NULL,
  4154. CLSCTX_ALL,
  4155. IID_IEventPropertyBag,
  4156. (LPVOID *) &pDatabase);
  4157. if (!SUCCEEDED(hrRes)) {
  4158. return (hrRes);
  4159. }
  4160. hrRes = pDatabase->Remove(&CComVariant(strPath));
  4161. if (!SUCCEEDED(hrRes)) {
  4162. return (hrRes);
  4163. }
  4164. return (S_OK);
  4165. }
  4166. #define DW2W(x) _itow(x,(LPWSTR) _alloca(11*sizeof(WCHAR)),10)
  4167. HRESULT STDMETHODCALLTYPE CEventMetabaseDatabaseManager::MakeVServerPath(BSTR strService, long lInstance, BSTR *pstrPath) {
  4168. DEBUG_OBJECT_CHECK
  4169. CComBSTR strTmp;
  4170. if (pstrPath) {
  4171. *pstrPath = NULL;
  4172. }
  4173. if (!pstrPath) {
  4174. return (E_POINTER);
  4175. }
  4176. if (!strService || !*strService || (lInstance < 0)) {
  4177. return (E_INVALIDARG);
  4178. }
  4179. strTmp = L"LM/";
  4180. strTmp.Append(strService);
  4181. strTmp.Append(L"/");
  4182. strTmp.Append(DW2W(lInstance));
  4183. strTmp.Append(L"/EventManager");
  4184. *pstrPath = strTmp.Detach();
  4185. return (S_OK);
  4186. }
  4187. HRESULT STDMETHODCALLTYPE CEventMetabaseDatabaseManager::MakeVRootPath(BSTR strService, long lInstance, BSTR strRoot, BSTR *pstrPath) {
  4188. DEBUG_OBJECT_CHECK
  4189. CComBSTR strTmp;
  4190. if (pstrPath) {
  4191. *pstrPath = NULL;
  4192. }
  4193. if (!pstrPath) {
  4194. return (E_POINTER);
  4195. }
  4196. if (!strService || !*strService || (lInstance < 0) || !strRoot || !*strRoot) {
  4197. return (E_INVALIDARG);
  4198. }
  4199. strTmp = L"LM/";
  4200. strTmp.Append(strService);
  4201. strTmp.Append(L"/");
  4202. strTmp.Append(DW2W(lInstance));
  4203. strTmp.Append(L"/root/");
  4204. strTmp.Append(strRoot);
  4205. strTmp.Append(L"/EventManager");
  4206. *pstrPath = strTmp.Detach();
  4207. return (S_OK);
  4208. }
  4209. /////////////////////////////////////////////////////////////////////////////
  4210. // CEventUtil
  4211. HRESULT CEventUtil::FinalConstruct() {
  4212. DEBUG_OBJECT_CHECK
  4213. TraceFunctEnter("CEventUtil::FinalConstruct");
  4214. HRESULT hrRes = S_OK;
  4215. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  4216. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  4217. ADD_DEBUG_OBJECT("CEventUtil")
  4218. TraceFunctLeave();
  4219. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  4220. }
  4221. void CEventUtil::FinalRelease() {
  4222. DEBUG_OBJECT_CHECK
  4223. TraceFunctEnter("CEventUtil::FinalRelease");
  4224. m_pUnkMarshaler.Release();
  4225. REMOVE_DEBUG_OBJECT
  4226. TraceFunctLeave();
  4227. }
  4228. HRESULT STDMETHODCALLTYPE CEventUtil::DisplayNameFromMoniker(IUnknown *pUnkMoniker,
  4229. BSTR *pstrDisplayName) {
  4230. DEBUG_OBJECT_CHECK
  4231. HRESULT hrRes;
  4232. CComPtr<IMoniker> pMoniker;
  4233. CComPtr<IBindCtx> pBindCtx;
  4234. LPWSTR pszDisplayName;
  4235. if (pstrDisplayName) {
  4236. *pstrDisplayName = NULL;
  4237. }
  4238. if (!pUnkMoniker || !pstrDisplayName) {
  4239. return (E_POINTER);
  4240. }
  4241. hrRes = pUnkMoniker->QueryInterface(IID_IMoniker,(LPVOID *) &pMoniker);
  4242. _ASSERTE(!SUCCEEDED(hrRes)||pMoniker);
  4243. if (!SUCCEEDED(hrRes)) {
  4244. return (hrRes);
  4245. }
  4246. hrRes = CreateBindCtx(0,&pBindCtx);
  4247. _ASSERTE(!SUCCEEDED(hrRes)||pBindCtx);
  4248. if (!SUCCEEDED(hrRes)) {
  4249. return (hrRes);
  4250. }
  4251. hrRes = pMoniker->GetDisplayName(pBindCtx,NULL,&pszDisplayName);
  4252. _ASSERTE(!SUCCEEDED(hrRes)||pszDisplayName);
  4253. if (!SUCCEEDED(hrRes)) {
  4254. return (hrRes);
  4255. }
  4256. *pstrDisplayName = SysAllocString(pszDisplayName);
  4257. CoTaskMemFree(pszDisplayName);
  4258. if (!pstrDisplayName) {
  4259. return (E_OUTOFMEMORY);
  4260. }
  4261. return (S_OK);
  4262. }
  4263. HRESULT STDMETHODCALLTYPE CEventUtil::MonikerFromDisplayName(BSTR strDisplayName,
  4264. IUnknown **ppUnkMoniker) {
  4265. DEBUG_OBJECT_CHECK
  4266. HRESULT hrRes;
  4267. CComPtr<IBindCtx> pBindCtx;
  4268. DWORD dwEaten;
  4269. if (ppUnkMoniker) {
  4270. *ppUnkMoniker = NULL;
  4271. }
  4272. if (!strDisplayName || !ppUnkMoniker) {
  4273. return (E_POINTER);
  4274. }
  4275. #if 0
  4276. hrRes = CreateBindCtx(0,&pBindCtx);
  4277. _ASSERTE(!SUCCEEDED(hrRes)||pBindCtx);
  4278. if (!SUCCEEDED(hrRes)) {
  4279. return (hrRes);
  4280. }
  4281. hrRes = MkParseDisplayNameEx(pBindCtx,strDisplayName,&dwEaten,(IMoniker **) ppUnkMoniker);
  4282. _ASSERTE(!SUCCEEDED(hrRes)||*ppUnkMoniker);
  4283. if (SUCCEEDED(hrRes)) {
  4284. _ASSERTE(!*ppUnkMoniker);
  4285. return (S_OK);
  4286. }
  4287. pBindCtx.Release();
  4288. #endif
  4289. hrRes = CreateBindCtx(0,&pBindCtx);
  4290. _ASSERTE(!SUCCEEDED(hrRes)||pBindCtx);
  4291. if (!SUCCEEDED(hrRes)) {
  4292. return (hrRes);
  4293. }
  4294. hrRes = MkParseDisplayName(pBindCtx,strDisplayName,&dwEaten,(IMoniker **) ppUnkMoniker);
  4295. _ASSERTE(!SUCCEEDED(hrRes)||*ppUnkMoniker);
  4296. if (!SUCCEEDED(hrRes)) {
  4297. _ASSERTE(!*ppUnkMoniker);
  4298. return (hrRes);
  4299. }
  4300. return (S_OK);
  4301. }
  4302. HRESULT STDMETHODCALLTYPE CEventUtil::ObjectFromMoniker(IUnknown *pUnkMoniker, IUnknown **ppUnkObject) {
  4303. DEBUG_OBJECT_CHECK
  4304. HRESULT hrRes;
  4305. CComPtr<IMoniker> pMoniker;
  4306. CComPtr<IBindCtx> pBindCtx;
  4307. if (ppUnkObject) {
  4308. *ppUnkObject = NULL;
  4309. }
  4310. if (!pUnkMoniker || !ppUnkObject) {
  4311. return (E_POINTER);
  4312. }
  4313. hrRes = pUnkMoniker->QueryInterface(IID_IMoniker,(LPVOID *) &pMoniker);
  4314. _ASSERTE(!SUCCEEDED(hrRes)||pMoniker);
  4315. if (!SUCCEEDED(hrRes)) {
  4316. return (hrRes);
  4317. }
  4318. hrRes = CreateBindCtx(0,&pBindCtx);
  4319. if (!SUCCEEDED(hrRes)) {
  4320. return (hrRes);
  4321. }
  4322. hrRes = pMoniker->BindToObject(pBindCtx,NULL,IID_IUnknown,(LPVOID *) ppUnkObject);
  4323. _ASSERTE(!SUCCEEDED(hrRes)||*ppUnkObject);
  4324. if (!SUCCEEDED(hrRes)) {
  4325. _ASSERTE(!*ppUnkObject);
  4326. return (hrRes);
  4327. }
  4328. return (S_OK);
  4329. }
  4330. HRESULT STDMETHODCALLTYPE CEventUtil::GetNewGUID(BSTR *pstrGUID) {
  4331. DEBUG_OBJECT_CHECK
  4332. CStringGUID objGuid;
  4333. if (pstrGUID) {
  4334. *pstrGUID = NULL;
  4335. }
  4336. if (!pstrGUID) {
  4337. return (E_POINTER);
  4338. }
  4339. objGuid.CalcNew();
  4340. if (!objGuid) {
  4341. return (E_OUTOFMEMORY);
  4342. }
  4343. *pstrGUID = SysAllocString(objGuid);
  4344. if (!*pstrGUID) {
  4345. return (E_OUTOFMEMORY);
  4346. }
  4347. return (S_OK);
  4348. }
  4349. HRESULT STDMETHODCALLTYPE CEventUtil::CopyPropertyBag(IUnknown *pUnkInput, IUnknown **ppUnkOutput) {
  4350. DEBUG_OBJECT_CHECK
  4351. CComQIPtr<IEventPropertyBag,&IID_IEventPropertyBag> pInput;
  4352. if (ppUnkOutput) {
  4353. *ppUnkOutput = NULL;
  4354. }
  4355. if (!pUnkInput || !ppUnkOutput) {
  4356. return (E_POINTER);
  4357. }
  4358. pInput = pUnkInput;
  4359. if (!pInput) {
  4360. return (E_NOINTERFACE);
  4361. }
  4362. return (::CopyPropertyBag(pInput,(IEventPropertyBag **) ppUnkOutput));
  4363. }
  4364. HRESULT STDMETHODCALLTYPE CEventUtil::CopyPropertyBagShallow(IUnknown *pUnkInput, IUnknown **ppUnkOutput) {
  4365. DEBUG_OBJECT_CHECK
  4366. CComQIPtr<IEventPropertyBag,&IID_IEventPropertyBag> pInput;
  4367. if (ppUnkOutput) {
  4368. *ppUnkOutput = NULL;
  4369. }
  4370. if (!pUnkInput || !ppUnkOutput) {
  4371. return (E_POINTER);
  4372. }
  4373. pInput = pUnkInput;
  4374. if (!pInput) {
  4375. return (E_NOINTERFACE);
  4376. }
  4377. return (::CopyPropertyBagShallow(pInput,(IEventPropertyBag **) ppUnkOutput));
  4378. }
  4379. HRESULT STDMETHODCALLTYPE CEventUtil::DispatchFromObject(IUnknown *pUnkObject, IDispatch **ppDispOutput) {
  4380. DEBUG_OBJECT_CHECK
  4381. if (ppDispOutput) {
  4382. *ppDispOutput = NULL;
  4383. }
  4384. if (!pUnkObject || !ppDispOutput) {
  4385. return (E_POINTER);
  4386. }
  4387. return (pUnkObject->QueryInterface(IID_IDispatch,(LPVOID *) ppDispOutput));
  4388. }
  4389. HRESULT STDMETHODCALLTYPE CEventUtil::GetIndexedGUID(BSTR strGUID, long lIndex, BSTR *pstrResult) {
  4390. DEBUG_OBJECT_CHECK
  4391. CStringGUID guidGUID;
  4392. CStringGUID guidNew;
  4393. if (pstrResult) {
  4394. *pstrResult = NULL;
  4395. }
  4396. if (!strGUID || !pstrResult) {
  4397. return (E_POINTER);
  4398. }
  4399. guidGUID.Assign(strGUID);
  4400. if (!guidGUID) {
  4401. return (E_INVALIDARG);
  4402. }
  4403. guidNew.Assign(guidGUID,(DWORD) lIndex);
  4404. if (!guidNew) {
  4405. return (E_FAIL);
  4406. }
  4407. *pstrResult = SysAllocString(guidNew);
  4408. if (!*pstrResult) {
  4409. return (E_OUTOFMEMORY);
  4410. }
  4411. return (S_OK);
  4412. }
  4413. HRESULT STDMETHODCALLTYPE CEventUtil::RegisterSource(BSTR strSourceType,
  4414. BSTR strSource,
  4415. long lInstance,
  4416. BSTR strService,
  4417. BSTR strVRoot,
  4418. BSTR strDatabaseManager,
  4419. BSTR strDisplayName,
  4420. IEventBindingManager **ppBindingManager) {
  4421. HRESULT hrRes;
  4422. CStringGUID guidSource;
  4423. CComPtr<IEventManager> pEventManager;
  4424. CComPtr<IEventSourceTypes> pSourceTypes;
  4425. CComPtr<IEventSourceType> pSourceType;
  4426. CComPtr<IEventSources> pSources;
  4427. CComPtr<IEventSource> pSource;
  4428. CComPtr<IEventDatabaseManager> pDatabaseManager;
  4429. if (ppBindingManager) {
  4430. *ppBindingManager = NULL;
  4431. }
  4432. if (!strSourceType || !strSource || !strService || !strDatabaseManager || !ppBindingManager) {
  4433. return (E_POINTER);
  4434. }
  4435. if (lInstance == -1) {
  4436. guidSource = strSource;
  4437. } else {
  4438. CStringGUID guidTmp;
  4439. guidTmp = strSource;
  4440. if (!guidTmp) {
  4441. return (E_INVALIDARG);
  4442. }
  4443. guidSource.Assign(guidTmp,lInstance);
  4444. }
  4445. if (!guidSource) {
  4446. return (E_INVALIDARG);
  4447. }
  4448. hrRes = CoCreateInstance(CLSID_CEventManager,
  4449. NULL,
  4450. CLSCTX_ALL,
  4451. IID_IEventManager,
  4452. (LPVOID *) &pEventManager);
  4453. if (!SUCCEEDED(hrRes)) {
  4454. return (hrRes);
  4455. }
  4456. hrRes = pEventManager->get_SourceTypes(&pSourceTypes);
  4457. if (!SUCCEEDED(hrRes)) {
  4458. return (hrRes);
  4459. }
  4460. hrRes = pSourceTypes->Item(&CComVariant(strSourceType),&pSourceType);
  4461. if (!SUCCEEDED(hrRes)) {
  4462. return (hrRes);
  4463. }
  4464. if (hrRes == S_FALSE) {
  4465. return (SEO_E_NOTPRESENT);
  4466. }
  4467. hrRes = pSourceType->get_Sources(&pSources);
  4468. if (!SUCCEEDED(hrRes)) {
  4469. return (hrRes);
  4470. }
  4471. hrRes = pSources->Add(CComBSTR((LPCWSTR) guidSource),&pSource);
  4472. if (!SUCCEEDED(hrRes)) {
  4473. return (hrRes);
  4474. }
  4475. if (hrRes == S_OK) {
  4476. VARIANT varDatabaseManager;
  4477. CComBSTR strPath;
  4478. CComPtr<IUnknown> pPath;
  4479. varDatabaseManager.vt = VT_BSTR | VT_BYREF;
  4480. varDatabaseManager.pbstrVal = &strDatabaseManager;
  4481. hrRes = SEOCreateObject(&varDatabaseManager,
  4482. NULL,
  4483. NULL,
  4484. IID_IEventDatabaseManager,
  4485. (IUnknown **) &pDatabaseManager);
  4486. if (!SUCCEEDED(hrRes)) {
  4487. return (hrRes);
  4488. }
  4489. if (strVRoot && strVRoot[0]) {
  4490. hrRes = pDatabaseManager->MakeVRootPath(strService,lInstance,strVRoot,&strPath);
  4491. } else {
  4492. hrRes = pDatabaseManager->MakeVServerPath(strService,lInstance,&strPath);
  4493. }
  4494. if (!SUCCEEDED(hrRes)) {
  4495. return (hrRes);
  4496. }
  4497. hrRes = pDatabaseManager->CreateDatabase(strPath,&pPath);
  4498. if (!SUCCEEDED(hrRes)) {
  4499. return (hrRes);
  4500. }
  4501. hrRes = pSource->put_BindingManagerMoniker(pPath);
  4502. if (!SUCCEEDED(hrRes)) {
  4503. return (hrRes);
  4504. }
  4505. if (strDisplayName) {
  4506. hrRes = pSource->put_DisplayName(strDisplayName);
  4507. if (!SUCCEEDED(hrRes)) {
  4508. return (hrRes);
  4509. }
  4510. }
  4511. hrRes = pSource->Save();
  4512. if (!SUCCEEDED(hrRes)) {
  4513. return (hrRes);
  4514. }
  4515. }
  4516. hrRes = pSource->GetBindingManager(ppBindingManager);
  4517. if (!SUCCEEDED(hrRes)) {
  4518. return (hrRes);
  4519. }
  4520. return (S_OK);
  4521. }
  4522. /////////////////////////////////////////////////////////////////////////////
  4523. // CEventComCat
  4524. HRESULT CEventComCat::FinalConstruct() {
  4525. DEBUG_OBJECT_CHECK
  4526. TraceFunctEnter("CEventComCat::FinalConstruct");
  4527. HRESULT hrRes = S_OK;
  4528. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  4529. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  4530. ADD_DEBUG_OBJECT("CEventComCat")
  4531. TraceFunctLeave();
  4532. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  4533. }
  4534. void CEventComCat::FinalRelease() {
  4535. DEBUG_OBJECT_CHECK
  4536. TraceFunctEnter("CEventComCat::FinalRelease");
  4537. m_pUnkMarshaler.Release();
  4538. REMOVE_DEBUG_OBJECT
  4539. TraceFunctLeave();
  4540. }
  4541. HRESULT STDMETHODCALLTYPE CEventComCat::RegisterCategory(BSTR pszCategory, BSTR pszDescription, long lcidLanguage) {
  4542. DEBUG_OBJECT_CHECK
  4543. HRESULT hrRes;
  4544. CComPtr<ICatRegister> pCatReg;
  4545. CATEGORYINFO ci;
  4546. CStringGUID objCat;
  4547. if (!pszCategory || !pszDescription) {
  4548. return (E_POINTER);
  4549. }
  4550. objCat = pszCategory;
  4551. if (!objCat) {
  4552. return (CO_E_CLASSSTRING);
  4553. }
  4554. if (wcslen(pszDescription) > sizeof(ci.szDescription)/sizeof(ci.szDescription[0])-1) {
  4555. return (E_INVALIDARG);
  4556. }
  4557. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  4558. NULL,
  4559. CLSCTX_ALL,
  4560. IID_ICatRegister,
  4561. (LPVOID *) &pCatReg);
  4562. _ASSERTE(!SUCCEEDED(hrRes)||pCatReg);
  4563. if (!SUCCEEDED(hrRes)) {
  4564. return (hrRes);
  4565. }
  4566. memset(&ci,0,sizeof(ci));
  4567. ci.catid = objCat;
  4568. ci.lcid = lcidLanguage;
  4569. wcscpy(ci.szDescription,pszDescription);
  4570. hrRes = pCatReg->RegisterCategories(1,&ci);
  4571. return (hrRes);
  4572. }
  4573. HRESULT STDMETHODCALLTYPE CEventComCat::UnRegisterCategory(BSTR pszCategory) {
  4574. DEBUG_OBJECT_CHECK
  4575. HRESULT hrRes;
  4576. CComPtr<ICatRegister> pCatReg;
  4577. CStringGUID objCat;
  4578. if (!pszCategory) {
  4579. return (E_POINTER);
  4580. }
  4581. objCat = pszCategory;
  4582. if (!objCat) {
  4583. return (CO_E_CLASSSTRING);
  4584. }
  4585. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  4586. NULL,
  4587. CLSCTX_ALL,
  4588. IID_ICatRegister,
  4589. (LPVOID *) &pCatReg);
  4590. _ASSERTE(!SUCCEEDED(hrRes)||pCatReg);
  4591. if (!SUCCEEDED(hrRes)) {
  4592. return (hrRes);
  4593. }
  4594. hrRes = pCatReg->UnRegisterCategories(1,(GUID *) &((REFGUID) objCat));
  4595. return (hrRes);
  4596. }
  4597. HRESULT STDMETHODCALLTYPE CEventComCat::RegisterClassImplementsCategory(BSTR pszClass, BSTR pszCategory) {
  4598. DEBUG_OBJECT_CHECK
  4599. HRESULT hrRes;
  4600. CComPtr<ICatRegister> pCatReg;
  4601. CStringGUID objClass;
  4602. CStringGUID objCat;
  4603. if (!pszClass || !pszCategory) {
  4604. return (E_POINTER);
  4605. }
  4606. objClass = pszClass;
  4607. if (!objClass) {
  4608. return (CO_E_CLASSSTRING);
  4609. }
  4610. objCat = pszCategory;
  4611. if (!objCat) {
  4612. return (CO_E_CLASSSTRING);
  4613. }
  4614. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  4615. NULL,
  4616. CLSCTX_ALL,
  4617. IID_ICatRegister,
  4618. (LPVOID *) &pCatReg);
  4619. _ASSERTE(!SUCCEEDED(hrRes)||pCatReg);
  4620. if (!SUCCEEDED(hrRes)) {
  4621. return (hrRes);
  4622. }
  4623. hrRes = pCatReg->RegisterClassImplCategories(objClass,1,(GUID *) &((REFGUID) objCat));
  4624. return (hrRes);
  4625. }
  4626. HRESULT STDMETHODCALLTYPE CEventComCat::UnRegisterClassImplementsCategory(BSTR pszClass, BSTR pszCategory) {
  4627. DEBUG_OBJECT_CHECK
  4628. HRESULT hrRes;
  4629. CComPtr<ICatRegister> pCatReg;
  4630. CStringGUID objClass;
  4631. CStringGUID objCat;
  4632. if (!pszClass || !pszCategory) {
  4633. return (E_POINTER);
  4634. }
  4635. objClass = pszClass;
  4636. if (!objClass) {
  4637. return (CO_E_CLASSSTRING);
  4638. }
  4639. objCat = pszCategory;
  4640. if (!objCat) {
  4641. return (CO_E_CLASSSTRING);
  4642. }
  4643. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  4644. NULL,
  4645. CLSCTX_ALL,
  4646. IID_ICatRegister,
  4647. (LPVOID *) &pCatReg);
  4648. _ASSERTE(!SUCCEEDED(hrRes)||pCatReg);
  4649. if (!SUCCEEDED(hrRes)) {
  4650. return (hrRes);
  4651. }
  4652. hrRes = pCatReg->UnRegisterClassImplCategories(objClass,1,(GUID *) &((REFGUID) objCat));
  4653. return (hrRes);
  4654. }
  4655. HRESULT STDMETHODCALLTYPE CEventComCat::RegisterClassRequiresCategory(BSTR pszClass, BSTR pszCategory) {
  4656. DEBUG_OBJECT_CHECK
  4657. HRESULT hrRes;
  4658. CComPtr<ICatRegister> pCatReg;
  4659. CStringGUID objClass;
  4660. CStringGUID objCat;
  4661. if (!pszClass || !pszCategory) {
  4662. return (E_POINTER);
  4663. }
  4664. objClass = pszClass;
  4665. if (!objClass) {
  4666. return (CO_E_CLASSSTRING);
  4667. }
  4668. objCat = pszCategory;
  4669. if (!objCat) {
  4670. return (CO_E_CLASSSTRING);
  4671. }
  4672. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  4673. NULL,
  4674. CLSCTX_ALL,
  4675. IID_ICatRegister,
  4676. (LPVOID *) &pCatReg);
  4677. _ASSERTE(!SUCCEEDED(hrRes)||pCatReg);
  4678. if (!SUCCEEDED(hrRes)) {
  4679. return (hrRes);
  4680. }
  4681. hrRes = pCatReg->RegisterClassReqCategories(objClass,1,(GUID *) &((REFGUID) objCat));
  4682. return (hrRes);
  4683. }
  4684. HRESULT STDMETHODCALLTYPE CEventComCat::UnRegisterClassRequiresCategory(BSTR pszClass, BSTR pszCategory) {
  4685. DEBUG_OBJECT_CHECK
  4686. HRESULT hrRes;
  4687. CComPtr<ICatRegister> pCatReg;
  4688. CStringGUID objClass;
  4689. CStringGUID objCat;
  4690. if (!pszClass || !pszCategory) {
  4691. return (E_POINTER);
  4692. }
  4693. objClass = pszClass;
  4694. if (!objClass) {
  4695. return (CO_E_CLASSSTRING);
  4696. }
  4697. objCat = pszCategory;
  4698. if (!objCat) {
  4699. return (CO_E_CLASSSTRING);
  4700. }
  4701. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  4702. NULL,
  4703. CLSCTX_ALL,
  4704. IID_ICatRegister,
  4705. (LPVOID *) &pCatReg);
  4706. _ASSERTE(!SUCCEEDED(hrRes)||pCatReg);
  4707. if (!SUCCEEDED(hrRes)) {
  4708. return (hrRes);
  4709. }
  4710. hrRes = pCatReg->UnRegisterClassReqCategories(objClass,1,(GUID *) &((REFGUID) objCat));
  4711. return (hrRes);
  4712. }
  4713. HRESULT STDMETHODCALLTYPE CEventComCat::GetCategories(SAFEARRAY **ppsaCategories) {
  4714. DEBUG_OBJECT_CHECK
  4715. HRESULT hrRes;
  4716. CComPtr<ICatInformation> pCatInfo;
  4717. CComPtr<IEnumCATEGORYINFO> pEnum;
  4718. DWORD dwTmp;
  4719. DWORD dwAlloc = 0;
  4720. CATEGORYINFO *pci = NULL;
  4721. if (ppsaCategories) {
  4722. *ppsaCategories = NULL;
  4723. }
  4724. if (!ppsaCategories) {
  4725. return (E_POINTER);
  4726. }
  4727. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  4728. NULL,
  4729. CLSCTX_ALL,
  4730. IID_ICatInformation,
  4731. (LPVOID *) &pCatInfo);
  4732. _ASSERTE(!SUCCEEDED(hrRes)||pCatInfo);
  4733. if (!SUCCEEDED(hrRes)) {
  4734. return (hrRes);
  4735. }
  4736. hrRes = pCatInfo->EnumCategories(LOCALE_NEUTRAL,&pEnum);
  4737. _ASSERTE(!SUCCEEDED(hrRes)||pEnum);
  4738. if (!SUCCEEDED(hrRes)) {
  4739. return (hrRes);
  4740. }
  4741. hrRes = S_FALSE;
  4742. while (1) {
  4743. dwTmp = (hrRes==S_FALSE) ? 1 : dwAlloc;
  4744. if (!MyReallocInPlace(&pci,sizeof(*pci)*(dwAlloc+dwTmp))) {
  4745. MyFree(pci);
  4746. return (E_OUTOFMEMORY);
  4747. }
  4748. hrRes = pEnum->Next(dwTmp,&pci[dwAlloc],&dwTmp);
  4749. // Do not alter hrRes between here and the bottom of the loop! The first statement
  4750. // in the loop relies on hrRes having the result from this call to IEnumCLSID::Next.
  4751. if (!SUCCEEDED(hrRes)) {
  4752. MyFree(pci);
  4753. return (hrRes);
  4754. }
  4755. if (!dwTmp) {
  4756. break;
  4757. }
  4758. dwAlloc += dwTmp;
  4759. }
  4760. *ppsaCategories = SafeArrayCreateVector(VT_VARIANT,1,dwAlloc);
  4761. if (!*ppsaCategories) {
  4762. MyFree(pci);
  4763. return (E_OUTOFMEMORY);
  4764. }
  4765. _ASSERTE(SafeArrayGetDim(*ppsaCategories)==1);
  4766. _ASSERTE(SafeArrayGetElemsize(*ppsaCategories)==sizeof(VARIANT));
  4767. hrRes = SafeArrayLock(*ppsaCategories);
  4768. _ASSERTE(SUCCEEDED(hrRes));
  4769. if (SUCCEEDED(hrRes)) {
  4770. HRESULT hrResTmp;
  4771. for (dwTmp=1;dwTmp<=dwAlloc;dwTmp++) {
  4772. CStringGUID objGuid;
  4773. VARIANT *pvarElt;
  4774. objGuid = pci[dwTmp-1].catid;
  4775. if (!objGuid) {
  4776. hrRes = E_OUTOFMEMORY;
  4777. break;
  4778. }
  4779. pvarElt = NULL;
  4780. hrRes = SafeArrayPtrOfIndex(*ppsaCategories,(long *) &dwTmp,(LPVOID *) &pvarElt);
  4781. _ASSERTE(!SUCCEEDED(hrRes)||pvarElt);
  4782. if (!SUCCEEDED(hrRes)) {
  4783. break;
  4784. }
  4785. pvarElt->bstrVal = SysAllocString(objGuid);
  4786. if (!pvarElt->bstrVal) {
  4787. hrRes = E_OUTOFMEMORY;
  4788. break;
  4789. }
  4790. pvarElt->vt = VT_BSTR;
  4791. }
  4792. hrResTmp = SafeArrayUnlock(*ppsaCategories);
  4793. _ASSERTE(SUCCEEDED(hrResTmp));
  4794. if (!SUCCEEDED(hrResTmp) && SUCCEEDED(hrRes)) {
  4795. hrRes = hrResTmp;
  4796. }
  4797. }
  4798. MyFree(pci);
  4799. if (!SUCCEEDED(hrRes)) {
  4800. SafeArrayDestroy(*ppsaCategories);
  4801. *ppsaCategories = NULL;
  4802. return (hrRes);
  4803. }
  4804. return (S_OK);
  4805. }
  4806. HRESULT STDMETHODCALLTYPE CEventComCat::GetCategoryDescription(BSTR pszCategory,
  4807. long lcidLanguage,
  4808. BSTR *pstrDescription) {
  4809. DEBUG_OBJECT_CHECK
  4810. HRESULT hrRes;
  4811. CComPtr<ICatInformation> pCatInfo;
  4812. CStringGUID objCat;
  4813. LPWSTR pszDesc;
  4814. if (pstrDescription) {
  4815. *pstrDescription = NULL;
  4816. }
  4817. if (!pszCategory || !pstrDescription) {
  4818. return (E_POINTER);
  4819. }
  4820. objCat = pszCategory;
  4821. if (!objCat) {
  4822. return (CO_E_CLASSSTRING);
  4823. }
  4824. hrRes = CoCreateInstance(CLSID_StdComponentCategoriesMgr,
  4825. NULL,
  4826. CLSCTX_ALL,
  4827. IID_ICatInformation,
  4828. (LPVOID *) &pCatInfo);
  4829. _ASSERTE(!SUCCEEDED(hrRes)||pCatInfo);
  4830. if (!SUCCEEDED(hrRes)) {
  4831. return (hrRes);
  4832. }
  4833. pszDesc = NULL;
  4834. hrRes = pCatInfo->GetCategoryDesc(objCat,lcidLanguage,&pszDesc);
  4835. _ASSERTE(!SUCCEEDED(hrRes)||pszDesc);
  4836. if (!SUCCEEDED(hrRes)) {
  4837. _ASSERTE(!pszDesc);
  4838. return (hrRes);
  4839. }
  4840. *pstrDescription = SysAllocString(pszDesc);
  4841. CoTaskMemFree(pszDesc);
  4842. if (!*pstrDescription) {
  4843. return (E_OUTOFMEMORY);
  4844. }
  4845. return (S_OK);
  4846. }
  4847. /////////////////////////////////////////////////////////////////////////////
  4848. // CEventRouterInternal
  4849. class ATL_NO_VTABLE CEventRouterInternal :
  4850. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  4851. // public CComCoClass<CEventRouterInternal, &CLSID_CEventRouterInternal>,
  4852. public IEventRouter,
  4853. public IEventNotifyBindingChange
  4854. {
  4855. DEBUG_OBJECT_DEF(CEventRouterInternal)
  4856. private:
  4857. class CDispatcher {
  4858. DEBUG_OBJECT_DEF2(CDispatcher,"CEventRouterInternal::CDispatcher",CEventRouterInternal__CDispatcher)
  4859. public:
  4860. CDispatcher();
  4861. virtual ~CDispatcher();
  4862. HRESULT Init(REFCLSID clsidDispatcher, IClassFactory *pClassFactory);
  4863. BOOL HasEventType(REFIID iidEventType);
  4864. HRESULT AddEventType(REFIID iidEventType, IEventRouter *piRouter, IEventBindingManager *piManager);
  4865. HRESULT GetDispatcher(REFIID iidDesired, LPVOID *ppvDispatcher);
  4866. REFCLSID GetCLSID() { return (m_clsidDispatcher); };
  4867. void SetPreload(IEnumGUID *pEnumPreload) {
  4868. m_pEnumPreload = pEnumPreload;
  4869. };
  4870. private:
  4871. CLSID m_clsidDispatcher;
  4872. DWORD m_dwEventTypes;
  4873. IID *m_aiidEventTypes;
  4874. CComQIPtr<IEventDispatcher,&IID_IEventDispatcher> m_pDispatcher;
  4875. CComPtr<IUnknown> m_pUnkDispatcher;
  4876. CComPtr<IEnumGUID> m_pEnumPreload;
  4877. };
  4878. public:
  4879. HRESULT FinalConstruct();
  4880. void FinalRelease();
  4881. BOOL FindDispatcher(REFCLSID clsidDispatcher, REFIID iidEventType, CDispatcher **ppDispatcher);
  4882. HRESULT AddDispatcher(REFCLSID clsidDispatcher, IClassFactory *pClassFactory, REFIID iidEventType, CDispatcher **ppDispatcher);
  4883. void PutDatabaseImpl(IEventBindingManager *pBindingManager, int iTimeout);
  4884. void MakeBindingManagerCopy(int iTimeout, BOOL bRequired);
  4885. DECLARE_PROTECT_FINAL_CONSTRUCT();
  4886. DECLARE_NOT_AGGREGATABLE(CEventRouterInternal);
  4887. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  4888. // L"EventRouterInternal Class",
  4889. // L"Event.RouterInternal.1",
  4890. // L"Event.RouterInternal");
  4891. DECLARE_GET_CONTROLLING_UNKNOWN();
  4892. BEGIN_COM_MAP(CEventRouterInternal)
  4893. COM_INTERFACE_ENTRY(IEventRouter)
  4894. COM_INTERFACE_ENTRY(IEventNotifyBindingChange)
  4895. COM_INTERFACE_ENTRY_AGGREGATE(IID_IEventLock, m_pLock.p)
  4896. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  4897. END_COM_MAP()
  4898. // IEventRouter
  4899. public:
  4900. HRESULT STDMETHODCALLTYPE get_Database(IEventBindingManager **ppBindingManager);
  4901. HRESULT STDMETHODCALLTYPE put_Database(IEventBindingManager *pBindingManager);
  4902. HRESULT STDMETHODCALLTYPE putref_Database(IEventBindingManager **ppBindingManager);
  4903. HRESULT STDMETHODCALLTYPE GetDispatcher(REFIID iidEvent,
  4904. REFIID iidDesired,
  4905. IUnknown **ppUnkResult);
  4906. HRESULT STDMETHODCALLTYPE GetDispatcherByCLSID(REFCLSID clsidDispatcher,
  4907. REFIID iidEvent,
  4908. REFIID iidDesired,
  4909. IUnknown **ppUnkResult);
  4910. HRESULT STDMETHODCALLTYPE GetDispatcherByClassFactory(REFCLSID clsidDispatcher,
  4911. IClassFactory *piClassFactory,
  4912. REFIID iidEvent,
  4913. REFIID iidDesired,
  4914. IUnknown **ppUnkResult);
  4915. // IEventNotifyBindingChange
  4916. public:
  4917. HRESULT STDMETHODCALLTYPE OnChange();
  4918. private:
  4919. class CDispatchers : public CSEOGrowableList<CDispatcher> {
  4920. // tbd - override various members
  4921. };
  4922. CDispatchers m_Dispatchers;
  4923. CComPtr<IEventBindingManager> m_pBindingManager;
  4924. CComPtr<IEventBindingManager> m_pBindingManagerCopy;
  4925. BOOL m_bMakeNewCopy;
  4926. CComPtr<IEventLock> m_pLock;
  4927. CComPtr<IUnknown> m_pUnkMarshaler;
  4928. CComPtr<IConnectionPoint> m_pCP;
  4929. DWORD m_dwCookie;
  4930. };
  4931. HRESULT CEventRouterInternal::FinalConstruct() {
  4932. DEBUG_OBJECT_CHECK
  4933. TraceFunctEnter("CEventRouterInternal::FinalConstruct");
  4934. HRESULT hrRes = S_OK;
  4935. m_bMakeNewCopy = TRUE;
  4936. hrRes = CoCreateInstance(CLSID_CEventLock,NULL,CLSCTX_ALL,IID_IEventLock,(LPVOID *) &m_pLock);
  4937. if (SUCCEEDED(hrRes)) {
  4938. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  4939. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  4940. }
  4941. ADD_DEBUG_OBJECT("CEventRouterInternal")
  4942. TraceFunctLeave();
  4943. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  4944. }
  4945. void CEventRouterInternal::FinalRelease() {
  4946. DEBUG_OBJECT_CHECK
  4947. TraceFunctEnter("CEventRouterInternal::FinalRelease");
  4948. put_Database(NULL);
  4949. m_pBindingManager.Release();
  4950. m_pBindingManagerCopy.Release();
  4951. m_pLock.Release();
  4952. m_pUnkMarshaler.Release();
  4953. REMOVE_DEBUG_OBJECT
  4954. TraceFunctLeave();
  4955. }
  4956. BOOL CEventRouterInternal::FindDispatcher(REFCLSID clsidDispatcher, REFIID iidEventType, CDispatcher **ppDispatcher) {
  4957. DEBUG_OBJECT_CHECK
  4958. if (ppDispatcher) {
  4959. *ppDispatcher = NULL;
  4960. }
  4961. if (!ppDispatcher) {
  4962. return (E_POINTER);
  4963. }
  4964. for (DWORD dwIdx=0;dwIdx<m_Dispatchers.Count();dwIdx++) {
  4965. if (m_Dispatchers[dwIdx].GetCLSID() == clsidDispatcher) {
  4966. if (m_Dispatchers[dwIdx].HasEventType(iidEventType)) {
  4967. *ppDispatcher = m_Dispatchers.Index(dwIdx);
  4968. return (TRUE);
  4969. }
  4970. return (FALSE);
  4971. }
  4972. }
  4973. return (FALSE);
  4974. }
  4975. HRESULT CEventRouterInternal::AddDispatcher(REFCLSID clsidDispatcher, IClassFactory *pClassFactory, REFIID iidEventType, CDispatcher **ppDispatcher) {
  4976. DEBUG_OBJECT_CHECK
  4977. HRESULT hrRes;
  4978. CDispatcher *pTmp;
  4979. if (ppDispatcher) {
  4980. *ppDispatcher = NULL;
  4981. }
  4982. if (!ppDispatcher) {
  4983. return (E_POINTER);
  4984. }
  4985. MakeBindingManagerCopy(LOCK_TIMEOUT,TRUE);
  4986. for (DWORD dwIdx=0;dwIdx<m_Dispatchers.Count();dwIdx++) {
  4987. if (m_Dispatchers[dwIdx].GetCLSID() == clsidDispatcher) {
  4988. hrRes = m_Dispatchers[dwIdx].AddEventType(iidEventType,this,m_pBindingManagerCopy);
  4989. if (!SUCCEEDED(hrRes)) {
  4990. return (hrRes);
  4991. }
  4992. *ppDispatcher = m_Dispatchers.Index(dwIdx);
  4993. return (S_OK);
  4994. }
  4995. }
  4996. pTmp = new CDispatcher;
  4997. if (!pTmp) {
  4998. return (E_OUTOFMEMORY);
  4999. }
  5000. hrRes = pTmp->Init(clsidDispatcher,pClassFactory);
  5001. if (!SUCCEEDED(hrRes)) {
  5002. delete pTmp;
  5003. return (hrRes);
  5004. }
  5005. hrRes = m_Dispatchers.Add(pTmp);
  5006. if (!SUCCEEDED(hrRes)) {
  5007. delete pTmp;
  5008. return (hrRes);
  5009. }
  5010. hrRes = pTmp->AddEventType(iidEventType,this,m_pBindingManagerCopy);
  5011. if (!SUCCEEDED(hrRes)) {
  5012. return (hrRes);
  5013. }
  5014. *ppDispatcher = pTmp;
  5015. return (S_OK);
  5016. }
  5017. void CEventRouterInternal::PutDatabaseImpl(IEventBindingManager *pBindingManager, int iTimeout) {
  5018. DEBUG_OBJECT_CHECK
  5019. BOOL bDoAdvise = FALSE;
  5020. HRESULT hrRes;
  5021. m_bMakeNewCopy = TRUE;
  5022. if (m_pBindingManager != pBindingManager) {
  5023. bDoAdvise = TRUE;
  5024. }
  5025. if (pBindingManager) {
  5026. pBindingManager->AddRef();
  5027. }
  5028. if (m_pBindingManager) {
  5029. m_Dispatchers.RemoveAll();
  5030. if (bDoAdvise) {
  5031. if (m_pCP) {
  5032. hrRes = m_pCP->Unadvise(m_dwCookie);
  5033. _ASSERTE(SUCCEEDED(hrRes));
  5034. m_pCP.Release();
  5035. }
  5036. }
  5037. }
  5038. if (bDoAdvise) {
  5039. m_pBindingManagerCopy.Release();
  5040. }
  5041. m_pBindingManager = pBindingManager;
  5042. if (m_pBindingManager) {
  5043. if (bDoAdvise) {
  5044. CComQIPtr<IConnectionPointContainer,&IID_IConnectionPointContainer> pCPC;
  5045. pCPC = m_pBindingManager;
  5046. if (pCPC) {
  5047. hrRes = pCPC->FindConnectionPoint(IID_IEventNotifyBindingChange,&m_pCP);
  5048. if (SUCCEEDED(hrRes)) {
  5049. hrRes = m_pCP->Advise(GetControllingUnknown(),&m_dwCookie);
  5050. _ASSERTE(SUCCEEDED(hrRes));
  5051. if (!SUCCEEDED(hrRes)) {
  5052. m_pCP.Release();
  5053. }
  5054. }
  5055. }
  5056. }
  5057. MakeBindingManagerCopy(iTimeout,FALSE);
  5058. }
  5059. if (pBindingManager) {
  5060. pBindingManager->Release();
  5061. }
  5062. }
  5063. void CEventRouterInternal::MakeBindingManagerCopy(int iTimeout, BOOL bRequired) {
  5064. HRESULT hrRes;
  5065. CComQIPtr<IEventBindingManagerCopier, &IID_IEventBindingManagerCopier> pCopier;
  5066. CComPtr<IEventBindingManager> pNewCopy;
  5067. _ASSERTE(m_pBindingManager);
  5068. if (!m_bMakeNewCopy) {
  5069. return;
  5070. }
  5071. pCopier = m_pBindingManager;
  5072. _ASSERTE(pCopier);
  5073. if (!pCopier) {
  5074. // We couldn't QI' for IEventBindingManagerCopier, so just use the
  5075. // current event binding manager without attempting to make a copy.
  5076. m_pBindingManagerCopy = m_pBindingManager;
  5077. goto done;
  5078. }
  5079. hrRes = pCopier->Copy(iTimeout,&pNewCopy);
  5080. _ASSERTE(SUCCEEDED(hrRes)||(hrRes==SEO_E_TIMEOUT));
  5081. if (SUCCEEDED(hrRes)) {
  5082. // We successfully made a copy of the binding event manager.
  5083. m_pBindingManagerCopy = pNewCopy;
  5084. goto done;
  5085. }
  5086. if (!bRequired) {
  5087. // We don't actually an event binding manager yet, so just exit while
  5088. // leaving m_bMakeNewCopy==TRUE.
  5089. return;
  5090. }
  5091. if (m_pBindingManagerCopy) {
  5092. // Since we must have an event binding manager, and since we already have
  5093. // an old copy, just continue using the old copy and forget about making
  5094. // a new copy.
  5095. goto done;
  5096. }
  5097. // Ok - we must have an event binding manager. And we don't have an old copy
  5098. // we can use. So, just create a completely empty copy.
  5099. m_pBindingManagerCopy.Release();
  5100. hrRes = pCopier->EmptyCopy(&m_pBindingManagerCopy);
  5101. _ASSERTE(SUCCEEDED(hrRes));
  5102. if (!SUCCEEDED(hrRes)) {
  5103. // Arrgg! We even failed to make the empty copy. We are really in trouble.
  5104. // So just use the event binding manager directly, without making a copy.
  5105. m_pBindingManagerCopy = m_pBindingManager;
  5106. }
  5107. done:
  5108. // The only case where we don't want to reset this flag is where we failed
  5109. // to make a copy, but we weren't required to make a copy either - in that
  5110. // case, we took an early return from the method. In all other case, we
  5111. // want to reset this flag to prevent any further attempts at making a
  5112. // copy.
  5113. m_bMakeNewCopy = FALSE;
  5114. }
  5115. HRESULT STDMETHODCALLTYPE CEventRouterInternal::get_Database(IEventBindingManager **ppBindingManager) {
  5116. DEBUG_OBJECT_CHECK
  5117. HRESULT hrRes;
  5118. if (ppBindingManager) {
  5119. *ppBindingManager = NULL;
  5120. }
  5121. if (!ppBindingManager) {
  5122. return (E_POINTER);
  5123. }
  5124. hrRes = m_pLock->LockRead(LOCK_TIMEOUT);
  5125. if (!SUCCEEDED(hrRes)) {
  5126. return (hrRes);
  5127. }
  5128. *ppBindingManager = m_pBindingManager;
  5129. if (!ppBindingManager) {
  5130. (*ppBindingManager)->AddRef();
  5131. }
  5132. m_pLock->UnlockRead();
  5133. return (S_OK);
  5134. }
  5135. HRESULT STDMETHODCALLTYPE CEventRouterInternal::put_Database(IEventBindingManager *pBindingManager) {
  5136. DEBUG_OBJECT_CHECK
  5137. HRESULT hrRes;
  5138. hrRes = m_pLock->LockWrite(LOCK_TIMEOUT);
  5139. if (!SUCCEEDED(hrRes)) {
  5140. return (hrRes);
  5141. }
  5142. PutDatabaseImpl(pBindingManager,LOCK_TIMEOUT);
  5143. m_pLock->UnlockWrite();
  5144. return (S_OK);
  5145. }
  5146. HRESULT STDMETHODCALLTYPE CEventRouterInternal::putref_Database(IEventBindingManager **ppBindingManager) {
  5147. DEBUG_OBJECT_CHECK
  5148. if (!ppBindingManager) {
  5149. return (E_POINTER);
  5150. }
  5151. return (put_Database(*ppBindingManager));
  5152. }
  5153. HRESULT STDMETHODCALLTYPE CEventRouterInternal::GetDispatcher(REFIID iidEventType,
  5154. REFIID iidDesired,
  5155. IUnknown **ppUnkResult) {
  5156. DEBUG_OBJECT_CHECK
  5157. return (GetDispatcherByCLSID(iidEventType,iidEventType,iidDesired,ppUnkResult));
  5158. }
  5159. HRESULT STDMETHODCALLTYPE CEventRouterInternal::GetDispatcherByCLSID(REFCLSID clsidDispatcher,
  5160. REFIID iidEventType,
  5161. REFIID iidDesired,
  5162. IUnknown **ppUnkResult) {
  5163. DEBUG_OBJECT_CHECK
  5164. return (GetDispatcherByClassFactory(clsidDispatcher,
  5165. NULL,
  5166. iidEventType,
  5167. iidDesired,
  5168. ppUnkResult));
  5169. }
  5170. HRESULT STDMETHODCALLTYPE CEventRouterInternal::GetDispatcherByClassFactory(REFCLSID clsidDispatcher,
  5171. IClassFactory *pClassFactory,
  5172. REFIID iidEventType,
  5173. REFIID iidDesired,
  5174. IUnknown **ppUnkResult) {
  5175. DEBUG_OBJECT_CHECK
  5176. HRESULT hrRes;
  5177. CDispatcher *pDispatcher;
  5178. CLocker cLock;
  5179. if (ppUnkResult) {
  5180. *ppUnkResult = NULL;
  5181. }
  5182. if (!ppUnkResult) {
  5183. return (E_POINTER);
  5184. }
  5185. hrRes = cLock.LockRead(m_pLock);
  5186. if (!SUCCEEDED(hrRes)) {
  5187. return (hrRes);
  5188. }
  5189. if (FindDispatcher(clsidDispatcher,iidEventType,&pDispatcher)) {
  5190. hrRes = pDispatcher->GetDispatcher(iidDesired,(LPVOID *) ppUnkResult);
  5191. return (hrRes);
  5192. }
  5193. cLock.Unlock();
  5194. hrRes = cLock.LockWrite(m_pLock);
  5195. if (!SUCCEEDED(hrRes)) {
  5196. return (hrRes);
  5197. }
  5198. hrRes = AddDispatcher(clsidDispatcher,pClassFactory,iidEventType,&pDispatcher);
  5199. if (SUCCEEDED(hrRes)) {
  5200. hrRes = pDispatcher->GetDispatcher(iidDesired,(LPVOID *) ppUnkResult);
  5201. }
  5202. return (hrRes);
  5203. }
  5204. class CDispSave {
  5205. private:
  5206. CDispSave(IClassFactory *pCF, REFCLSID rclsid) {
  5207. if (pCF) {
  5208. m_pCF = pCF;
  5209. m_clsid = rclsid;
  5210. } else {
  5211. m_clsid = GUID_NULL;
  5212. }
  5213. };
  5214. ~CDispSave() {
  5215. // nothing
  5216. };
  5217. public:
  5218. static void Init(CDispSave *pNew, IClassFactory *pCF, REFCLSID rclsid) {
  5219. new(pNew) CDispSave(pCF,rclsid);
  5220. };
  5221. static void Term(CDispSave *pDisp) {
  5222. pDisp->~CDispSave();
  5223. };
  5224. public:
  5225. CComPtr<IClassFactory> m_pCF;
  5226. GUID m_clsid;
  5227. };
  5228. HRESULT STDMETHODCALLTYPE CEventRouterInternal::OnChange() {
  5229. DEBUG_OBJECT_CHECK
  5230. HRESULT hrRes = S_OK;
  5231. CDispSave *pSave = NULL;
  5232. DWORD dwSaveCount;
  5233. DWORD dwIdx;
  5234. hrRes = m_pLock->LockWrite(LOCK_TIMEOUT_SHORT);
  5235. _ASSERTE(SUCCEEDED(hrRes));
  5236. if (!SUCCEEDED(hrRes)) {
  5237. return (S_OK);
  5238. }
  5239. // First, let's go through and make a copy of (some of) the dispatcher info that's
  5240. // in this router. We do this by allocating an array of objects on the stack...
  5241. dwSaveCount = m_Dispatchers.Count();
  5242. pSave = (CDispSave *) _alloca(sizeof(CDispSave)*dwSaveCount);
  5243. if (pSave) {
  5244. // Now we initialize each of the objects.
  5245. for (dwIdx=0;dwIdx<dwSaveCount;dwIdx++) {
  5246. CComPtr<IClassFactory> pCF;
  5247. // The Init() routine wants either an IClassFactory or a NULL value.
  5248. hrRes = m_Dispatchers[dwIdx].GetDispatcher(IID_IClassFactory,(LPVOID *) &pCF);
  5249. CDispSave::Init(&pSave[dwIdx],pCF,m_Dispatchers[dwIdx].GetCLSID());
  5250. pCF.Release();
  5251. }
  5252. }
  5253. PutDatabaseImpl(m_pBindingManager,LOCK_TIMEOUT_SHORT);
  5254. if (pSave) {
  5255. // Now we do the pre-loading...
  5256. for (dwIdx=0;dwIdx<dwSaveCount;dwIdx++) {
  5257. // If the previous dispatcher implements IClassFactory...
  5258. if (pSave[dwIdx].m_pCF) {
  5259. CDispatcher *pDisp;
  5260. CComPtr<IEventDispatcherChain> pChain;
  5261. CComPtr<IUnknown> pUnkEnum;
  5262. CComQIPtr<IEnumGUID,&IID_IEnumGUID> pEnum;
  5263. IID iidEventType;
  5264. // ...then use the previous dispatcher to create a new dispatcher.
  5265. hrRes = AddDispatcher(pSave[dwIdx].m_clsid,pSave[dwIdx].m_pCF,GUID_NULL,&pDisp);
  5266. _ASSERTE(SUCCEEDED(hrRes));
  5267. if (SUCCEEDED(hrRes)) {
  5268. // Now, if the new dispatcher implements IEventDispatcherChain...
  5269. hrRes = pDisp->GetDispatcher(IID_IEventDispatcherChain,(LPVOID *) &pChain);
  5270. }
  5271. if (pChain) {
  5272. // ... then call the new dispatcher's IEventDispatcherChain::SetPrevious method.
  5273. hrRes = pChain->SetPrevious(pSave[dwIdx].m_pCF,&pUnkEnum);
  5274. }
  5275. if (pUnkEnum) {
  5276. // If the IEventDispatcherChain::SetPrevious method returned an object...
  5277. pEnum = pUnkEnum;
  5278. }
  5279. if (pEnum) {
  5280. // ... and if that object implements IEnumGUID...
  5281. if (!m_bMakeNewCopy) {
  5282. // ... and if we have a binding manager copy now...
  5283. while (pEnum->Next(1,&iidEventType,NULL) == S_OK) {
  5284. // ... then we loop through the GUID's and add each of them as an
  5285. // event type (which causes the new dispatcher's IEventDispatcher::SetContext
  5286. // method to be called).
  5287. hrRes = pDisp->AddEventType(iidEventType,this,m_pBindingManagerCopy);
  5288. _ASSERTE(SUCCEEDED(hrRes));
  5289. }
  5290. } else {
  5291. // If we don't have a binding manager copy, then set it up so
  5292. // that we'll do the event type pre-loading on the first
  5293. // event fired to the new dispatcher.
  5294. pDisp->SetPreload(pEnum);
  5295. }
  5296. }
  5297. pChain.Release();
  5298. pUnkEnum.Release();
  5299. pEnum.Release();
  5300. }
  5301. }
  5302. }
  5303. if (pSave) {
  5304. for (dwIdx=0;dwIdx<dwSaveCount;dwIdx++) {
  5305. // Be sure to clean-up the array of objects on the stack - if we
  5306. // don't do this explicitly, then we would leak ref-counts on the
  5307. // old dispatcher(s).
  5308. CDispSave::Term(&pSave[dwIdx]);
  5309. }
  5310. }
  5311. m_pLock->UnlockWrite();
  5312. return (S_OK);
  5313. }
  5314. CEventRouterInternal::CDispatcher::CDispatcher() {
  5315. DEBUG_OBJECT_CHECK
  5316. m_dwEventTypes = 0;
  5317. m_aiidEventTypes = NULL;
  5318. }
  5319. CEventRouterInternal::CDispatcher::~CDispatcher() {
  5320. DEBUG_OBJECT_CHECK
  5321. if (m_aiidEventTypes) {
  5322. delete[] m_aiidEventTypes;
  5323. m_aiidEventTypes = NULL;
  5324. }
  5325. }
  5326. HRESULT CEventRouterInternal::CDispatcher::Init(REFCLSID clsidDispatcher, IClassFactory *pClassFactory) {
  5327. DEBUG_OBJECT_CHECK
  5328. HRESULT hrRes;
  5329. m_clsidDispatcher = clsidDispatcher;
  5330. if (pClassFactory) {
  5331. hrRes = pClassFactory->CreateInstance(NULL,IID_IUnknown,(LPVOID *) &m_pUnkDispatcher);
  5332. } else {
  5333. hrRes = CoCreateInstance(clsidDispatcher,
  5334. NULL,
  5335. CLSCTX_ALL,
  5336. IID_IUnknown,
  5337. (LPVOID *) &m_pUnkDispatcher);
  5338. }
  5339. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkDispatcher);
  5340. if (!SUCCEEDED(hrRes)) {
  5341. return (hrRes);
  5342. }
  5343. m_pDispatcher = m_pUnkDispatcher;
  5344. return (S_OK);
  5345. }
  5346. BOOL CEventRouterInternal::CDispatcher::HasEventType(REFIID iidEventType) {
  5347. DEBUG_OBJECT_CHECK
  5348. for (DWORD dwIdx=0;dwIdx<m_dwEventTypes;dwIdx++) {
  5349. if (m_aiidEventTypes[dwIdx] == iidEventType) {
  5350. return (TRUE);
  5351. }
  5352. }
  5353. return (FALSE);
  5354. }
  5355. HRESULT CEventRouterInternal::CDispatcher::AddEventType(REFIID iidEventType, IEventRouter *piRouter, IEventBindingManager *piManager) {
  5356. DEBUG_OBJECT_CHECK
  5357. IID *aiidTmp;
  5358. HRESULT hrRes;
  5359. if (iidEventType == GUID_NULL) {
  5360. return (S_FALSE);
  5361. }
  5362. if (HasEventType(iidEventType)) {
  5363. return (S_FALSE);
  5364. }
  5365. if (m_pEnumPreload) {
  5366. // If we were set-up to pre-load some event types...
  5367. CComPtr<IEnumGUID> pEnum;
  5368. IID iidPreload;
  5369. pEnum = m_pEnumPreload;
  5370. m_pEnumPreload.Release(); // Prevent infinite recusion
  5371. while (pEnum->Next(1,&iidPreload,NULL) == S_OK) {
  5372. // Add each event type returned by the enumerator.
  5373. hrRes = AddEventType(iidPreload,piRouter,piManager);
  5374. _ASSERTE(SUCCEEDED(hrRes));
  5375. }
  5376. }
  5377. if (m_pDispatcher) {
  5378. CComPtr<IEventBindings> pBindings;
  5379. hrRes = piManager->get_Bindings((LPOLESTR) ((LPCOLESTR) CStringGUID(iidEventType)),&pBindings);
  5380. if (!SUCCEEDED(hrRes)) {
  5381. return (hrRes);
  5382. }
  5383. hrRes = m_pDispatcher->SetContext(iidEventType,piRouter,pBindings);
  5384. if (!SUCCEEDED(hrRes)) {
  5385. return (hrRes);
  5386. }
  5387. }
  5388. aiidTmp = new IID[m_dwEventTypes+1];
  5389. if (!aiidTmp) {
  5390. return (E_OUTOFMEMORY);
  5391. }
  5392. memcpy(aiidTmp,m_aiidEventTypes,sizeof(m_aiidEventTypes[0])*m_dwEventTypes);
  5393. delete[] m_aiidEventTypes;
  5394. m_aiidEventTypes = aiidTmp;
  5395. aiidTmp[m_dwEventTypes++] = iidEventType;
  5396. return (S_OK);
  5397. }
  5398. HRESULT CEventRouterInternal::CDispatcher::GetDispatcher(REFIID iidDesired, LPVOID *ppvDispatcher) {
  5399. DEBUG_OBJECT_CHECK
  5400. if (ppvDispatcher) {
  5401. *ppvDispatcher = NULL;
  5402. }
  5403. if (!ppvDispatcher) {
  5404. return (E_POINTER);
  5405. }
  5406. if (!m_pUnkDispatcher) {
  5407. return (E_FAIL);
  5408. }
  5409. return (m_pUnkDispatcher->QueryInterface(iidDesired,ppvDispatcher));
  5410. }
  5411. /////////////////////////////////////////////////////////////////////////////
  5412. // CEventRouter
  5413. HRESULT CEventRouter::FinalConstruct() {
  5414. DEBUG_OBJECT_CHECK
  5415. TraceFunctEnter("CEventRouter::FinalConstruct");
  5416. HRESULT hrRes = S_OK;
  5417. hrRes = CComObject<CEventRouterInternal>::_CreatorClass::CreateInstance(NULL,
  5418. IID_IEventRouter,
  5419. (LPVOID *) &m_pRouter);
  5420. if (SUCCEEDED(hrRes)) {
  5421. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  5422. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  5423. }
  5424. ADD_DEBUG_OBJECT("CEventRouter")
  5425. TraceFunctLeave();
  5426. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  5427. }
  5428. void CEventRouter::FinalRelease() {
  5429. DEBUG_OBJECT_CHECK
  5430. TraceFunctEnter("CEventRouter::FinalRelease");
  5431. if (m_pRouter) {
  5432. m_pRouter->put_Database(NULL);
  5433. }
  5434. m_pRouter.Release();
  5435. m_pUnkMarshaler.Release();
  5436. REMOVE_DEBUG_OBJECT
  5437. TraceFunctLeave();
  5438. }
  5439. HRESULT STDMETHODCALLTYPE CEventRouter::get_Database(IEventBindingManager **ppBindingManager) {
  5440. DEBUG_OBJECT_CHECK
  5441. if (!m_pRouter) {
  5442. return (E_FAIL);
  5443. }
  5444. return (m_pRouter->get_Database(ppBindingManager));
  5445. }
  5446. HRESULT STDMETHODCALLTYPE CEventRouter::put_Database(IEventBindingManager *pBindingManager) {
  5447. DEBUG_OBJECT_CHECK
  5448. if (!m_pRouter) {
  5449. return (E_FAIL);
  5450. }
  5451. return (m_pRouter->put_Database(pBindingManager));
  5452. }
  5453. HRESULT STDMETHODCALLTYPE CEventRouter::putref_Database(IEventBindingManager **ppBindingManager) {
  5454. DEBUG_OBJECT_CHECK
  5455. if (!m_pRouter) {
  5456. return (E_FAIL);
  5457. }
  5458. return (m_pRouter->putref_Database(ppBindingManager));
  5459. }
  5460. HRESULT STDMETHODCALLTYPE CEventRouter::GetDispatcher(REFIID iidEventType,
  5461. REFIID iidDesired,
  5462. IUnknown **ppUnkResult) {
  5463. DEBUG_OBJECT_CHECK
  5464. if (!m_pRouter) {
  5465. return (E_FAIL);
  5466. }
  5467. return (m_pRouter->GetDispatcher(iidEventType,iidDesired,ppUnkResult));
  5468. }
  5469. HRESULT STDMETHODCALLTYPE CEventRouter::GetDispatcherByCLSID(REFCLSID clsidDispatcher,
  5470. REFIID iidEventType,
  5471. REFIID iidDesired,
  5472. IUnknown **ppUnkResult) {
  5473. DEBUG_OBJECT_CHECK
  5474. if (!m_pRouter) {
  5475. return (E_FAIL);
  5476. }
  5477. return (m_pRouter->GetDispatcherByCLSID(clsidDispatcher,
  5478. iidEventType,
  5479. iidDesired,
  5480. ppUnkResult));
  5481. }
  5482. HRESULT STDMETHODCALLTYPE CEventRouter::GetDispatcherByClassFactory(REFCLSID clsidDispatcher,
  5483. IClassFactory *pClassFactory,
  5484. REFIID iidEventType,
  5485. REFIID iidDesired,
  5486. IUnknown **ppUnkResult) {
  5487. DEBUG_OBJECT_CHECK
  5488. if (!m_pRouter) {
  5489. return (E_FAIL);
  5490. }
  5491. return (m_pRouter->GetDispatcherByClassFactory(clsidDispatcher,
  5492. pClassFactory,
  5493. iidEventType,
  5494. iidDesired,
  5495. ppUnkResult));
  5496. }
  5497. /////////////////////////////////////////////////////////////////////////////
  5498. // CEventServiceSubObject
  5499. class ATL_NO_VTABLE CEventServiceSubObject :
  5500. public CComObjectRootEx<CComMultiThreadModelNoCS>,
  5501. // public CComCoClass<CEventRouterInternal, &CLSID_CEventRouterInternal>,
  5502. public IEventNotifyBindingChange
  5503. {
  5504. DEBUG_OBJECT_DEF(CEventServiceSubObject)
  5505. public:
  5506. HRESULT FinalConstruct();
  5507. void FinalRelease();
  5508. DECLARE_PROTECT_FINAL_CONSTRUCT();
  5509. DECLARE_NOT_AGGREGATABLE(CEventServiceSubObject);
  5510. // DECLARE_REGISTRY_RESOURCEID_EX(IDR_StdAfx,
  5511. // L"EventServiceSubObject Class",
  5512. // L"Event.ServiceSubObject.1",
  5513. // L"Event.ServiceSubObject");
  5514. DECLARE_GET_CONTROLLING_UNKNOWN();
  5515. BEGIN_COM_MAP(CEventServiceSubObject)
  5516. COM_INTERFACE_ENTRY(IEventNotifyBindingChange)
  5517. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  5518. END_COM_MAP()
  5519. // IEventNotifyBindingChange
  5520. public:
  5521. HRESULT STDMETHODCALLTYPE OnChange();
  5522. private:
  5523. CComPtr<IUnknown> m_pUnkMarshaler;
  5524. };
  5525. HRESULT CEventServiceSubObject::FinalConstruct() {
  5526. DEBUG_OBJECT_CHECK
  5527. TraceFunctEnter("CEventServiceSubObject::FinalConstruct");
  5528. HRESULT hrRes = S_OK;
  5529. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  5530. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  5531. ADD_DEBUG_OBJECT("CEventServiceObject")
  5532. TraceFunctLeave();
  5533. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  5534. }
  5535. void CEventServiceSubObject::FinalRelease() {
  5536. DEBUG_OBJECT_CHECK
  5537. TraceFunctEnter("CEventServiceSubObject::FinalRelease");
  5538. m_pUnkMarshaler.Release();
  5539. REMOVE_DEBUG_OBJECT
  5540. TraceFunctLeave();
  5541. }
  5542. HRESULT STDMETHODCALLTYPE CEventServiceSubObject::OnChange() {
  5543. // nothing
  5544. return (S_OK);
  5545. }
  5546. /////////////////////////////////////////////////////////////////////////////
  5547. // CEventServiceObject
  5548. HRESULT CEventServiceObject::FinalConstruct() {
  5549. DEBUG_OBJECT_CHECK
  5550. TraceFunctEnter("CEventServiceObject::FinalConstruct");
  5551. HRESULT hrRes = S_OK;
  5552. CComPtr<IConnectionPoint> pCP;
  5553. hrRes = CoCreateInstance(CLSID_CSEOMetaDictionary,
  5554. NULL,
  5555. CLSCTX_ALL,
  5556. IID_IUnknown,
  5557. (LPVOID *) &m_pUnkMetabase);
  5558. if (SUCCEEDED(hrRes)) {
  5559. hrRes = CoCreateFreeThreadedMarshaler(GetControllingUnknown(),&m_pUnkMarshaler.p);
  5560. _ASSERTE(!SUCCEEDED(hrRes)||m_pUnkMarshaler);
  5561. }
  5562. if (SUCCEEDED(hrRes)) {
  5563. m_pCPC = m_pUnkMetabase;
  5564. _ASSERTE(m_pCPC);
  5565. if (!m_pCPC) {
  5566. hrRes = E_NOINTERFACE;
  5567. }
  5568. }
  5569. if (SUCCEEDED(hrRes)) {
  5570. hrRes = m_pCPC->FindConnectionPoint(IID_IEventNotifyBindingChange,&pCP);
  5571. _ASSERTE(SUCCEEDED(hrRes));
  5572. if (!SUCCEEDED(hrRes)) {
  5573. m_pCPC.Release();
  5574. }
  5575. }
  5576. if (SUCCEEDED(hrRes)) {
  5577. hrRes = CComObject<CEventServiceSubObject>::_CreatorClass::CreateInstance(NULL,
  5578. IID_IUnknown,
  5579. (LPVOID *) &m_pSubObject);
  5580. _ASSERTE(SUCCEEDED(hrRes));
  5581. if (SUCCEEDED(hrRes)) {
  5582. hrRes = pCP->Advise(m_pSubObject,&m_dwCookie);
  5583. _ASSERTE(SUCCEEDED(hrRes));
  5584. }
  5585. if (!SUCCEEDED(hrRes)) {
  5586. m_pCPC.Release();
  5587. }
  5588. }
  5589. ADD_DEBUG_OBJECT("CEventServiceObject")
  5590. TraceFunctLeave();
  5591. return (SUCCEEDED(hrRes)?S_OK:hrRes);
  5592. }
  5593. void CEventServiceObject::FinalRelease() {
  5594. DEBUG_OBJECT_CHECK
  5595. TraceFunctEnter("CEventServiceObject::FinalRelease");
  5596. if (m_pCPC) {
  5597. CComPtr<IConnectionPoint> pCP;
  5598. HRESULT hrRes;
  5599. hrRes = m_pCPC->FindConnectionPoint(IID_IEventNotifyBindingChange,&pCP);
  5600. _ASSERTE(SUCCEEDED(hrRes));
  5601. if (SUCCEEDED(hrRes)) {
  5602. hrRes = pCP->Unadvise(m_dwCookie);
  5603. _ASSERTE(SUCCEEDED(hrRes));
  5604. }
  5605. m_pCPC.Release();
  5606. }
  5607. m_pSubObject.Release();
  5608. m_pUnkMetabase.Release();
  5609. m_pUnkMarshaler.Release();
  5610. REMOVE_DEBUG_OBJECT
  5611. TraceFunctLeave();
  5612. }