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.

595 lines
15 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: wrap.cxx
  7. //
  8. // Contents: Wrapper implementations
  9. //
  10. //---------------------------------------------------------------
  11. #include "headers.cxx"
  12. // Retrieve interface pointer for possibly NULL objects
  13. #define SAFEI(obj) ((obj) ? (obj)->GetI() : NULL)
  14. //+--------------------------------------------------------------
  15. //
  16. // IStorage wrappers
  17. //
  18. //---------------------------------------------------------------
  19. WStorage *WStorage::Wrap(IStorage *pistg)
  20. {
  21. WStorage *wstg;
  22. wstg = new WStorage(pistg);
  23. if (wstg == NULL)
  24. error(EXIT_OOM, "Unable to wrap IStorage\n");
  25. return wstg;
  26. }
  27. WStorage::WStorage(IStorage *pstg)
  28. {
  29. // Note: takes ownership of pstg
  30. _pstg = pstg;
  31. }
  32. WStorage::~WStorage(void)
  33. {
  34. if (_pstg)
  35. Release();
  36. }
  37. void WStorage::Unwrap(void)
  38. {
  39. delete this;
  40. }
  41. HRESULT WStorage::QueryInterface(REFIID riid, void **ppvObj)
  42. {
  43. out("IStorage %p::QueryInterface(riid, %p)", _pstg, ppvObj);
  44. return Result(_pstg->QueryInterface(riid, ppvObj));
  45. }
  46. ULONG WStorage::AddRef(void)
  47. {
  48. ULONG ul;
  49. ul = _pstg->AddRef();
  50. out("IStorage %p::AddRef() - %lu\n", _pstg, ul);
  51. return ul;
  52. }
  53. ULONG WStorage::Release(void)
  54. {
  55. ULONG ul;
  56. ul = _pstg->Release();
  57. out("IStorage %p::Release() - %lu\n", _pstg, ul);
  58. if (ul == 0)
  59. _pstg = NULL;
  60. return ul;
  61. }
  62. HRESULT WStorage::CreateStream(const OLECHAR * pwcsName,
  63. const DWORD grfMode,
  64. DWORD reserved1,
  65. DWORD reserved2,
  66. WStream **ppstm)
  67. {
  68. HRESULT hr;
  69. IStream *pistm;
  70. out("IStorage %p::CreateStream(%s, 0x%lX, %lu, %lu, %p)", _pstg,
  71. OlecsOut(pwcsName), grfMode, reserved1, reserved2, ppstm);
  72. hr = Result(_pstg->CreateStream(pwcsName, grfMode, reserved1,
  73. reserved2, &pistm));
  74. *ppstm = WStream::Wrap(pistm);
  75. return hr;
  76. }
  77. HRESULT WStorage::OpenStream(const OLECHAR * pwcsName,
  78. void *reserved1,
  79. const DWORD grfMode,
  80. DWORD reserved2,
  81. WStream **ppstm)
  82. {
  83. HRESULT hr;
  84. IStream *pistm;
  85. out("IStorage %p::OpenStream(%s, %p, 0x%lX, %lu, %p)", _pstg,
  86. OlecsOut(pwcsName), reserved1, grfMode, reserved2, ppstm);
  87. hr = Result(_pstg->OpenStream(pwcsName, reserved1, grfMode,
  88. reserved2, &pistm));
  89. *ppstm = WStream::Wrap(pistm);
  90. return hr;
  91. }
  92. HRESULT WStorage::CreateStorage(const OLECHAR * pwcsName,
  93. const DWORD grfMode,
  94. DWORD reserved1,
  95. DWORD reserved2,
  96. WStorage **ppstg)
  97. {
  98. HRESULT hr;
  99. IStorage *pistg;
  100. out("IStorage %p::CreateStorage(%s, 0x%lX, %lu, %lu, %p)", _pstg,
  101. OlecsOut(pwcsName), grfMode, reserved1, reserved2, ppstg);
  102. hr = Result(_pstg->CreateStorage(pwcsName, grfMode, reserved1,
  103. reserved2, &pistg));
  104. *ppstg = WStorage::Wrap(pistg);
  105. return hr;
  106. }
  107. HRESULT WStorage::OpenStorage(const OLECHAR * pwcsName,
  108. WStorage *pstgPriority,
  109. const DWORD grfMode,
  110. SNB snbExclude,
  111. DWORD reserved,
  112. WStorage **ppstg)
  113. {
  114. HRESULT hr;
  115. IStorage *pistg;
  116. out("IStorage %p::OpenStorage(%s, %p, 0x%lX, %p, %lu, %p)", _pstg,
  117. OlecsOut(pwcsName), SAFEI(pstgPriority), grfMode,
  118. snbExclude, reserved, ppstg);
  119. hr = Result(_pstg->OpenStorage(pwcsName, (IStorage*) SAFEI(pstgPriority),
  120. grfMode, snbExclude,
  121. reserved, &pistg));
  122. *ppstg = WStorage::Wrap(pistg);
  123. return hr;
  124. }
  125. HRESULT WStorage::CopyTo(DWORD ciidExclude,
  126. IID *rgiidExclude,
  127. SNB snbExclude,
  128. WStorage *pstgDest)
  129. {
  130. out("IStorage %p::CopyTo(%lu, %p, %p, %p)", _pstg, ciidExclude,
  131. rgiidExclude, snbExclude, pstgDest->GetI());
  132. return Result(_pstg->CopyTo(ciidExclude, rgiidExclude, snbExclude,
  133. pstgDest->GetI()));
  134. }
  135. HRESULT WStorage::MoveElementTo(OLECHAR const FAR* lpszName,
  136. WStorage FAR *pstgDest,
  137. OLECHAR const FAR* lpszNewName,
  138. DWORD grfFlags)
  139. {
  140. out("IStorage %p::MoveElementTo(%p, %p, %p, %lu)", _pstg, lpszName,
  141. pstgDest->GetI(), lpszNewName, grfFlags);
  142. return Result(_pstg->MoveElementTo(lpszName, pstgDest->GetI(),
  143. lpszNewName, grfFlags));
  144. }
  145. HRESULT WStorage::Commit(const DWORD grfCommitFlags)
  146. {
  147. out("IStorage %p::Commit(0x%lX)", _pstg, grfCommitFlags);
  148. return Result(_pstg->Commit(grfCommitFlags));
  149. }
  150. HRESULT WStorage::Revert(void)
  151. {
  152. out("IStorage %p::Revert()", _pstg);
  153. return Result(_pstg->Revert());
  154. }
  155. HRESULT WStorage::EnumElements(DWORD reserved1,
  156. void *reserved2,
  157. DWORD reserved3,
  158. WEnumSTATSTG **ppenm)
  159. {
  160. HRESULT hr;
  161. IEnumSTATSTG *pienm;
  162. out("IStorage %p::EnumElements(%lu, %p, %lu, %p)", _pstg,
  163. reserved1, reserved2, reserved3, ppenm);
  164. hr = Result(_pstg->EnumElements(reserved1, reserved2, reserved3, &pienm));
  165. *ppenm = WEnumSTATSTG::Wrap(pienm);
  166. return hr;
  167. }
  168. HRESULT WStorage::DestroyElement(const OLECHAR * pwcsName)
  169. {
  170. out("IStorage %p::DestroyElement(%s)", _pstg, OlecsOut(pwcsName));
  171. return Result(_pstg->DestroyElement(pwcsName));
  172. }
  173. HRESULT WStorage::RenameElement(const OLECHAR * pwcsOldName,
  174. const OLECHAR * pwcsNewName)
  175. {
  176. out("IStorage %p::RenameElement(%s, %s)", _pstg, OlecsOut(pwcsOldName),
  177. OlecsOut(pwcsNewName));
  178. return Result(_pstg->RenameElement(pwcsOldName, pwcsNewName));
  179. }
  180. HRESULT WStorage::SetElementTimes(const OLECHAR *lpszName,
  181. FILETIME const *pctime,
  182. FILETIME const *patime,
  183. FILETIME const *pmtime)
  184. {
  185. out("IStorage %p::SetElementTimes(%s, %p, %p, %p)", _pstg,
  186. OlecsOut(lpszName), pctime, patime, pmtime);
  187. return Result(_pstg->SetElementTimes(lpszName, pctime, patime, pmtime));
  188. }
  189. HRESULT WStorage::SetClass(REFCLSID clsid)
  190. {
  191. out("IStorage %p::SetClass(%s)", _pstg, GuidText(&clsid));
  192. return Result(_pstg->SetClass(clsid));
  193. }
  194. HRESULT WStorage::SetStateBits(DWORD grfStateBits, DWORD grfMask)
  195. {
  196. out("IStorage %p::SetStateBits(0x%lX, 0x%lX)", _pstg, grfStateBits,
  197. grfMask);
  198. return Result(_pstg->SetStateBits(grfStateBits, grfMask));
  199. }
  200. HRESULT WStorage::Stat(STATSTG *pstatstg, DWORD grfStatFlag)
  201. {
  202. out("IStorage %p::Stat(%p, %lu)", _pstg, pstatstg, grfStatFlag);
  203. return Result(_pstg->Stat(pstatstg, grfStatFlag));
  204. }
  205. //+--------------------------------------------------------------
  206. //
  207. // IStream wrappers
  208. //
  209. //---------------------------------------------------------------
  210. WStream *WStream::Wrap(IStream *pistm)
  211. {
  212. WStream *wstm;
  213. wstm = new WStream(pistm);
  214. if (wstm == NULL)
  215. error(EXIT_OOM, "Unable to wrap IStream\n");
  216. return wstm;
  217. }
  218. WStream::WStream(IStream *pstm)
  219. {
  220. // Note: takes ownership of pstm
  221. _pstm = pstm;
  222. }
  223. WStream::~WStream(void)
  224. {
  225. if (_pstm)
  226. Release();
  227. }
  228. void WStream::Unwrap(void)
  229. {
  230. delete this;
  231. }
  232. HRESULT WStream::QueryInterface(REFIID riid, void **ppvObj)
  233. {
  234. out("IStream %p::QueryInterface(riid, %p)", _pstm, ppvObj);
  235. return Result(_pstm->QueryInterface(riid, ppvObj));
  236. }
  237. ULONG WStream::AddRef(void)
  238. {
  239. ULONG ul;
  240. ul = _pstm->AddRef();
  241. out("IStream %p::AddRef() - %lu\n", _pstm, ul);
  242. return ul;
  243. }
  244. ULONG WStream::Release(void)
  245. {
  246. ULONG ul;
  247. ul = _pstm->Release();
  248. out("IStream %p::Release() - %lu\n", _pstm, ul);
  249. if (ul == 0)
  250. _pstm = NULL;
  251. return ul;
  252. }
  253. HRESULT WStream::Read(VOID *pv, ULONG cb, ULONG *pcbRead)
  254. {
  255. HRESULT hr;
  256. out("IStream %p::Read(%p, %lu, %p)", _pstm, pv, cb, pcbRead);
  257. hr = _pstm->Read(pv, cb, pcbRead);
  258. if (pcbRead)
  259. out(" - %lu bytes", *pcbRead);
  260. Result(hr);
  261. if (pcbRead && *pcbRead != cb && fExitOnFail)
  262. error(EXIT_BADSC, "Couldn't read data\n");
  263. return hr;
  264. }
  265. HRESULT WStream::Write(VOID *pv, ULONG cb, ULONG *pcbWritten)
  266. {
  267. HRESULT hr;
  268. out("IStream %p::Write(%p, %lu, %p)", _pstm, pv, cb, pcbWritten);
  269. hr = _pstm->Write(pv, cb, pcbWritten);
  270. if (pcbWritten)
  271. out(" - %lu bytes", *pcbWritten);
  272. Result(hr);
  273. if (pcbWritten && *pcbWritten != cb && fExitOnFail)
  274. error(EXIT_BADSC, "Couldn't write data\n");
  275. return hr;
  276. }
  277. HRESULT WStream::Seek(LONG dlibMove,
  278. DWORD dwOrigin,
  279. ULONG *plibNewPosition)
  280. {
  281. HRESULT hr;
  282. LARGE_INTEGER dlib;
  283. ULARGE_INTEGER plib;
  284. out("IStream %p::Seek(%ld, %lu, %p)", _pstm, dlibMove, dwOrigin,
  285. plibNewPosition);
  286. LISet32(dlib, dlibMove);
  287. hr = _pstm->Seek(dlib, dwOrigin, &plib);
  288. if (plibNewPosition)
  289. {
  290. *plibNewPosition = ULIGetLow(plib);
  291. out(" - ptr %lu", *plibNewPosition);
  292. }
  293. return Result(hr);
  294. }
  295. HRESULT WStream::SetSize(ULONG libNewSize)
  296. {
  297. ULARGE_INTEGER lib;
  298. out("IStream %p::SetSize(%lu)", _pstm, libNewSize);
  299. ULISet32(lib, libNewSize);
  300. return Result(_pstm->SetSize(lib));
  301. }
  302. HRESULT WStream::Commit(const DWORD dwFlags)
  303. {
  304. out("IStream %p:Commit(%lu)", _pstm, dwFlags);
  305. return Result(_pstm->Commit(dwFlags));
  306. }
  307. HRESULT WStream::CopyTo(WStream *pstm,
  308. ULONG cb,
  309. ULONG *pcbRead,
  310. ULONG *pcbWritten)
  311. {
  312. ULARGE_INTEGER lcb, pcbr, pcbw;
  313. HRESULT hr;
  314. out("IStream %p::CopyTo(%p, %lu, %p, %p)", _pstm, pstm->GetI(), cb,
  315. pcbRead, pcbWritten);
  316. ULISet32(lcb, cb);
  317. hr = Result(_pstm->CopyTo(pstm->GetI(), lcb, &pcbr, &pcbw));
  318. if (pcbRead)
  319. *pcbRead = ULIGetLow(pcbr);
  320. if (pcbWritten)
  321. *pcbWritten = ULIGetLow(pcbw);
  322. return hr;
  323. }
  324. HRESULT WStream::Stat(STATSTG *pstatstg, DWORD grfStatFlag)
  325. {
  326. out("IStream %p::Stat(%p, %lu)", _pstm, pstatstg, grfStatFlag);
  327. return Result(_pstm->Stat(pstatstg, grfStatFlag));
  328. }
  329. HRESULT WStream::Clone(WStream * *ppstm)
  330. {
  331. HRESULT hr;
  332. IStream *pistm;
  333. out("IStream %p::Clone(%p)", _pstm, ppstm);
  334. hr = Result(_pstm->Clone(&pistm));
  335. *ppstm = WStream::Wrap(pistm);
  336. return hr;
  337. }
  338. //+--------------------------------------------------------------
  339. //
  340. // IEnumSTATSTG wrappers
  341. //
  342. //---------------------------------------------------------------
  343. WEnumSTATSTG *WEnumSTATSTG::Wrap(IEnumSTATSTG *pienm)
  344. {
  345. WEnumSTATSTG *wenm;
  346. wenm = new WEnumSTATSTG(pienm);
  347. if (wenm == NULL)
  348. error(EXIT_OOM, "Unable to wrap IEnumSTATSTG\n");
  349. return wenm;
  350. }
  351. WEnumSTATSTG::WEnumSTATSTG(IEnumSTATSTG *penm)
  352. {
  353. // Note: takes ownership of penm
  354. _penm = penm;
  355. }
  356. WEnumSTATSTG::~WEnumSTATSTG(void)
  357. {
  358. if (_penm)
  359. Release();
  360. }
  361. void WEnumSTATSTG::Unwrap(void)
  362. {
  363. delete this;
  364. }
  365. HRESULT WEnumSTATSTG::QueryInterface(REFIID riid, void **ppvObj)
  366. {
  367. out("IEnumSTATSTG %p::QueryInterface(riid, %p)", _penm, ppvObj);
  368. return Result(_penm->QueryInterface(riid, ppvObj));
  369. }
  370. ULONG WEnumSTATSTG::AddRef(void)
  371. {
  372. ULONG ul;
  373. ul = _penm->AddRef();
  374. out("IEnumSTATSTG %p::AddRef() - %lu\n", _penm, ul);
  375. return ul;
  376. }
  377. ULONG WEnumSTATSTG::Release(void)
  378. {
  379. ULONG ul;
  380. ul = _penm->Release();
  381. out("IEnumSTATSTG %p::Release() - %lu\n", _penm, ul);
  382. if (ul == 0)
  383. _penm = NULL;
  384. return ul;
  385. }
  386. HRESULT WEnumSTATSTG::Next(ULONG celt, STATSTG rgelt[], ULONG *pceltFetched)
  387. {
  388. out("IEnumSTATSTG %p::Next(%lu, rgelt, %p)", _penm, celt, pceltFetched);
  389. return Result(_penm->Next(celt, rgelt, pceltFetched));
  390. }
  391. HRESULT WEnumSTATSTG::Skip(ULONG celt)
  392. {
  393. out("IEnumSTATSTG %p::Skip(%lu)", _penm, celt);
  394. return Result(_penm->Skip(celt));
  395. }
  396. HRESULT WEnumSTATSTG::Reset(void)
  397. {
  398. out("IEnumSTATSTG %p::Reset()", _penm);
  399. return Result(_penm->Reset());
  400. }
  401. HRESULT WEnumSTATSTG::Clone(WEnumSTATSTG **ppenm)
  402. {
  403. HRESULT hr;
  404. IEnumSTATSTG *pienm;
  405. out("IEnumSTATSTG %p::Clone(%p)", _penm, ppenm);
  406. hr = Result(_penm->Clone(&pienm));
  407. *ppenm = WEnumSTATSTG::Wrap(pienm);
  408. return hr;
  409. }
  410. //+--------------------------------------------------------------
  411. //
  412. // Root level wrappers
  413. //
  414. //---------------------------------------------------------------
  415. HRESULT WStgCreateDocfile(const OLECHAR * pwcsName,
  416. const DWORD grfMode,
  417. DWORD reserved,
  418. WStorage * *ppstgOpen)
  419. {
  420. HRESULT hr;
  421. IStorage *pistg;
  422. #define LARGE_SECTORS
  423. #ifndef LARGE_SECTORS
  424. if (pwcsName)
  425. {
  426. out("StgCreateDocfile(%s, 0x%lX, %lu, %p)",
  427. OlecsOut(pwcsName), grfMode, reserved, ppstgOpen);
  428. }
  429. hr = Result(StgCreateDocfile(pwcsName, grfMode,
  430. reserved, &pistg));
  431. #else
  432. out("StgCreateStorageEx(%s, 0x%lX, %lu, %p)", OlecsOut(pwcsName), grfMode,
  433. reserved, ppstgOpen);
  434. STGOPTIONS stgoptions;
  435. stgoptions.usVersion = STGOPTIONS_VERSION;
  436. stgoptions.reserved = 0;
  437. stgoptions.ulSectorSize = 4096;
  438. stgoptions.pwcsTemplateFile = NULL;
  439. hr = Result(StgCreateStorageEx ( pwcsName, grfMode,
  440. STGFMT_DOCFILE,
  441. 0, &stgoptions,
  442. 0, IID_IStorage, (void **) &pistg));
  443. #endif
  444. *ppstgOpen = WStorage::Wrap(pistg);
  445. return hr;
  446. }
  447. HRESULT WStgCreateDocfileOnILockBytes(ILockBytes *plkbyt,
  448. const DWORD grfMode,
  449. DWORD reserved,
  450. WStorage * *ppstgOpen)
  451. {
  452. HRESULT hr;
  453. IStorage *pistg;
  454. out("StgCreateDocfileOnILockBytes(%p, 0x%lX, %lu, %p)",
  455. plkbyt, grfMode, reserved, ppstgOpen);
  456. hr = Result(StgCreateDocfileOnILockBytes(plkbyt, grfMode,
  457. reserved, &pistg));
  458. *ppstgOpen = WStorage::Wrap(pistg);
  459. return hr;
  460. }
  461. HRESULT WStgOpenStorage(const OLECHAR * pwcsName,
  462. WStorage *pstgPriority,
  463. const DWORD grfMode,
  464. SNB snbExclude,
  465. DWORD reserved,
  466. WStorage * *ppstgOpen)
  467. {
  468. HRESULT hr;
  469. IStorage *pistg;
  470. out("StgOpenStorage(%s, %p, 0x%lX, %p, %lu, %p)", OlecsOut(pwcsName),
  471. SAFEI(pstgPriority), grfMode, snbExclude, reserved, ppstgOpen);
  472. hr = Result(StgOpenStorage(pwcsName, (IStorage*)SAFEI(pstgPriority), grfMode,
  473. snbExclude,
  474. reserved, &pistg));
  475. *ppstgOpen = WStorage::Wrap(pistg);
  476. return hr;
  477. }
  478. HRESULT WStgOpenStorageOnILockBytes(ILockBytes *plkbyt,
  479. WStorage *pstgPriority,
  480. const DWORD grfMode,
  481. SNB snbExclude,
  482. DWORD reserved,
  483. WStorage * *ppstgOpen)
  484. {
  485. HRESULT hr;
  486. IStorage *pistg;
  487. out("StgOpenStorageOnILockBytes(%p, %p, 0x%lX, %p, %lu, %p)",
  488. plkbyt, SAFEI(pstgPriority), grfMode, snbExclude, reserved,
  489. ppstgOpen);
  490. hr = Result(StgOpenStorageOnILockBytes(plkbyt, (IStorage*)SAFEI(pstgPriority),
  491. grfMode, snbExclude, reserved,
  492. &pistg));
  493. *ppstgOpen = WStorage::Wrap(pistg);
  494. return hr;
  495. }
  496. HRESULT WStgIsStorageFile(const OLECHAR * pwcsName)
  497. {
  498. out("StgIsStorageFile(%s)", OlecsOut(pwcsName));
  499. return Result(StgIsStorageFile(pwcsName));
  500. }
  501. HRESULT WStgIsStorageILockBytes(ILockBytes * plkbyt)
  502. {
  503. out("StgIsStorageILockBytes(%p)", plkbyt);
  504. return Result(StgIsStorageILockBytes(plkbyt));
  505. }