Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

739 lines
22 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: comdbg.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef COMDBG_H
  11. #define COMDBG_H
  12. #include <objidl.h>
  13. #include <comdef.h>
  14. #include <atlbase.h>
  15. #include <atlcom.h>
  16. #include "dbg.h"
  17. #ifdef DBG
  18. //#define COMDBG
  19. #endif
  20. #ifdef COMDBG
  21. inline void DumpStorage(IStorage* pStorage)
  22. {
  23. ASSERT(pStorage != NULL);
  24. if (pStorage == NULL)
  25. return;
  26. STATSTG s;
  27. HRESULT hr = pStorage->Stat(&s, STATFLAG_DEFAULT);
  28. ASSERT(hr == S_OK);
  29. if (hr != S_OK)
  30. return;
  31. TRACE(L"%s->\n", s.pwcsName);
  32. CoTaskMemFree(s.pwcsName);
  33. IEnumSTATSTGPtr spElements;
  34. hr = pStorage->EnumElements(0, NULL, 0, &spElements);
  35. ASSERT(hr == S_OK || hr == STG_E_ACCESSDENIED);
  36. if (hr == STG_E_ACCESSDENIED)
  37. TRACE(L" (not enumerating contents of write-only storage)\n", s.pwcsName);
  38. if (hr != S_OK)
  39. return;
  40. do
  41. {
  42. ULONG numberReturned;
  43. hr = spElements->Next(1, &s, &numberReturned);
  44. if (hr != S_OK || numberReturned != 1)
  45. return;
  46. if (s.type == STGTY_STORAGE)
  47. TRACE(L" [%s]\n", s.pwcsName);
  48. else
  49. TRACE(L" %s (%u bytes)\n", s.pwcsName, s.cbSize.LowPart);
  50. CoTaskMemFree(s.pwcsName);
  51. } while (true);
  52. }
  53. class ProxyReporter
  54. {
  55. public:
  56. ProxyReporter()
  57. : m_LastName(L"Unnamed"), m_LastInterface(L"Unknown"), m_LastThis(UINT_PTR(this))
  58. {
  59. TRACE(L"<PR>(%s(%s:%X)) is crowning.\n", GetLastInterface(), GetLastName(), GetLastThis());
  60. }
  61. virtual ~ProxyReporter()
  62. {
  63. TRACE(L"<PR>(%s(%s:%X)) is dead.\n", GetLastInterface(), GetLastName(), m_LastThis);
  64. }
  65. protected:
  66. void Born() const
  67. {
  68. TRACE(L"<PR>(%s(%s:%X)) is alive.\n", GetLastInterface(), GetLastName(), GetLastThis());
  69. }
  70. void Dying() const
  71. {
  72. TRACE(L"<PR>(%s(%s:%X)) is dying.\n", GetLastInterface(), GetLastName(), GetLastThis());
  73. }
  74. void CallHome(const wchar_t* from) const
  75. {
  76. TRACE(L"<PR>(%s(%s:%X)#%u) calling home from: %s\n", GetLastInterface(), GetLastName(), GetLastThis(), GetRefCount(), from);
  77. }
  78. virtual const void* GetThis() const
  79. {
  80. return this;
  81. }
  82. virtual const wchar_t* GetInstanceName() const
  83. {
  84. return m_LastName;
  85. }
  86. virtual const wchar_t* GetInterfaceName() const
  87. {
  88. return m_LastInterface;
  89. }
  90. virtual unsigned GetRefCount() const
  91. {
  92. return 0;
  93. }
  94. private:
  95. mutable const wchar_t* m_LastName;
  96. mutable const wchar_t* m_LastInterface;
  97. mutable UINT_PTR m_LastThis;
  98. const const wchar_t* GetLastName() const
  99. {
  100. return m_LastName = GetInstanceName();
  101. }
  102. const const wchar_t* GetLastInterface() const
  103. {
  104. return m_LastInterface = GetInterfaceName();
  105. }
  106. unsigned GetLastThis() const
  107. {
  108. return m_LastThis = UINT_PTR(GetThis());
  109. }
  110. }; // class ProxyReporter
  111. template<typename Base>
  112. class ATLProxyReporter : public Base
  113. {
  114. public:
  115. ATLProxyReporter()
  116. : m_InstanceName(L"Unnamed")
  117. {
  118. Born();
  119. }
  120. virtual ~ATLProxyReporter()
  121. {
  122. Dying();
  123. }
  124. void InitATLProxyReporter(const wchar_t* instanceName)
  125. {
  126. ASSERT(instanceName != NULL);
  127. m_InstanceName = instanceName;
  128. CallHome(L"InitATLProxyReporter");
  129. }
  130. protected:
  131. ULONG InternalAddRef()
  132. {
  133. const ULONG r = Base::InternalAddRef();
  134. CallHome(L"InternalAddRef(after)");
  135. return r;
  136. }
  137. ULONG InternalRelease()
  138. {
  139. CallHome(L"InternalRelease(before)");
  140. return Base::InternalRelease();
  141. }
  142. virtual const void* GetThis() const
  143. {
  144. return this;
  145. }
  146. virtual const wchar_t* GetInstanceName() const
  147. {
  148. ASSERT(m_InstanceName != NULL);
  149. return m_InstanceName;
  150. }
  151. virtual unsigned GetRefCount() const
  152. {
  153. return unsigned(m_dwRef);
  154. }
  155. private:
  156. const wchar_t* m_InstanceName;
  157. }; // class ATLProxyReporter
  158. class __declspec(uuid("B425E0EC-A086-11d0-8F59-00A0C91ED3C8")) DebugStream :
  159. public IStream, public CComObjectRoot, public ProxyReporter
  160. {
  161. public:
  162. DebugStream()
  163. {
  164. }
  165. virtual ~DebugStream()
  166. {
  167. }
  168. void InitDebugStream(IStream* pStream)
  169. {
  170. ASSERT(m_spStream == NULL);
  171. ASSERT(pStream != NULL);
  172. m_spStream = pStream;
  173. }
  174. BEGIN_COM_MAP(DebugStream)
  175. COM_INTERFACE_ENTRY_IID(__uuidof(DebugStream), DebugStream)
  176. COM_INTERFACE_ENTRY_IID(__uuidof(IStream), IStream)
  177. END_COM_MAP()
  178. DECLARE_NOT_AGGREGATABLE(DebugStream)
  179. // IStream
  180. public:
  181. STDMETHOD(Read)(void *pv, ULONG cb, ULONG *pcbRead)
  182. {
  183. ASSERT(m_spStream != NULL);
  184. HRESULT const hr = m_spStream->Read(pv, cb, pcbRead);
  185. CallHome(SUCCEEDED(hr) ? L"Read" : L"Read(failed!)");
  186. return hr;
  187. }
  188. STDMETHOD(Write)(const void *pv, ULONG cb, ULONG *pcbWritten)
  189. {
  190. ASSERT(m_spStream != NULL);
  191. HRESULT const hr = m_spStream->Write(pv, cb, pcbWritten);
  192. CallHome(SUCCEEDED(hr) ? L"Write" : L"Write(failed!)");
  193. return hr;
  194. }
  195. STDMETHOD(Seek)(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
  196. {
  197. ASSERT(m_spStream != NULL);
  198. HRESULT const hr = m_spStream->Seek(dlibMove, dwOrigin, plibNewPosition);
  199. CallHome(SUCCEEDED(hr) ? L"Seek" : L"Seek(failed!)");
  200. return hr;
  201. }
  202. STDMETHOD(SetSize)(ULARGE_INTEGER libNewSize)
  203. {
  204. ASSERT(m_spStream != NULL);
  205. HRESULT const hr = m_spStream->SetSize(libNewSize);
  206. CallHome(SUCCEEDED(hr) ? L"SetSize" : L"SetSize(failed!)");
  207. return hr;
  208. }
  209. STDMETHOD(CopyTo)(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
  210. {
  211. ASSERT(m_spStream != NULL);
  212. HRESULT const hr = m_spStream->CopyTo(pstm, cb, pcbRead, pcbWritten);
  213. CallHome(SUCCEEDED(hr) ? L"CopyTo" : L"CopyTo(failed!)");
  214. return hr;
  215. }
  216. STDMETHOD(Commit)(DWORD grfCommitFlags)
  217. {
  218. ASSERT(m_spStream != NULL);
  219. HRESULT const hr = m_spStream->Commit(grfCommitFlags);
  220. CallHome(SUCCEEDED(hr) ? L"Commit" : L"Commit(failed!)");
  221. return hr;
  222. }
  223. STDMETHOD(Revert)()
  224. {
  225. ASSERT(m_spStream != NULL);
  226. HRESULT const hr = m_spStream->Revert();
  227. CallHome(SUCCEEDED(hr) ? L"Revert" : L"Revert(failed!)");
  228. return hr;
  229. }
  230. STDMETHOD(LockRegion)(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  231. {
  232. ASSERT(m_spStream != NULL);
  233. HRESULT const hr = m_spStream->LockRegion(libOffset, cb, dwLockType);
  234. CallHome(SUCCEEDED(hr) ? L"LockRegion" : L"LockRegion(failed!)");
  235. return hr;
  236. }
  237. STDMETHOD(UnlockRegion)(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  238. {
  239. ASSERT(m_spStream != NULL);
  240. HRESULT const hr = m_spStream->UnlockRegion(libOffset, cb, dwLockType);
  241. CallHome(SUCCEEDED(hr) ? L"UnlockRegion" : L"UnlockRegion(failed!)");
  242. return hr;
  243. }
  244. STDMETHOD(Stat)(STATSTG *pstatstg, DWORD grfStatFlag)
  245. {
  246. ASSERT(m_spStream != NULL);
  247. HRESULT const hr = m_spStream->Stat(pstatstg, grfStatFlag);
  248. CallHome(SUCCEEDED(hr) ? L"Stat" : L"Stat(failed!)");
  249. return hr;
  250. }
  251. STDMETHOD(Clone)(IStream** ppstm)
  252. {
  253. ASSERT(m_spStream != NULL);
  254. HRESULT const hr = m_spStream->Clone(ppstm);
  255. CallHome(SUCCEEDED(hr) ? L"Clone" : L"Clone(failed!)");
  256. return hr;
  257. }
  258. protected:
  259. virtual const wchar_t* GetInterfaceName() const
  260. {
  261. return L"DebugStream";
  262. }
  263. private:
  264. IStreamPtr m_spStream;
  265. }; // class DebugStream
  266. class __declspec(uuid("B6E77CAC-A0AC-11d0-8F59-00A0C91ED3C8")) DebugStorage :
  267. public IStorage, public CComObjectRoot, public ProxyReporter
  268. {
  269. public:
  270. DebugStorage()
  271. {
  272. }
  273. virtual ~DebugStorage()
  274. {
  275. ASSERT(m_spStorage != NULL);
  276. CallHome(L"~DebugStorage, elements:");
  277. DumpStorage(m_spStorage);
  278. }
  279. void InitDebugStorage(IStorage* pStorage)
  280. {
  281. ASSERT(m_spStorage == NULL);
  282. ASSERT(pStorage != NULL);
  283. m_spStorage = pStorage;
  284. }
  285. BEGIN_COM_MAP(DebugStorage)
  286. COM_INTERFACE_ENTRY_IID(__uuidof(DebugStorage), DebugStorage)
  287. COM_INTERFACE_ENTRY_IID(__uuidof(IStorage), IStorage)
  288. END_COM_MAP()
  289. DECLARE_NOT_AGGREGATABLE(DebugStorage)
  290. // IStorage
  291. public:
  292. STDMETHOD(CreateStream)(const OLECHAR *pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStream** ppstm)
  293. {
  294. ASSERT(m_spStorage != NULL);
  295. HRESULT const hr = m_spStorage->CreateStream(pwcsName, grfMode, reserved1, reserved2, ppstm);
  296. CallHomeAndDump(SUCCEEDED(hr) ? L"CreateStream" : L"CreateStream(failed!)");
  297. return hr;
  298. }
  299. STDMETHOD(OpenStream)(const OLECHAR *pwcsName, void *reserved1, DWORD grfMode, DWORD reserved2, IStream** ppstm)
  300. {
  301. ASSERT(m_spStorage != NULL);
  302. HRESULT const hr = m_spStorage->OpenStream(pwcsName, reserved1, grfMode, reserved2, ppstm);
  303. CallHomeAndDump(SUCCEEDED(hr) ? L"OpenStream" : L"OpenStream(failed!)");
  304. return hr;
  305. }
  306. STDMETHOD(CreateStorage)(const OLECHAR *pwcsName, DWORD grfMode, DWORD reserved1, DWORD reserved2, IStorage** ppstg)
  307. {
  308. ASSERT(m_spStorage != NULL);
  309. HRESULT const hr = m_spStorage->CreateStorage(pwcsName, grfMode, reserved1, reserved2, ppstg);
  310. CallHomeAndDump(SUCCEEDED(hr) ? L"CreateStorage" : L"CreateStorage(failed!)");
  311. return hr;
  312. }
  313. STDMETHOD(OpenStorage)(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage** ppstg)
  314. {
  315. ASSERT(m_spStorage != NULL);
  316. HRESULT const hr = m_spStorage->OpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, ppstg);
  317. CallHomeAndDump(SUCCEEDED(hr) ? L"OpenStorage, elements:" : L"OpenStorage(failed!)");
  318. return hr;
  319. }
  320. STDMETHOD(CopyTo)(DWORD ciidExclude, const IID *rgiidExclude, SNB snbExclude, IStorage *pstgDest)
  321. {
  322. ASSERT(m_spStorage != NULL);
  323. HRESULT const hr = m_spStorage->CopyTo(ciidExclude, rgiidExclude, snbExclude, pstgDest);
  324. CallHomeAndDump(SUCCEEDED(hr) ? L"CopyTo" : L"CopyTo(failed!)");
  325. return hr;
  326. }
  327. STDMETHOD(MoveElementTo)(const OLECHAR *pwcsName, IStorage *pstgDest, const OLECHAR *pwcsNewName, DWORD grfFlags)
  328. {
  329. ASSERT(m_spStorage != NULL);
  330. HRESULT const hr = m_spStorage->MoveElementTo(pwcsName, pstgDest, pwcsNewName, grfFlags);
  331. CallHomeAndDump(SUCCEEDED(hr) ? L"MoveElementTo" : L"MoveElementTo(failed!)");
  332. return hr;
  333. }
  334. STDMETHOD(Commit)(DWORD grfCommitFlags)
  335. {
  336. ASSERT(m_spStorage != NULL);
  337. HRESULT const hr = m_spStorage->Commit(grfCommitFlags);
  338. CallHomeAndDump(SUCCEEDED(hr) ? L"Commit" : L"Commit(failed!)");
  339. return hr;
  340. }
  341. STDMETHOD(Revert)()
  342. {
  343. ASSERT(m_spStorage != NULL);
  344. HRESULT const hr = m_spStorage->Revert();
  345. CallHomeAndDump(SUCCEEDED(hr) ? L"Revert" : L"Revert(failed!)");
  346. return hr;
  347. }
  348. STDMETHOD(EnumElements)(DWORD reserved1, void *reserved2, DWORD reserved3, IEnumSTATSTG** ppenum)
  349. {
  350. ASSERT(m_spStorage != NULL);
  351. HRESULT const hr = m_spStorage->EnumElements(reserved1, reserved2, reserved3, ppenum);
  352. CallHomeAndDump(SUCCEEDED(hr) ? L"EnumElements" : L"EnumElements(failed!)");
  353. return hr;
  354. }
  355. STDMETHOD(DestroyElement)(const OLECHAR* pwcsName)
  356. {
  357. ASSERT(m_spStorage != NULL);
  358. HRESULT const hr = m_spStorage->DestroyElement(pwcsName);
  359. CallHomeAndDump(SUCCEEDED(hr) ? L"DestroyElement" : L"DestroyElement(failed!)");
  360. return hr;
  361. }
  362. STDMETHOD(RenameElement)(const OLECHAR *pwcsOldName, const OLECHAR *pwcsNewName)
  363. {
  364. ASSERT(m_spStorage != NULL);
  365. HRESULT const hr = m_spStorage->RenameElement(pwcsOldName, pwcsNewName);
  366. CallHomeAndDump(SUCCEEDED(hr) ? L"RenameElement" : L"RenameElement(failed!)");
  367. return hr;
  368. }
  369. STDMETHOD(SetElementTimes)(const OLECHAR *pwcsName, const FILETIME *pctime, const FILETIME *patime, const FILETIME *pmtime)
  370. {
  371. ASSERT(m_spStorage != NULL);
  372. HRESULT const hr = m_spStorage->SetElementTimes(pwcsName, pctime, patime, pmtime);
  373. CallHomeAndDump(SUCCEEDED(hr) ? L"SetElementTimes" : L"SetElementTimes(failed!)");
  374. return hr;
  375. }
  376. STDMETHOD(SetClass)(REFCLSID clsid)
  377. {
  378. ASSERT(m_spStorage != NULL);
  379. HRESULT const hr = m_spStorage->SetClass(clsid);
  380. CallHomeAndDump(SUCCEEDED(hr) ? L"SetClass" : L"SetClass(failed!)");
  381. return hr;
  382. }
  383. STDMETHOD(SetStateBits)(DWORD grfStateBits, DWORD grfMask)
  384. {
  385. ASSERT(m_spStorage != NULL);
  386. HRESULT const hr = m_spStorage->SetStateBits(grfStateBits, grfMask);
  387. CallHomeAndDump(SUCCEEDED(hr) ? L"SetStateBits" : L"SetStateBits(failed!)");
  388. return hr;
  389. }
  390. STDMETHOD(Stat)(STATSTG *pstatstg, DWORD grfStatFlag)
  391. {
  392. ASSERT(m_spStorage != NULL);
  393. HRESULT const hr = m_spStorage->Stat(pstatstg, grfStatFlag);
  394. CallHomeAndDump(SUCCEEDED(hr) ? L"Stat" : L"Stat(failed!)");
  395. return hr;
  396. }
  397. // ProxyReporter
  398. protected:
  399. virtual const wchar_t* GetInterfaceName() const
  400. {
  401. return L"DebugStorage";
  402. }
  403. private:
  404. IStoragePtr m_spStorage;
  405. void CallHomeAndDump(const wchar_t* from) const
  406. {
  407. CallHome(from);
  408. DumpStorage(m_spStorage);
  409. }
  410. }; // class DebugStorage
  411. #endif // COMDBG
  412. /*+-------------------------------------------------------------------------*
  413. * CreateDebugStream
  414. *
  415. * Wrapper on IStorage::CreateStream
  416. *--------------------------------------------------------------------------*/
  417. inline HRESULT CreateDebugStream(IStorage* pStorage, const wchar_t* name, DWORD grfMode, const wchar_t* instanceName, IStream** ppStream)
  418. {
  419. ASSERT(pStorage != NULL);
  420. ASSERT(name != NULL);
  421. ASSERT(ppStream != NULL);
  422. ASSERT(instanceName != NULL);
  423. #ifndef COMDBG
  424. HRESULT hr = pStorage->CreateStream(name, grfMode, NULL, NULL, ppStream);
  425. return hr;
  426. #else // COMDBG
  427. IStreamPtr spStream;
  428. HRESULT hr = pStorage->CreateStream(name, grfMode, NULL, NULL, &spStream);
  429. ASSERT(SUCCEEDED(hr) && spStream != NULL);
  430. if (FAILED(hr))
  431. return (hr);
  432. typedef CComObject<ATLProxyReporter<DebugStream> > ProxyStreamObject;
  433. ProxyStreamObject* pObject;
  434. hr = ProxyStreamObject::CreateInstance(&pObject);
  435. ASSERT(SUCCEEDED(hr));
  436. if (FAILED(hr))
  437. return E_FAIL;
  438. pObject->InitATLProxyReporter(instanceName);
  439. pObject->InitDebugStream(spStream);
  440. hr = pObject->QueryInterface(IID_IStream, reinterpret_cast<void**>(ppStream));
  441. ASSERT(SUCCEEDED(hr));
  442. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  443. #endif // COMDBG
  444. }
  445. inline HRESULT CreateDebugStream(IStorage* pStorage, const wchar_t* name, DWORD grfMode, IStream** ppStream)
  446. {
  447. return (CreateDebugStream (pStorage, name, grfMode, name, ppStream));
  448. }
  449. /*+-------------------------------------------------------------------------*
  450. * OpenDebugStream
  451. *
  452. * Wrapper on IStorage::OpenStream
  453. *--------------------------------------------------------------------------*/
  454. inline HRESULT OpenDebugStream(IStorage* pStorage, const wchar_t* name, DWORD grfMode, const wchar_t* instanceName, IStream** ppStream)
  455. {
  456. ASSERT(pStorage != NULL);
  457. ASSERT(name != NULL);
  458. ASSERT(ppStream != NULL);
  459. ASSERT(instanceName != NULL);
  460. #ifndef COMDBG
  461. HRESULT hr = pStorage->OpenStream(name, NULL, grfMode, NULL, ppStream);
  462. return hr;
  463. #else // COMDBG
  464. IStreamPtr spStream;
  465. HRESULT hr = pStorage->OpenStream(name, NULL, grfMode, NULL, &spStream);
  466. if (FAILED(hr))
  467. return (hr);
  468. typedef CComObject<ATLProxyReporter<DebugStream> > ProxyStreamObject;
  469. ProxyStreamObject* pObject;
  470. hr = ProxyStreamObject::CreateInstance(&pObject);
  471. ASSERT(SUCCEEDED(hr));
  472. if (FAILED(hr))
  473. return E_FAIL;
  474. pObject->InitATLProxyReporter(instanceName);
  475. pObject->InitDebugStream(spStream);
  476. hr = pObject->QueryInterface(IID_IStream, reinterpret_cast<void**>(ppStream));
  477. ASSERT(SUCCEEDED(hr));
  478. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  479. #endif // COMDBG
  480. }
  481. inline HRESULT OpenDebugStream(IStorage* pStorage, const wchar_t* name, DWORD grfMode, IStream** ppStream)
  482. {
  483. return (OpenDebugStream (pStorage, name, grfMode, name, ppStream));
  484. }
  485. /*+-------------------------------------------------------------------------*
  486. * CreateDebugStorage
  487. *
  488. * Wrapper on IStorage::CreateStorage
  489. *--------------------------------------------------------------------------*/
  490. inline HRESULT CreateDebugStorage(IStorage* pStorage, const wchar_t* name, DWORD grfMode, const wchar_t* instanceName, IStorage** ppStorage)
  491. {
  492. ASSERT(pStorage != NULL);
  493. ASSERT(name != NULL);
  494. ASSERT(ppStorage != NULL);
  495. ASSERT(instanceName != NULL);
  496. #ifndef COMDBG
  497. HRESULT hr = pStorage->CreateStorage(name, grfMode, NULL, NULL, ppStorage);
  498. return hr;
  499. #else // COMDBG
  500. IStoragePtr spStorage;
  501. HRESULT hr = pStorage->CreateStorage(name, grfMode, NULL, NULL, &spStorage);
  502. ASSERT(SUCCEEDED(hr) && spStorage != NULL);
  503. if (FAILED(hr))
  504. return (hr);
  505. typedef CComObject<ATLProxyReporter<DebugStorage> > ProxyStorageObject;
  506. ProxyStorageObject* pObject;
  507. hr = ProxyStorageObject::CreateInstance(&pObject);
  508. ASSERT(SUCCEEDED(hr));
  509. if (FAILED(hr))
  510. return E_FAIL;
  511. pObject->InitATLProxyReporter(instanceName);
  512. pObject->InitDebugStorage(spStorage);
  513. hr = pObject->QueryInterface(IID_IStorage, reinterpret_cast<void**>(ppStorage));
  514. ASSERT(SUCCEEDED(hr));
  515. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  516. #endif // COMDBG
  517. }
  518. inline HRESULT CreateDebugStorage(IStorage* pStorage, const wchar_t* name, DWORD grfMode, IStorage** ppStorage)
  519. {
  520. return (CreateDebugStorage (pStorage, name, grfMode, name, ppStorage));
  521. }
  522. /*+-------------------------------------------------------------------------*
  523. * CreateDebugDocfile
  524. *
  525. * Wrapper on StgCreateDocfile
  526. *--------------------------------------------------------------------------*/
  527. inline HRESULT CreateDebugDocfile(const wchar_t* name, DWORD grfMode, const wchar_t* instanceName, IStorage** ppStorage)
  528. {
  529. ASSERT(ppStorage != NULL);
  530. #ifndef COMDBG
  531. HRESULT hr = StgCreateDocfile(name, grfMode, NULL, ppStorage);
  532. return hr;
  533. #else // COMDBG
  534. IStoragePtr spStorage;
  535. HRESULT hr = StgCreateDocfile(name, grfMode, NULL, &spStorage);
  536. ASSERT(SUCCEEDED(hr) && spStorage != NULL);
  537. if (FAILED(hr))
  538. return (hr);
  539. typedef CComObject<ATLProxyReporter<DebugStorage> > ProxyStorageObject;
  540. ProxyStorageObject* pObject;
  541. hr = ProxyStorageObject::CreateInstance(&pObject);
  542. ASSERT(SUCCEEDED(hr));
  543. if (FAILED(hr))
  544. return E_FAIL;
  545. pObject->InitATLProxyReporter((instanceName) ? instanceName : L"<temporary>");
  546. pObject->InitDebugStorage(spStorage);
  547. hr = pObject->QueryInterface(IID_IStorage, reinterpret_cast<void**>(ppStorage));
  548. ASSERT(SUCCEEDED(hr));
  549. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  550. #endif // COMDBG
  551. }
  552. inline HRESULT CreateDebugDocfile(const wchar_t* name, DWORD grfMode, IStorage** ppStorage)
  553. {
  554. return (CreateDebugDocfile (name, grfMode, name, ppStorage));
  555. }
  556. /*+-------------------------------------------------------------------------*
  557. * OpenDebugStorage
  558. *
  559. * Wrapper on IStorage::OpenStorage
  560. *--------------------------------------------------------------------------*/
  561. inline HRESULT OpenDebugStorage(IStorage* pStorage, const wchar_t* name, DWORD grfMode, const wchar_t* instanceName, IStorage** ppStorage)
  562. {
  563. ASSERT(pStorage != NULL);
  564. ASSERT(name != NULL);
  565. ASSERT(ppStorage != NULL);
  566. ASSERT(instanceName != NULL);
  567. #ifndef COMDBG
  568. HRESULT hr = pStorage->OpenStorage(name, NULL, grfMode, NULL, NULL, ppStorage);
  569. return hr;
  570. #else // COMDBG
  571. IStoragePtr spStorage;
  572. HRESULT hr = pStorage->OpenStorage(name, NULL, grfMode, NULL, NULL, &spStorage);
  573. if (FAILED(hr))
  574. return (hr);
  575. typedef CComObject<ATLProxyReporter<DebugStorage> > ProxyStorageObject;
  576. ProxyStorageObject* pObject;
  577. hr = ProxyStorageObject::CreateInstance(&pObject);
  578. ASSERT(SUCCEEDED(hr));
  579. if (FAILED(hr))
  580. return E_FAIL;
  581. pObject->InitATLProxyReporter(instanceName);
  582. pObject->InitDebugStorage(spStorage);
  583. hr = pObject->QueryInterface(IID_IStorage, reinterpret_cast<void**>(ppStorage));
  584. ASSERT(SUCCEEDED(hr));
  585. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  586. #endif // COMDBG
  587. }
  588. inline HRESULT OpenDebugStorage(IStorage* pStorage, const wchar_t* name, DWORD grfMode, IStorage** ppStorage)
  589. {
  590. return (OpenDebugStorage (pStorage, name, grfMode, name, ppStorage));
  591. }
  592. /*+-------------------------------------------------------------------------*
  593. * OpenDebugStorage
  594. *
  595. * Wrapper on StgOpenStorage
  596. *--------------------------------------------------------------------------*/
  597. inline HRESULT OpenDebugStorage(const wchar_t* name, DWORD grfMode, const wchar_t* instanceName, IStorage** ppStorage)
  598. {
  599. ASSERT(name != NULL);
  600. ASSERT(ppStorage != NULL);
  601. ASSERT(instanceName != NULL);
  602. #ifndef COMDBG
  603. HRESULT hr = StgOpenStorage(name, NULL, grfMode, NULL, NULL, ppStorage);
  604. return hr;
  605. #else // COMDBG
  606. IStoragePtr spStorage;
  607. HRESULT hr = StgOpenStorage(name, NULL, grfMode, NULL, NULL, &spStorage);
  608. if (FAILED(hr))
  609. return (hr);
  610. typedef CComObject<ATLProxyReporter<DebugStorage> > ProxyStorageObject;
  611. ProxyStorageObject* pObject;
  612. hr = ProxyStorageObject::CreateInstance(&pObject);
  613. ASSERT(SUCCEEDED(hr));
  614. if (FAILED(hr))
  615. return E_FAIL;
  616. pObject->InitATLProxyReporter(instanceName);
  617. pObject->InitDebugStorage(spStorage);
  618. hr = pObject->QueryInterface(IID_IStorage, reinterpret_cast<void**>(ppStorage));
  619. ASSERT(SUCCEEDED(hr));
  620. return SUCCEEDED(hr) ? S_OK : E_FAIL;
  621. #endif // COMDBG
  622. }
  623. inline HRESULT OpenDebugStorage(const wchar_t* name, DWORD grfMode, IStorage** ppStorage)
  624. {
  625. return (OpenDebugStorage (name, grfMode, name, ppStorage));
  626. }
  627. #endif // COMDBG_H