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.

1171 lines
30 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: bindctx.cxx
  7. //
  8. // Contents: CBindCtx methods implementations
  9. // to support custom marshaling
  10. //
  11. // Classes:
  12. //
  13. // Functions:
  14. //
  15. // History: 9-12-96 JohannP (Johann Posch) Created
  16. //
  17. //----------------------------------------------------------------------------
  18. #include <trans.h>
  19. #include "bindctx.hxx"
  20. PerfDbgTag(tagCBindCtx, "Urlmon", "Log CBindCtx", DEB_URLMON);
  21. #define OBJECTPARAMKEYCHECK1 (_pbcRem && !wcscmp(pszKey, SZ_TRANSACTIONDATA))
  22. #define OBJECTPARAMKEYCHECK2 (_pbcRem && wcscmp(pszKey, SZ_BINDING) \
  23. && wcscmp(pszKey, REG_BSCB_HOLDER) \
  24. && wcscmp(pszKey, REG_ENUMFORMATETC)\
  25. && wcscmp(pszKey, REG_MEDIA_HOLDER) \
  26. && wcscmp(pszKey, SZ_TRANSACTIONDATA))
  27. //+---------------------------------------------------------------------------
  28. //
  29. // Method: CBindCtx::Create
  30. //
  31. // Synopsis:
  32. //
  33. // Arguments: [ppCBCtx] --
  34. //
  35. // Returns:
  36. //
  37. // History: 9-12-96 JohannP (Johann Posch) Created
  38. //
  39. // Notes:
  40. //
  41. //----------------------------------------------------------------------------
  42. HRESULT CBindCtx::Create(CBindCtx **ppCBCtx, IBindCtx *pbc)
  43. {
  44. DEBUG_ENTER((DBG_TRANS,
  45. Hresult,
  46. "CBindCtx::Create",
  47. "%#x, %#x",
  48. ppCBCtx, pbc
  49. ));
  50. PerfDbgLog1(tagCBindCtx, NULL, "+CBindCtx::Create (pbc:%lx)", pbc);
  51. HRESULT hr = NOERROR;
  52. *ppCBCtx = NULL;
  53. if (pbc == NULL)
  54. {
  55. hr = CreateBindCtx(0, &pbc);
  56. }
  57. else
  58. {
  59. // check if this is actually a wrapped object
  60. // if so don't wrap it again
  61. hr = pbc->QueryInterface(IID_IAsyncBindCtx, (void **)ppCBCtx);
  62. if (hr != NOERROR)
  63. {
  64. hr = NOERROR;
  65. *ppCBCtx = NULL;
  66. }
  67. pbc->AddRef();
  68. }
  69. if (hr == NOERROR && *ppCBCtx == NULL)
  70. {
  71. TransAssert((pbc));
  72. *ppCBCtx = new CBindCtx(pbc);
  73. if (*ppCBCtx == NULL)
  74. {
  75. hr = E_OUTOFMEMORY;
  76. }
  77. }
  78. if (pbc)
  79. {
  80. pbc->Release();
  81. }
  82. PerfDbgLog2(tagCBindCtx, NULL, "-CBindCtx::Create (out:%lx,hr:%lx)", *ppCBCtx, hr);
  83. DEBUG_LEAVE(hr);
  84. return hr;
  85. }
  86. //+---------------------------------------------------------------------------
  87. //
  88. // Method: CBindCtx::CBindCtx
  89. //
  90. // Synopsis:
  91. //
  92. // Arguments: [pbc] --
  93. //
  94. // Returns:
  95. //
  96. // History: 9-12-96 JohannP (Johann Posch) Created
  97. //
  98. // Notes:
  99. //
  100. //----------------------------------------------------------------------------
  101. CBindCtx::CBindCtx(IBindCtx *pbc)
  102. {
  103. DEBUG_ENTER((DBG_TRANS,
  104. None,
  105. "CBindCtx::CBindCtx",
  106. "this=%#x, %#x",
  107. this, pbc
  108. ));
  109. _pbcLocal = pbc;
  110. if (_pbcLocal)
  111. {
  112. _pbcLocal->AddRef();
  113. }
  114. _pbcRem = NULL;
  115. _dwThreadId = GetCurrentThreadId();
  116. _pCTrans = 0;
  117. _pCTransData = 0;
  118. DllAddRef();
  119. DEBUG_LEAVE(0);
  120. }
  121. //+---------------------------------------------------------------------------
  122. //
  123. // Method: CBindCtx::~CBindCtx
  124. //
  125. // Synopsis:
  126. //
  127. // Arguments: (none)
  128. //
  129. // Returns:
  130. //
  131. // History: 9-12-96 JohannP (Johann Posch) Created
  132. //
  133. // Notes:
  134. //
  135. //----------------------------------------------------------------------------
  136. CBindCtx::~CBindCtx()
  137. {
  138. DEBUG_ENTER((DBG_TRANS,
  139. None,
  140. "CBindCtx::~CBindCtx",
  141. "this=%#x",
  142. this
  143. ));
  144. //TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  145. if (_pbcRem)
  146. {
  147. _pbcRem->Release();
  148. }
  149. if (_pbcLocal)
  150. {
  151. _pbcLocal->Release();
  152. }
  153. if (_pCTrans)
  154. {
  155. _pCTrans->Release();
  156. }
  157. if (_pCTransData)
  158. {
  159. _pCTransData->Release();
  160. }
  161. DllRelease();
  162. DEBUG_LEAVE(0);
  163. }
  164. //+---------------------------------------------------------------------------
  165. //
  166. // Method: CBindCtx::CanMarshalIID
  167. //
  168. // Synopsis: Checks whether this object supports marshalling this IID.
  169. //
  170. // Arguments: [riid] --
  171. //
  172. // Returns:
  173. //
  174. // History: 9-12-96 JohannP (Johann Posch) Created
  175. //
  176. // Notes:
  177. //
  178. //----------------------------------------------------------------------------
  179. inline BOOL CBindCtx::CanMarshalIID(REFIID riid)
  180. {
  181. DEBUG_ENTER((DBG_TRANS,
  182. Bool,
  183. "CBindCtx::CanMarshalIID",
  184. "this=%#x, %#x",
  185. this, &riid
  186. ));
  187. // keep this in sync with the QueryInterface
  188. BOOL bRet = (BOOL) (riid == IID_IBindCtx);
  189. DEBUG_LEAVE(bRet);
  190. return bRet;
  191. }
  192. //+---------------------------------------------------------------------------
  193. //
  194. // Method: CBindCtx::ValidateMarshalParams
  195. //
  196. // Synopsis: Validates the standard set parameters that are passed into most
  197. // of the IMarshal methods
  198. //
  199. // Arguments: [riid] --
  200. // [pvInterface] --
  201. // [dwDestContext] --
  202. // [pvDestContext] --
  203. // [mshlflags] --
  204. //
  205. // Returns:
  206. //
  207. // History: 9-12-96 JohannP (Johann Posch) Created
  208. //
  209. // Notes:
  210. //
  211. //----------------------------------------------------------------------------
  212. HRESULT CBindCtx::ValidateMarshalParams(REFIID riid,void *pvInterface,
  213. DWORD dwDestContext,void *pvDestContext,DWORD mshlflags)
  214. {
  215. DEBUG_ENTER((DBG_TRANS,
  216. Hresult,
  217. "CBindCtx::ValidateMarshalParams",
  218. "this=%#x, %#x, %#x, %#x, %#x, %#x",
  219. this, &riid, pvInterface, dwDestContext, pvDestContext, mshlflags
  220. ));
  221. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::ValidateMarshalParams");
  222. TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  223. HRESULT hr = NOERROR;
  224. if (CanMarshalIID(riid))
  225. {
  226. UrlMkAssert((dwDestContext == MSHCTX_INPROC || dwDestContext == MSHCTX_LOCAL || dwDestContext == MSHCTX_NOSHAREDMEM));
  227. UrlMkAssert((mshlflags == MSHLFLAGS_NORMAL || mshlflags == MSHLFLAGS_TABLESTRONG));
  228. if ( (dwDestContext != MSHCTX_INPROC && dwDestContext != MSHCTX_LOCAL && dwDestContext != MSHCTX_NOSHAREDMEM)
  229. || (mshlflags != MSHLFLAGS_NORMAL && mshlflags != MSHLFLAGS_TABLESTRONG))
  230. {
  231. hr = E_INVALIDARG;
  232. }
  233. }
  234. else
  235. {
  236. hr = E_NOINTERFACE;
  237. }
  238. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::ValidateMarshalParams (hr:%lx)", hr);
  239. DEBUG_LEAVE(hr);
  240. return hr;
  241. }
  242. //+---------------------------------------------------------------------------
  243. //
  244. // Method: CBindCtx::QueryInterface
  245. //
  246. // Synopsis:
  247. //
  248. // Arguments: [riid] --
  249. // [ppvObj] --
  250. //
  251. // Returns:
  252. //
  253. // History: 9-12-96 JohannP (Johann Posch) Created
  254. //
  255. // Notes:
  256. //
  257. //----------------------------------------------------------------------------
  258. STDMETHODIMP CBindCtx::QueryInterface(REFIID riid, void **ppvObj)
  259. {
  260. DEBUG_ENTER((DBG_TRANS,
  261. Hresult,
  262. "CBindCtx::IUnknown::QueryInterface",
  263. "this=%#x, %#x, %#x",
  264. this, &riid, ppvObj
  265. ));
  266. VDATEPTROUT(ppvObj, void *);
  267. HRESULT hr = NOERROR;
  268. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::QueryInterface");
  269. TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  270. if ( riid == IID_IUnknown
  271. || riid == IID_IBindCtx
  272. || riid == IID_IAsyncBindCtx)
  273. {
  274. *ppvObj = this;
  275. }
  276. else if (riid == IID_IMarshal)
  277. {
  278. *ppvObj = (void*) (IMarshal *) this;
  279. }
  280. else
  281. {
  282. *ppvObj = NULL;
  283. hr = E_NOINTERFACE;
  284. }
  285. if (hr == NOERROR)
  286. {
  287. AddRef();
  288. }
  289. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::QueryInterface (hr:%lx)", hr);
  290. DEBUG_LEAVE(hr);
  291. return hr;
  292. }
  293. //+---------------------------------------------------------------------------
  294. //
  295. // Function: CBindCtx::AddRef
  296. //
  297. // Synopsis:
  298. //
  299. // Arguments: [ULONG] --
  300. //
  301. // Returns:
  302. //
  303. // History: 9-12-96 JohannP (Johann Posch) Created
  304. //
  305. // Notes:
  306. //
  307. //----------------------------------------------------------------------------
  308. STDMETHODIMP_(ULONG) CBindCtx::AddRef(void)
  309. {
  310. DEBUG_ENTER((DBG_TRANS,
  311. Dword,
  312. "CBindCtx::IUnknown::AddRef",
  313. "this=%#x",
  314. this
  315. ));
  316. //TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  317. LONG lRet = ++_CRefs;
  318. PerfDbgLog1(tagCBindCtx, this, "CBindCtx::AddRef (cRefs:%ld)", lRet);
  319. DEBUG_LEAVE(lRet);
  320. return lRet;
  321. }
  322. //+---------------------------------------------------------------------------
  323. //
  324. // Function: CBindCtx::Release
  325. //
  326. // Synopsis:
  327. //
  328. // Arguments: [ULONG] --
  329. //
  330. // Returns:
  331. //
  332. // History: 9-12-96 JohannP (Johann Posch) Created
  333. //
  334. // Notes:
  335. //
  336. //----------------------------------------------------------------------------
  337. STDMETHODIMP_(ULONG) CBindCtx::Release(void)
  338. {
  339. DEBUG_ENTER((DBG_TRANS,
  340. Dword,
  341. "CBindCtx::IUnknown::Release",
  342. "this=%#x",
  343. this
  344. ));
  345. //TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  346. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::Release");
  347. LONG lRet = --_CRefs;
  348. if (_CRefs == 0)
  349. {
  350. delete this;
  351. }
  352. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::Release (cRefs:%ld)", lRet);
  353. DEBUG_LEAVE(lRet);
  354. return lRet;
  355. }
  356. //+---------------------------------------------------------------------------
  357. //
  358. // Method: CBindCtx::GetObjectParam
  359. //
  360. // Synopsis:
  361. //
  362. // Arguments: [pszKey] --
  363. // [ppunk] --
  364. //
  365. // Returns:
  366. //
  367. // History: 9-12-96 JohannP (Johann Posch) Created
  368. //
  369. // Notes:
  370. //
  371. //----------------------------------------------------------------------------
  372. STDMETHODIMP CBindCtx::GetObjectParam(LPOLESTR pszKey, IUnknown **ppunk)
  373. {
  374. DEBUG_ENTER((DBG_TRANS,
  375. Hresult,
  376. "CBindCtx::IBindCtx::GetObjectParam",
  377. "this=%#x, %#x, %#x",
  378. this, pszKey, ppunk
  379. ));
  380. HRESULT hr = NOERROR;
  381. PerfDbgLog3(tagCBindCtx, this, "+CBindCtx::GetObjectParam (_pbcLocal:%lx, _pbcRem:%lx, szParam:%ws)", _pbcLocal, _pbcRem, pszKey);
  382. UrlMkAssert((pszKey && ppunk));
  383. if (OBJECTPARAMKEYCHECK1)
  384. {
  385. // get the interface from the remote object
  386. PerfDbgLog2(tagCBindCtx, this, "=== CBindCtx::GetObjectParam (_pbcRem:%lx, szParam:%ws)", _pbcRem, pszKey);
  387. hr = _pbcLocal->GetObjectParam(pszKey, ppunk);
  388. if (hr != NOERROR)
  389. {
  390. hr = _pbcRem->GetObjectParam(pszKey, ppunk);
  391. }
  392. }
  393. else
  394. {
  395. hr = _pbcLocal->GetObjectParam(pszKey, ppunk);
  396. }
  397. if ((hr != NOERROR) && OBJECTPARAMKEYCHECK2)
  398. {
  399. hr = _pbcRem->GetObjectParam(pszKey, ppunk);
  400. }
  401. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::GetObjectParam (hr:%lx)", hr);
  402. DEBUG_LEAVE(hr);
  403. return hr;
  404. }
  405. //+---------------------------------------------------------------------------
  406. //
  407. // Method: CBindCtx::EnumObjectParam
  408. //
  409. // Synopsis:
  410. //
  411. // Arguments: [ppenum] --
  412. //
  413. // Returns:
  414. //
  415. // History: 9-12-96 JohannP (Johann Posch) Created
  416. //
  417. // Notes: BUGBUG - this implementation is wrong; need to wrap
  418. //
  419. //----------------------------------------------------------------------------
  420. STDMETHODIMP CBindCtx::EnumObjectParam(IEnumString **ppenum)
  421. {
  422. DEBUG_ENTER((DBG_TRANS,
  423. Hresult,
  424. "CBindCtx::IBindCtx::EnumObjectParam",
  425. "this=%#x, %#x",
  426. this, ppenum
  427. ));
  428. HRESULT hr = _pbcLocal->EnumObjectParam(ppenum);
  429. DEBUG_LEAVE(hr);
  430. return hr;
  431. }
  432. STDMETHODIMP CBindCtx::RevokeObjectParam(LPOLESTR pszKey)
  433. {
  434. DEBUG_ENTER((DBG_TRANS,
  435. Hresult,
  436. "CBindCtx::IBindCtx::RevokeObjectParam",
  437. "this=%#x, %#x",
  438. this, pszKey
  439. ));
  440. HRESULT hr = NOERROR;
  441. PerfDbgLog3(tagCBindCtx, this, "+CBindCtx::RevokeObjectParam (_pbcLocal:%lx, _pbcRem:%lx, szParam:%ws)", _pbcLocal, _pbcRem, pszKey);
  442. UrlMkAssert(pszKey);
  443. if (OBJECTPARAMKEYCHECK1)
  444. {
  445. // get the interface from the remote object
  446. PerfDbgLog2(tagCBindCtx, this, "=== CBindCtx::RevokeObjectParam (_pbcRem:%lx, szParam:%ws)", _pbcRem, pszKey);
  447. hr = _pbcLocal->RevokeObjectParam(pszKey);
  448. if (hr != NOERROR)
  449. {
  450. hr = _pbcRem->RevokeObjectParam(pszKey);
  451. }
  452. }
  453. else
  454. {
  455. hr = _pbcLocal->RevokeObjectParam(pszKey);
  456. }
  457. if ((hr != NOERROR) && OBJECTPARAMKEYCHECK2)
  458. {
  459. hr = _pbcRem->RevokeObjectParam(pszKey);
  460. }
  461. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::RevokeObjectParam (hr:%lx)", hr);
  462. DEBUG_LEAVE(hr);
  463. return hr;
  464. }
  465. //+---------------------------------------------------------------------------
  466. //
  467. // IMarshal methods
  468. //
  469. //+---------------------------------------------------------------------------
  470. //
  471. // Method: CBindCtx::GetUnmarshalClass
  472. //
  473. // Synopsis:
  474. //
  475. // Arguments: [riid] --
  476. // [pvInterface] --
  477. // [dwDestContext] --
  478. // [pvDestContext] --
  479. // [mshlflags] --
  480. // [pCid] --
  481. //
  482. // Returns:
  483. //
  484. // History: 9-12-96 JohannP (Johann Posch) Created
  485. //
  486. // Notes:
  487. //
  488. //----------------------------------------------------------------------------
  489. STDMETHODIMP CBindCtx::GetUnmarshalClass(REFIID riid,void *pvInterface,
  490. DWORD dwDestContext,void *pvDestContext,DWORD mshlflags,CLSID *pCid)
  491. {
  492. DEBUG_ENTER((DBG_TRANS,
  493. Hresult,
  494. "CBindCtx::IMarshal::GetUnmarshalClass",
  495. "this=%#x, %#x, %#x, %#x, %#x, %#x, %#x",
  496. this, &riid, pvInterface, dwDestContext, pvDestContext, mshlflags, pCid
  497. ));
  498. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::GetUnmarshalClass");
  499. HRESULT hr;
  500. hr = ValidateMarshalParams(riid, pvInterface, dwDestContext,pvDestContext, mshlflags);
  501. if (hr == NOERROR)
  502. {
  503. *pCid = (CLSID) CLSID_UrlMkBindCtx;
  504. }
  505. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::GetUnmarshalClass (hr:%lx)", hr);
  506. DEBUG_LEAVE(hr);
  507. return hr;
  508. }
  509. //+---------------------------------------------------------------------------
  510. //
  511. // Method: CBindCtx::GetMarshalSizeMax
  512. //
  513. // Synopsis:
  514. //
  515. // Arguments: [void] --
  516. // [pvInterface] --
  517. // [dwDestContext] --
  518. // [pvDestContext] --
  519. // [mshlflags] --
  520. // [pSize] --
  521. //
  522. // Returns:
  523. //
  524. // History: 9-12-96 JohannP (Johann Posch) Created
  525. //
  526. // Notes:
  527. //
  528. //----------------------------------------------------------------------------
  529. STDMETHODIMP CBindCtx::GetMarshalSizeMax(REFIID riid,void *pvInterface,
  530. DWORD dwDestContext,void *pvDestContext,DWORD mshlflags,DWORD *pSize)
  531. {
  532. DEBUG_ENTER((DBG_TRANS,
  533. Hresult,
  534. "CBindCtx::IMarshal::GetMarshalSizeMax",
  535. "this=%#x, %#x, %#x, %#x, %#x, %#x, %#x",
  536. this, &riid, pvInterface, dwDestContext, pvDestContext, mshlflags, pSize
  537. ));
  538. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::GetMarshalSizeMax");
  539. HRESULT hr;
  540. if (pSize == NULL)
  541. {
  542. hr = E_INVALIDARG;
  543. }
  544. else
  545. {
  546. hr = ValidateMarshalParams(riid, pvInterface, dwDestContext,pvDestContext, mshlflags);
  547. if (hr == NOERROR)
  548. {
  549. hr = CoGetMarshalSizeMax(pSize, IID_IBindCtx, _pbcLocal, dwDestContext,pvDestContext,mshlflags);
  550. // marshal also the transaction object
  551. *pSize += sizeof(_pCTrans) + sizeof(DWORD);
  552. }
  553. }
  554. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::GetMarshalSizeMax (hr:%lx)", hr);
  555. DEBUG_LEAVE(hr);
  556. return hr;
  557. }
  558. //+---------------------------------------------------------------------------
  559. //
  560. // Method: CBindCtx::MarshalInterface
  561. //
  562. // Synopsis:
  563. //
  564. // Arguments: [REFIID] --
  565. // [riid] --
  566. // [DWORD] --
  567. // [void] --
  568. // [DWORD] --
  569. // [mshlflags] --
  570. //
  571. // Returns:
  572. //
  573. // History: 9-12-96 JohannP (Johann Posch) Created
  574. //
  575. // Notes:
  576. //
  577. //----------------------------------------------------------------------------
  578. STDMETHODIMP CBindCtx::MarshalInterface(IStream *pistm,REFIID riid,
  579. void *pvInterface,DWORD dwDestContext,
  580. void *pvDestContext,DWORD mshlflags)
  581. {
  582. DEBUG_ENTER((DBG_TRANS,
  583. Hresult,
  584. "CBindCtx::IMarshal::MarshalInterface",
  585. "this=%#x, %#x, %#x, %#x, %#x, %#x, %#x",
  586. this, pistm, &riid, pvInterface, dwDestContext, pvDestContext, mshlflags
  587. ));
  588. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::MarshalInterface");
  589. HRESULT hr;
  590. BOOL fTransfered = FALSE;
  591. hr = ValidateMarshalParams(riid, pvInterface, dwDestContext,pvDestContext, mshlflags);
  592. if (hr == NOERROR)
  593. {
  594. hr = CoMarshalInterface(pistm, IID_IBindCtx, _pbcLocal, dwDestContext, pvDestContext, mshlflags);
  595. }
  596. if ( (hr == NOERROR)
  597. && (dwDestContext == MSHCTX_INPROC)
  598. && (_pCTrans != NULL) )
  599. {
  600. TransAssert((_pCTrans));
  601. TransAssert((_pCTransData));
  602. hr = _pCTrans->PrepareThreadTransfer();
  603. if (hr == NOERROR)
  604. {
  605. DWORD dwProcessId = GetCurrentProcessId();
  606. // marshal also the transaction object
  607. hr = pistm->Write(&_pCTrans, sizeof(_pCTrans), NULL);
  608. TransAssert((hr == NOERROR));
  609. // addref the pointer here to keep the object alive!
  610. //
  611. _pCTrans->AddRef();
  612. // marshal also the transdata object
  613. hr = pistm->Write(&_pCTransData, sizeof(_pCTransData), NULL);
  614. TransAssert((hr == NOERROR));
  615. if (_pCTransData)
  616. {
  617. _pCTransData->PrepareThreadTransfer();
  618. // addref the pointer here to keep the object alive!
  619. //
  620. _pCTransData->AddRef();
  621. }
  622. hr = pistm->Write(&dwProcessId, sizeof(DWORD), NULL);
  623. TransAssert((hr == NOERROR));
  624. fTransfered = TRUE;
  625. }
  626. }
  627. if (!fTransfered)
  628. {
  629. DWORD dwProcessId = 0;
  630. LPVOID pNull = NULL;
  631. // marshal also the transaction object
  632. hr = pistm->Write(&pNull, sizeof(pNull), NULL);
  633. TransAssert((hr == NOERROR));
  634. hr = pistm->Write(&pNull, sizeof(pNull), NULL);
  635. TransAssert((hr == NOERROR));
  636. hr = pistm->Write(&dwProcessId, sizeof(DWORD), NULL);
  637. TransAssert((hr == NOERROR));
  638. }
  639. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::MarshalInterface (hr:%lx)", hr);
  640. DEBUG_LEAVE(hr);
  641. return hr;
  642. }
  643. //+---------------------------------------------------------------------------
  644. //
  645. // Method: CBindCtx::UnmarshalInterface
  646. //
  647. // Synopsis: Unmarshals an Urlmon interface out of a stream
  648. //
  649. // Arguments: [REFIID] --
  650. // [void] --
  651. // [ppvObj] --
  652. //
  653. // Returns:
  654. //
  655. // History: 9-12-96 JohannP (Johann Posch) Created
  656. //
  657. // Notes:
  658. //
  659. //----------------------------------------------------------------------------
  660. STDMETHODIMP CBindCtx::UnmarshalInterface(IStream *pistm,REFIID riid,void ** ppvObj)
  661. {
  662. DEBUG_ENTER((DBG_TRANS,
  663. Hresult,
  664. "CBindCtx::IMarshal::UnmarshalInterface",
  665. "this=%#x, %#x, %#x, %#x",
  666. this, pistm, &riid, ppvObj
  667. ));
  668. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::UnmarshalInterface");
  669. HRESULT hr = NOERROR;
  670. TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  671. if (ppvObj == NULL)
  672. {
  673. hr = E_INVALIDARG;
  674. }
  675. else if (! CanMarshalIID(riid))
  676. {
  677. *ppvObj = NULL;
  678. hr = E_NOINTERFACE;
  679. }
  680. else
  681. {
  682. *ppvObj = NULL;
  683. hr = CoUnmarshalInterface(pistm, IID_IBindCtx, (void **) &_pbcRem);
  684. // call QI to get the requested interface
  685. if (hr == NOERROR)
  686. {
  687. hr = QueryInterface(riid, ppvObj);
  688. {
  689. HRESULT hr1;
  690. DWORD dwProcessId;
  691. // marshal also the transaction object
  692. hr1 = pistm->Read(&_pCTrans, sizeof(_pCTrans), NULL);
  693. // Note: pTrans was addref'd as the object was marshaled // it is now addref'd
  694. // keep it since we hold on to the object
  695. if (FAILED(hr1))
  696. {
  697. _pCTrans = 0;
  698. }
  699. // marshal also the transdata object
  700. hr1 = pistm->Read(&_pCTransData, sizeof(_pCTransData), NULL);
  701. // Note: pTrans was addref'd as the object was marshaled // it is now addref'd
  702. // keep it since we hold on to the object
  703. if (FAILED(hr1))
  704. {
  705. _pCTransData = 0;
  706. }
  707. //TransAssert((hr1 == NOERROR));
  708. hr1 = pistm->Read(&dwProcessId, sizeof(DWORD), NULL);
  709. TransAssert((hr1 == NOERROR));
  710. if (FAILED(hr1))
  711. {
  712. dwProcessId = 0;
  713. }
  714. }
  715. }
  716. else
  717. {
  718. TransAssert(( _pbcRem == 0));
  719. }
  720. }
  721. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::UnmarshalInterface (hr:%lx)", hr);
  722. DEBUG_LEAVE(hr);
  723. return hr;
  724. }
  725. STDMETHODIMP CBindCtx::ReleaseMarshalData(IStream *pStm)
  726. {
  727. DEBUG_ENTER((DBG_TRANS,
  728. Hresult,
  729. "CBindCtx::IMarshal::ReleaseMarshalData",
  730. "this=%#x, %#x",
  731. this, pStm
  732. ));
  733. PerfDbgLog(tagCBindCtx, this, "CBindCtx::ReleaseMarshalData");
  734. DEBUG_LEAVE(NOERROR);
  735. return NOERROR;
  736. }
  737. STDMETHODIMP CBindCtx::DisconnectObject(DWORD dwReserved)
  738. {
  739. DEBUG_ENTER((DBG_TRANS,
  740. Hresult,
  741. "CBindCtx::IMarshal::DisconnectObject",
  742. "this=%#x, %#x",
  743. this, dwReserved
  744. ));
  745. PerfDbgLog(tagCBindCtx, this, "CBindCtx::DisconnectObject");
  746. DEBUG_LEAVE(NOERROR);
  747. return NOERROR;
  748. }
  749. //+---------------------------------------------------------------------------
  750. //
  751. // Method: CBindCtx::SetTransactionObject
  752. //
  753. // Synopsis:
  754. //
  755. // Arguments: [pCTrans] --
  756. //
  757. // Returns:
  758. //
  759. // History: 10-09-1996 JohannP (Johann Posch) Created
  760. //
  761. // Notes:
  762. //
  763. //----------------------------------------------------------------------------
  764. STDMETHODIMP CBindCtx::SetTransactionObject(CTransaction *pCTrans)
  765. {
  766. DEBUG_ENTER((DBG_TRANS,
  767. Hresult,
  768. "CBindCtx::SetTransactionObject",
  769. "this=%#x, %#x",
  770. this, pCTrans
  771. ));
  772. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::SetTransactionObject");
  773. //TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  774. if (pCTrans != _pCTrans)
  775. {
  776. if (_pCTrans)
  777. {
  778. _pCTrans->Release();
  779. }
  780. _pCTrans = pCTrans;
  781. if (_pCTrans)
  782. {
  783. _pCTrans->AddRef();
  784. }
  785. }
  786. PerfDbgLog(tagCBindCtx, this, "-CBindCtx::SetTransactionObject (hr:0)");
  787. DEBUG_LEAVE(NOERROR);
  788. return NOERROR;
  789. }
  790. //+---------------------------------------------------------------------------
  791. //
  792. // Method: CBindCtx::GetTransactionObject
  793. //
  794. // Synopsis:
  795. //
  796. // Arguments: [ppCTrans] --
  797. //
  798. // Returns:
  799. //
  800. // History: 10-09-1996 JohannP (Johann Posch) Created
  801. //
  802. // Notes:
  803. //
  804. //----------------------------------------------------------------------------
  805. STDMETHODIMP CBindCtx::GetTransactionObject(CTransaction **ppCTrans)
  806. {
  807. DEBUG_ENTER((DBG_TRANS,
  808. Hresult,
  809. "CBindCtx::GetTransactionObject",
  810. "this=%#x, %#x",
  811. this, ppCTrans
  812. ));
  813. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::GetTransactionObject");
  814. //TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  815. HRESULT hr = NOERROR;
  816. if (_pCTrans)
  817. {
  818. *ppCTrans = _pCTrans;
  819. _pCTrans->AddRef();
  820. }
  821. else
  822. {
  823. hr = E_NOINTERFACE;
  824. *ppCTrans = NULL;
  825. }
  826. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::GetTransactionObject (hr:%lx)", hr);
  827. DEBUG_LEAVE(hr);
  828. return hr;
  829. }
  830. //+---------------------------------------------------------------------------
  831. //
  832. // Method: CBindCtx::SetTransactionObjects
  833. //
  834. // Synopsis:
  835. //
  836. // Arguments: [pCTrans] --
  837. //
  838. // Returns:
  839. //
  840. // History: 10-09-1996 JohannP (Johann Posch) Created
  841. //
  842. // Notes:
  843. //
  844. //----------------------------------------------------------------------------
  845. STDMETHODIMP CBindCtx::SetTransactionObjects(CTransaction *pCTrans,CTransData *pCTransData)
  846. {
  847. DEBUG_ENTER((DBG_TRANS,
  848. Hresult,
  849. "CBindCtx::SetTransactionObjects",
  850. "this=%#x, %#x, %#x",
  851. this, pCTrans, pCTransData
  852. ));
  853. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::SetTransactionObjects");
  854. //TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  855. if (pCTrans != _pCTrans)
  856. {
  857. if (_pCTrans)
  858. {
  859. _pCTrans->Release();
  860. }
  861. _pCTrans = pCTrans;
  862. if (_pCTrans)
  863. {
  864. _pCTrans->AddRef();
  865. }
  866. }
  867. if (pCTransData != _pCTransData)
  868. {
  869. if (_pCTransData)
  870. {
  871. _pCTransData->Release();
  872. }
  873. _pCTransData = pCTransData;
  874. if (_pCTransData)
  875. {
  876. _pCTransData->AddRef();
  877. }
  878. }
  879. PerfDbgLog(tagCBindCtx, this, "-CBindCtx::SetTransactionObjects (hr:0)");
  880. DEBUG_LEAVE(NOERROR);
  881. return NOERROR;
  882. }
  883. //+---------------------------------------------------------------------------
  884. //
  885. // Method: CBindCtx::GetTransactionObject
  886. //
  887. // Synopsis:
  888. //
  889. // Arguments: [ppCTrans] --
  890. //
  891. // Returns:
  892. //
  893. // History: 10-09-1996 JohannP (Johann Posch) Created
  894. //
  895. // Notes:
  896. //
  897. //----------------------------------------------------------------------------
  898. STDMETHODIMP CBindCtx::GetTransactionObjects(CTransaction **ppCTrans,CTransData **ppCTransData)
  899. {
  900. DEBUG_ENTER((DBG_TRANS,
  901. Hresult,
  902. "CBindCtx::GetTransactionObjects",
  903. "this=%#x, %#x, %#x",
  904. this, ppCTrans, ppCTransData
  905. ));
  906. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::GetTransactionObjects");
  907. TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  908. HRESULT hr = NOERROR;
  909. if (_pCTrans)
  910. {
  911. *ppCTrans = _pCTrans;
  912. _pCTrans->AddRef();
  913. }
  914. else
  915. {
  916. hr = E_NOINTERFACE;
  917. *ppCTrans = NULL;
  918. }
  919. if (_pCTransData && ppCTransData)
  920. {
  921. *ppCTransData = _pCTransData;
  922. _pCTransData->AddRef();
  923. }
  924. else
  925. {
  926. if (!_pCTrans)
  927. {
  928. hr = E_NOINTERFACE;
  929. }
  930. if (ppCTransData)
  931. {
  932. *ppCTransData = NULL;
  933. }
  934. }
  935. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::GetTransactionObjects (hr:%lx)", hr);
  936. DEBUG_LEAVE(hr);
  937. return hr;
  938. }
  939. //+---------------------------------------------------------------------------
  940. //
  941. // Method: CBindCtx::SetTransData
  942. //
  943. // Synopsis:
  944. //
  945. // Arguments: [pCTransData] --
  946. //
  947. // Returns:
  948. //
  949. // History: 10-09-1996 JohannP (Johann Posch) Created
  950. //
  951. // Notes:
  952. //
  953. //----------------------------------------------------------------------------
  954. STDMETHODIMP CBindCtx::SetTransData(CTransData *pCTransData)
  955. {
  956. DEBUG_ENTER((DBG_TRANS,
  957. Hresult,
  958. "CBindCtx::SetTransData",
  959. "this=%#x, %#x",
  960. this, pCTransData
  961. ));
  962. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::SetTransData");
  963. TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  964. if (pCTransData != _pCTransData)
  965. {
  966. if (_pCTransData)
  967. {
  968. _pCTransData->Release();
  969. }
  970. _pCTransData = pCTransData;
  971. if (_pCTransData)
  972. {
  973. _pCTransData->AddRef();
  974. }
  975. }
  976. PerfDbgLog(tagCBindCtx, this, "-CBindCtx::SetTransData (hr:0)");
  977. DEBUG_LEAVE(NOERROR);
  978. return NOERROR;
  979. }
  980. //+---------------------------------------------------------------------------
  981. //
  982. // Method: CBindCtx::GetTransData
  983. //
  984. // Synopsis:
  985. //
  986. // Arguments: [ppCTransData] --
  987. //
  988. // Returns:
  989. //
  990. // History: 10-09-1996 JohannP (Johann Posch) Created
  991. //
  992. // Notes:
  993. //
  994. //----------------------------------------------------------------------------
  995. STDMETHODIMP CBindCtx::GetTransData(CTransData **ppCTransData)
  996. {
  997. DEBUG_ENTER((DBG_TRANS,
  998. Hresult,
  999. "CBindCtx::GetTransData",
  1000. "this=%#x, %#x",
  1001. this, ppCTransData
  1002. ));
  1003. PerfDbgLog(tagCBindCtx, this, "+CBindCtx::GetTransData");
  1004. TransAssert(( _dwThreadId == GetCurrentThreadId() ));
  1005. HRESULT hr = NOERROR;
  1006. if (_pCTransData)
  1007. {
  1008. *ppCTransData = _pCTransData;
  1009. _pCTransData->AddRef();
  1010. }
  1011. else
  1012. {
  1013. hr = E_NOINTERFACE;
  1014. *ppCTransData = NULL;
  1015. }
  1016. PerfDbgLog1(tagCBindCtx, this, "-CBindCtx::GetTransData (hr:%lx)", hr);
  1017. DEBUG_LEAVE(hr);
  1018. return hr;
  1019. }