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.

521 lines
16 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1993.
  5. //
  6. // File: dfunmfct.cxx
  7. //
  8. // Contents: Implementation of CDocfileUnmarshalFactory
  9. //
  10. // History: 25-Jan-93 DrewB Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <exphead.cxx>
  14. #pragma hdrstop
  15. #include <dfunmfct.hxx>
  16. #include <marshl.hxx>
  17. #include <logfile.hxx>
  18. #include <expdf.hxx>
  19. #include <expst.hxx>
  20. #if WIN32 >= 300
  21. #include <omarshal.hxx>
  22. #endif
  23. //+--------------------------------------------------------------
  24. //
  25. // Member: CDocfileUnmarshalFactory::new, public
  26. //
  27. // Synopsis: Overloaded allocator
  28. //
  29. // Returns: Memory block for CDocfileUnmarshalFactory instance
  30. //
  31. // History: 25-Jun-93 AlexT Created
  32. //
  33. // Notes: We only need one instance of CDocfileUnmarshalFactory.
  34. // We use a static memory block for that instance (so we
  35. // can share it). We don't use a static object because
  36. // we want to avoid the static construction call when this
  37. // library is loaded.
  38. //
  39. //---------------------------------------------------------------
  40. BYTE abCDocfileUnmarshalFactory[sizeof(CDocfileUnmarshalFactory)];
  41. inline void *CDocfileUnmarshalFactory::operator new(size_t size)
  42. {
  43. olAssert(size == sizeof(CDocfileUnmarshalFactory) &&
  44. aMsg("Class size mismatch"));
  45. return(abCDocfileUnmarshalFactory);
  46. }
  47. //+--------------------------------------------------------------
  48. //
  49. // Member: CDocfileUnmarshalFactory::delete, public
  50. //
  51. // Synopsis: Overloaded deallocator
  52. //
  53. // History: 25-Jun-93 AlexT Created
  54. //
  55. // Notes: Should never be called
  56. //
  57. //---------------------------------------------------------------
  58. void CDocfileUnmarshalFactory::operator delete(void *pv)
  59. {
  60. olAssert(!aMsg("CDocfileUnmarshalFactory::operator delete called!"));
  61. }
  62. //+---------------------------------------------------------------------------
  63. //
  64. // Function: DllGetClassObject, public
  65. //
  66. // Synopsis: Returns class factory objects for CLSID_DfMarshal
  67. //
  68. // Arguments: [clsid] - Class ID of object to get
  69. // [riid] - IID of interface to get
  70. // [ppv] - Object return
  71. //
  72. // Returns: Appropriate status code
  73. //
  74. // Modifies: [ppv]
  75. //
  76. // History: 26-Jan-93 DrewB Created
  77. //
  78. //----------------------------------------------------------------------------
  79. #ifdef WIN32
  80. HRESULT Storage32DllGetClassObject(REFCLSID clsid, REFIID riid, void **ppv)
  81. #else
  82. STDAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void FAR* FAR* ppv)
  83. #endif // WIN32
  84. {
  85. SCODE sc;
  86. olDebugOut((DEB_TRACE, "In DllGetClassObject(clsid, riid, %p)\n", ppv));
  87. TRY
  88. {
  89. olChk(ValidatePtrBuffer(ppv));
  90. *ppv = NULL;
  91. olChk(ValidateIid(riid));
  92. #if WIN32 >= 300
  93. if (IsEqualCLSID(clsid, CLSID_NtHandleMarshal))
  94. {
  95. if (!IsEqualIID(riid, IID_IUnknown) &&
  96. !IsEqualIID(riid, IID_IClassFactory))
  97. olErr(EH_Err, E_NOINTERFACE);
  98. *ppv = (IClassFactory *) &sCNtHandleUnmarshalFactory;
  99. }
  100. else
  101. #endif
  102. if (IsEqualCLSID(clsid, CLSID_DfMarshal))
  103. {
  104. if (!IsEqualIID(riid, IID_IUnknown) &&
  105. !IsEqualIID(riid, IID_IClassFactory))
  106. olErr(EH_Err, E_NOINTERFACE);
  107. // Multiple inits don't hurt
  108. *ppv = (IClassFactory *)new CDocfileUnmarshalFactory;
  109. olAssert(*ppv != NULL && aMsg("new CDocfileUnmarshalFactory failed!"));
  110. }
  111. else
  112. olErr(EH_Err, STG_E_INVALIDPARAMETER);
  113. }
  114. CATCH(CException, e)
  115. {
  116. sc = e.GetErrorCode();
  117. }
  118. END_CATCH
  119. olDebugOut((DEB_TRACE, "Out DllGetClassObject => %p\n", *ppv));
  120. EH_Err:
  121. return ResultFromScode(sc);
  122. }
  123. //+--------------------------------------------------------------
  124. //
  125. // Member: CDocfileUnmarshalFactory::AddRef, public
  126. //
  127. // Synopsis: Increments the ref count
  128. //
  129. // Returns: Appropriate status code
  130. //
  131. // History: 25-Jan-93 DrewB Created
  132. //
  133. //---------------------------------------------------------------
  134. STDMETHODIMP_(ULONG) CDocfileUnmarshalFactory::AddRef(void)
  135. {
  136. LONG lRet;
  137. olLog(("%p::In CDocfileUnmarshalFactory::AddRef()\n", this));
  138. olDebugOut((DEB_TRACE, "In CDocfileUnmarshalFactory::AddRef:%p()\n",
  139. this));
  140. lRet = _AddRef();
  141. olDebugOut((DEB_TRACE, "Out CDocfileUnmarshalFactory::AddRef => %ld\n",
  142. lRet));
  143. olLog(("%p::Out CDocfileUnmarshalFactory::AddRef(). ret == %ld\n",
  144. this, lRet));
  145. return lRet;
  146. }
  147. //+--------------------------------------------------------------
  148. //
  149. // Member: CDocfileUnmarshalFactory::Release, public
  150. //
  151. // Synopsis: Releases resources
  152. //
  153. // Returns: Appropriate status code
  154. //
  155. // History: 25-Jan-93 DrewB Created
  156. //
  157. //---------------------------------------------------------------
  158. STDMETHODIMP_(ULONG) CDocfileUnmarshalFactory::Release(void)
  159. {
  160. LONG lRet;
  161. olLog(("%p::In CDocfileUnmarshalFactory::Release()\n", this));
  162. olDebugOut((DEB_TRACE, "In CDocfileUnmarshalFactory::Release:%p()\n",
  163. this));
  164. lRet = 0;
  165. olDebugOut((DEB_TRACE, "Out CDocfileUnmarshalFactory::Release => %ld\n",
  166. lRet));
  167. olLog(("%p::Out CDocfileUnmarshalFactory::Release(). ret == %ld\n",
  168. this, lRet));
  169. return lRet;
  170. }
  171. //+--------------------------------------------------------------
  172. //
  173. // Member: CDocfileUnmarshalFactory::QueryInterface, public
  174. //
  175. // Synopsis: Returns an object for the requested interface
  176. //
  177. // Arguments: [iid] - Interface ID
  178. // [ppv] - Object return
  179. //
  180. // Returns: Appropriate status code
  181. //
  182. // Modifies: [ppv]
  183. //
  184. // History: 25-Jan-93 DrewB Created
  185. //
  186. //---------------------------------------------------------------
  187. STDMETHODIMP CDocfileUnmarshalFactory::QueryInterface(REFIID riid,
  188. void **ppv)
  189. {
  190. SCODE sc;
  191. olLog(("%p::In CDocfileUnmarshalFactory::QueryInterface(riid, %p)\n",
  192. this, ppv));
  193. olDebugOut((DEB_TRACE, "In CDocfileUnmarshalFactory::QueryInterface:%p("
  194. "riid, %p)\n", this, ppv));
  195. TRY
  196. {
  197. olChk(Validate());
  198. olChk(ValidateOutPtrBuffer(ppv));
  199. *ppv = NULL;
  200. olChk(ValidateIid(riid));
  201. if (IsEqualIID(riid, IID_IClassFactory) ||
  202. IsEqualIID(riid, IID_IUnknown))
  203. {
  204. _AddRef();
  205. *ppv = (IClassFactory *)this;
  206. }
  207. else if (IsEqualIID(riid, IID_IMarshal))
  208. {
  209. _AddRef();
  210. *ppv = (IMarshal *)this;
  211. }
  212. else
  213. olErr(EH_Err, E_NOINTERFACE);
  214. }
  215. CATCH(CException, e)
  216. {
  217. sc = e.GetErrorCode();
  218. }
  219. END_CATCH
  220. olDebugOut((DEB_TRACE, "Out CDocfileUnmarshalFactory::QueryInterface => "
  221. "%p\n", *ppv));
  222. EH_Err:
  223. olLog(("%p::Out CDocfileUnmarshalFactory::QueryInterface(). "
  224. "*ppv == %p, ret == 0x%lX\n", this, *ppv, sc));
  225. return ResultFromScode(sc);
  226. }
  227. //+--------------------------------------------------------------
  228. //
  229. // Member: CDocfileUnmarshalFactory::GetUnmarshalClass, public
  230. //
  231. // Synopsis: Returns the class ID
  232. //
  233. // Arguments: [riid] - IID of object
  234. // [pv] - Unreferenced
  235. // [dwDestContext] - Unreferenced
  236. // [pvDestContext] - Unreferenced
  237. // [mshlflags] - Unreferenced
  238. // [pcid] - CLSID return
  239. //
  240. // Returns: Appropriate status code
  241. //
  242. // Modifies: [pcid]
  243. //
  244. // History: 25-Jan-93 DrewB Created
  245. //
  246. //---------------------------------------------------------------
  247. STDMETHODIMP CDocfileUnmarshalFactory::GetUnmarshalClass(REFIID riid,
  248. void *pv,
  249. DWORD dwDestContext,
  250. LPVOID pvDestContext,
  251. DWORD mshlflags,
  252. LPCLSID pcid)
  253. {
  254. olLog(("%p::INVALID CALL TO CDocfileUnmarshalFactory::GetUnmarshalClass("
  255. "riid, %p, %lu, %p, %lu, %p)\n", this, pv, dwDestContext,
  256. pvDestContext, mshlflags, pcid));
  257. return ResultFromScode(STG_E_INVALIDFUNCTION);
  258. }
  259. //+--------------------------------------------------------------
  260. //
  261. // Member: CDocfileUnmarshalFactory::GetMarshalSizeMax, public
  262. //
  263. // Synopsis: Returns the size needed for the marshal buffer
  264. //
  265. // Arguments: [iid] - IID of object being marshaled
  266. // [pv] - Unreferenced
  267. // [dwDestContext] - Unreferenced
  268. // [pvDestContext] - Unreferenced
  269. // [mshlflags] - Unreferenced
  270. // [pcbSize] - Size return
  271. //
  272. // Returns: Appropriate status code
  273. //
  274. // Modifies: [pcbSize]
  275. //
  276. // History: 25-Jan-93 DrewB Created
  277. //
  278. //---------------------------------------------------------------
  279. STDMETHODIMP CDocfileUnmarshalFactory::GetMarshalSizeMax(REFIID iid,
  280. void *pv,
  281. DWORD dwDestContext,
  282. LPVOID pvDestContext,
  283. DWORD mshlflags,
  284. LPDWORD pcbSize)
  285. {
  286. olLog(("%p::INVALID CALL TO CDocfileUnmarshalFactory::GetMarshalSizeMax("
  287. "riid, %p, %lu, %p, %lu, %p)\n",
  288. this, pv, dwDestContext, pvDestContext, mshlflags, pcbSize));
  289. return ResultFromScode(STG_E_INVALIDFUNCTION);
  290. }
  291. //+--------------------------------------------------------------
  292. //
  293. // Member: CDocfileUnmarshalFactory::MarshalInterface, public
  294. //
  295. // Synopsis: Marshals a given object
  296. //
  297. // Arguments: [pstStm] - Stream to write marshal data into
  298. // [iid] - Interface to marshal
  299. // [pv] - Unreferenced
  300. // [dwDestContext] - Unreferenced
  301. // [pvDestContext] - Unreferenced
  302. // [mshlflags] - Unreferenced
  303. //
  304. // Returns: Appropriate status code
  305. //
  306. // History: 25-Jan-93 DrewB Created
  307. //
  308. //---------------------------------------------------------------
  309. STDMETHODIMP CDocfileUnmarshalFactory::MarshalInterface(IStream *pstStm,
  310. REFIID iid,
  311. void *pv,
  312. DWORD dwDestContext,
  313. LPVOID pvDestContext,
  314. DWORD mshlflags)
  315. {
  316. olLog(("%p::INVALID CALL TO CDocfileUnmarshalFactory::MarshalInterface("
  317. "%p, riid, %p, %lu, %p, %lu). Context == %lX\n",
  318. this, pstStm, pv, dwDestContext, pvDestContext, mshlflags,
  319. (ULONG)GetCurrentContextId()));
  320. return ResultFromScode(STG_E_INVALIDFUNCTION);
  321. }
  322. //+--------------------------------------------------------------
  323. //
  324. // Member: CDocfileUnmarshalFactory::UnmarshalInterface, public
  325. //
  326. // Synopsis: Calls through to DfUnmarshalInterface
  327. //
  328. // Arguments: [pstStm] - Marshal stream
  329. // [riid] - IID of object to unmarshal
  330. // [ppv] - Object return
  331. //
  332. // Returns: Appropriate status code
  333. //
  334. // Modifies: [ppv]
  335. //
  336. // History: 25-Jan-93 DrewB Created
  337. //
  338. //---------------------------------------------------------------
  339. STDMETHODIMP CDocfileUnmarshalFactory::UnmarshalInterface(IStream *pstStm,
  340. REFIID iid,
  341. void **ppv)
  342. {
  343. return DfUnMarshalInterface(pstStm, iid, TRUE, ppv);
  344. }
  345. //+--------------------------------------------------------------
  346. //
  347. // Member: CDocfileUnmarshalFactory::ReleaseMarshalData, public
  348. //
  349. // Synopsis: Non-functional
  350. //
  351. // Arguments: [pstStm] -
  352. //
  353. // Returns: Appropriate status code
  354. //
  355. // History: 18-Sep-92 DrewB Created
  356. //
  357. //---------------------------------------------------------------
  358. #ifdef WIN32
  359. STDMETHODIMP CDocfileUnmarshalFactory::ReleaseMarshalData(IStream *pstStm)
  360. {
  361. SCODE sc;
  362. IID iid;
  363. DWORD mshlflags;
  364. olLog(("%p::In CDocfileUnmarshalFactory::ReleaseMarshalData(%p)\n",
  365. this, pstStm));
  366. olChk(SkipStdMarshal(pstStm, &iid, &mshlflags));
  367. if (IsEqualIID(iid, IID_ILockBytes))
  368. {
  369. sc = CFileStream::StaticReleaseMarshalData(pstStm, mshlflags);
  370. }
  371. else if (IsEqualIID(iid, IID_IStorage))
  372. {
  373. sc = CExposedDocFile::StaticReleaseMarshalData(pstStm, mshlflags);
  374. }
  375. else if (IsEqualIID(iid, IID_IStream))
  376. {
  377. sc = CExposedStream::StaticReleaseMarshalData(pstStm, mshlflags);
  378. }
  379. else
  380. {
  381. sc = E_NOINTERFACE;
  382. }
  383. olLog(("%p::Out CDocfileUnmarshalFactory::ReleaseMarshalData, sc == %lX\n",
  384. this, sc));
  385. EH_Err:
  386. return ResultFromScode(sc);
  387. }
  388. #else
  389. STDMETHODIMP CDocfileUnmarshalFactory::ReleaseMarshalData(IStream *pstStm)
  390. {
  391. olLog(("%p::Stb CDocfileUnmarshalFactory::ReleaseMarshalData(%p)\n",
  392. this, pstStm));
  393. return NOERROR;
  394. }
  395. #endif
  396. //+--------------------------------------------------------------
  397. //
  398. // Member: CDocfileUnmarshalFactory::DisconnectObject, public
  399. //
  400. // Synopsis: Non-functional
  401. //
  402. // Arguments: [dwRevserved] -
  403. //
  404. // Returns: Appropriate status code
  405. //
  406. // History: 18-Sep-92 DrewB Created
  407. //
  408. //---------------------------------------------------------------
  409. STDMETHODIMP CDocfileUnmarshalFactory::DisconnectObject(DWORD dwReserved)
  410. {
  411. olLog(("%p::Stb CDocfileUnmarshalFactory::DisconnectObject(%lu)\n",
  412. this, dwReserved));
  413. return NOERROR;
  414. }
  415. //+---------------------------------------------------------------------------
  416. //
  417. // Member: CDocfileUnmarshalFactory::CreateInstance, public
  418. //
  419. // Synopsis: Creates an instance of the docfile IMarshal unmarshaller
  420. //
  421. // Arguments: [pUnkOuter] -
  422. // [riid] - IID of object to create
  423. // [ppv] - Object return
  424. //
  425. // Returns: Appropriate status code
  426. //
  427. // Modifies: [ppv]
  428. //
  429. // History: 25-Jan-93 DrewB Created
  430. //
  431. //----------------------------------------------------------------------------
  432. STDMETHODIMP CDocfileUnmarshalFactory::CreateInstance(IUnknown *pUnkOuter,
  433. REFIID riid,
  434. LPVOID *ppv)
  435. {
  436. SCODE sc;
  437. olLog(("%p::In CDocfileUnmarshalFactory::CreateInstance(%p, riid, %p)\n",
  438. this, pUnkOuter, ppv));
  439. olDebugOut((DEB_TRACE, "In CDocfileUnmarshalFactory::CreateInstance:%p("
  440. "%p, riid, %p)\n", this, pUnkOuter, ppv));
  441. TRY
  442. {
  443. olChk(Validate());
  444. olChk(ValidatePtrBuffer(ppv));
  445. *ppv = NULL;
  446. olChk(ValidateIid(riid));
  447. if (pUnkOuter != NULL || !IsEqualIID(riid, IID_IMarshal))
  448. olErr(EH_Err, STG_E_INVALIDPARAMETER);
  449. _AddRef();
  450. *ppv = (IMarshal *)this;
  451. }
  452. CATCH(CException, e)
  453. {
  454. sc = e.GetErrorCode();
  455. }
  456. END_CATCH
  457. olDebugOut((DEB_TRACE, "Out CDocfileUnmarshalFactory::CreateInstance => "
  458. "%p\n", ppv));
  459. EH_Err:
  460. olLog(("%p::Out CDocfileUnmarshalFactory::CreateInstance(). "
  461. "*ppv == %p, ret == 0x%lX\n", this, *ppv, sc));
  462. return ResultFromScode(sc);
  463. }
  464. //+---------------------------------------------------------------------------
  465. //
  466. // Member: CDocfileUnmarshalFactory::LockServer, public
  467. //
  468. // Synopsis: Non-functional
  469. //
  470. // Arguments: [fLock] -
  471. //
  472. // Returns: Appropriate status code
  473. //
  474. // History: 25-Jan-93 DrewB Created
  475. //
  476. //----------------------------------------------------------------------------
  477. STDMETHODIMP CDocfileUnmarshalFactory::LockServer(BOOL fLock)
  478. {
  479. olLog(("%p::Stb CDocfileUnmarshalFactory::LockServer(%d)\n",
  480. this, fLock));
  481. return NOERROR;
  482. }