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.

4822 lines
140 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: create.cpp
  7. //
  8. // Contents: creation and miscellaneous APIs
  9. //
  10. // Classes:
  11. //
  12. // Functions: OleCreate
  13. // OleCreateEx
  14. // OleCreateFromData
  15. // OleCreateFromDataEx
  16. // OleCreateLinkFromData
  17. // OleCreateLinkFromDataEx
  18. // OleCreateLink
  19. // OleCreateLinkEx
  20. // OleCreateLinkToFile
  21. // OleCreateLinkToFileEx
  22. // OleCreateFromFile
  23. // OleCreateFromFileEx
  24. // OleDoAutoConvert
  25. // OleLoad
  26. // OleCreateStaticFromData
  27. // OleQueryCreateFromData
  28. // OleQueryLinkFromData
  29. // CoIsHashedOle1Class (internal)
  30. // EnsureCLSIDIsRegistered (internal)
  31. //
  32. // History: dd-mmm-yy Author Comment
  33. // 26-Apr-96 davidwor Moved validation into separate function.
  34. // 01-Mar-96 davidwor Added extended create functions.
  35. // 16-Dec-94 alexgo added call tracing
  36. // 07-Jul-94 KevinRo Changed RegQueryValue to RegOpenKey in
  37. // strategic places.
  38. // 10-May-94 KevinRo Reimplemented OLE 1.0 interop
  39. // 24-Jan-94 alexgo first pass at converting to Cairo-style
  40. // memory allocation
  41. // 11-Jan-94 alexgo added VDATEHEAP macros to every function
  42. // 10-Dec-93 AlexT header clean up - include ole1cls.h
  43. // 08-Dec-93 ChrisWe added necessary casts to GlobalLock() calls
  44. // resulting from removing bogus GlobalLock() macros in
  45. // le2int.h
  46. // 29-Nov-93 ChrisWe changed call to UtIsFormatSupported to
  47. // take a single DWORD of direction flags
  48. // 22-Nov-93 ChrisWe replaced overloaded == with IsEqualxID
  49. // 28-Oct-93 alexgo 32bit port
  50. // 24-Aug-92 srinik created
  51. //
  52. //--------------------------------------------------------------------------
  53. #include <le2int.h>
  54. #pragma SEG(create)
  55. #include <create.h>
  56. #include <ole1cls.h> // Only needed to get CLSID_WordDocument
  57. // HACK ALERT!! This is needed for the MFC OleQueryCreateFromData hack
  58. #include <clipdata.h>
  59. NAME_SEG(Create)
  60. ASSERTDATA
  61. //used in wCreateObject
  62. #define STG_NONE 0
  63. #define STG_INITNEW 1
  64. #define STG_LOAD 2
  65. #define QUERY_CREATE_NONE 0
  66. #define QUERY_CREATE_OLE 1
  67. #define QUERY_CREATE_STATIC 2
  68. INTERNAL wDoUpdate(IUnknown FAR* lpUnknown);
  69. //+-------------------------------------------------------------------------
  70. //
  71. // Function: wGetEnumFormatEtc
  72. //
  73. // Synopsis: retrieves a FormatEtc enumerator
  74. //
  75. // Effects:
  76. //
  77. // Arguments: [pDataObj] -- the data object
  78. // [dwDirection] -- direction
  79. // [ppenum] -- where to put the enumerator
  80. //
  81. // Requires:
  82. //
  83. // Returns:
  84. //
  85. // Signals:
  86. //
  87. // Modifies:
  88. //
  89. // Algorithm: asks the data object for the enumerator
  90. // if it returns OLE_S_USEREG, then get try to get the
  91. // clsid from IOleObject::GetUserClassID and enumerate
  92. // the formats from the registry.
  93. //
  94. // History: dd-mmm-yy Author Comment
  95. // 24-Apr-94 alexgo author
  96. // 13-Mar-95 scottsk Added hack for the Bob Calendar
  97. //
  98. // Notes:
  99. //
  100. //--------------------------------------------------------------------------
  101. HRESULT wGetEnumFormatEtc( IDataObject *pDataObj, DWORD dwDirection,
  102. IEnumFORMATETC **ppIEnum)
  103. {
  104. HRESULT hresult;
  105. IOleObject * pOleObject;
  106. CLSID clsid;
  107. VDATEHEAP();
  108. LEDebugOut((DEB_ITRACE, "%p _IN wGetEnumFormatEtc ( %p , %p , %lx )"
  109. "\n", NULL, pDataObj, ppIEnum, dwDirection));
  110. hresult = pDataObj->EnumFormatEtc(dwDirection, ppIEnum);
  111. if( hresult == ResultFromScode(OLE_S_USEREG) )
  112. {
  113. hresult = pDataObj->QueryInterface(IID_IOleObject,
  114. (void **)&pOleObject);
  115. if( hresult != NOERROR )
  116. {
  117. // return E_FAIL vs E_NOINTERFACE
  118. hresult = ResultFromScode(E_FAIL);
  119. goto errRtn;
  120. }
  121. hresult = pOleObject->GetUserClassID(&clsid);
  122. if( hresult == NOERROR )
  123. {
  124. hresult = OleRegEnumFormatEtc(clsid, dwDirection,
  125. ppIEnum);
  126. }
  127. pOleObject->Release();
  128. }
  129. else if (*ppIEnum == NULL && hresult == NOERROR)
  130. {
  131. // HACK ALERT: NT Bug #8350. MS Bob Calendar returns success from
  132. // IDO::EnumFormatEtc and sets *ppIEnum = NULL on the IDO used during
  133. // drag-drop. Massage the return value to be failure.
  134. hresult = E_FAIL;
  135. }
  136. errRtn:
  137. LEDebugOut((DEB_ITRACE, "%p OUT wGetEnumFormatEtc ( %lx ) [ %p ]\n",
  138. NULL, hresult, *ppIEnum));
  139. return hresult;
  140. }
  141. //+-------------------------------------------------------------------------
  142. //
  143. // Function: OleCreate
  144. //
  145. // Synopsis: Creates and runs an object of the requested CLSID
  146. //
  147. // Effects:
  148. //
  149. // Arguments: [rclsid] -- the CLSID of the object to create
  150. // [iid] -- the interface to request on the object
  151. // [renderopt] -- render options, such as OLERENDER_DRAW
  152. // [lpFormatEtc] -- rendering format, if OLERENDER_FORMAT is
  153. // specified in renderopt.
  154. // [lpClientSite] -- the client site for the object
  155. // [lpStg] -- the object's storage
  156. // [lplpObj] -- where to put the pointer to the created
  157. // object
  158. //
  159. // Requires: HRESULT
  160. //
  161. // Returns:
  162. //
  163. // Signals:
  164. //
  165. // Modifies:
  166. //
  167. // Algorithm:
  168. //
  169. // History: dd-mmm-yy Author Comment
  170. // 16-Dec-94 alexgo added call tracing
  171. // 05-May-94 alexgo fixed error case if cache initialization
  172. // fails.
  173. // 28-Oct-93 alexgo 32bit port
  174. //
  175. // Notes:
  176. //
  177. //--------------------------------------------------------------------------
  178. #pragma SEG(OleCreate)
  179. STDAPI OleCreate
  180. (
  181. REFCLSID rclsid,
  182. REFIID iid,
  183. DWORD renderopt,
  184. LPFORMATETC lpFormatEtc,
  185. IOleClientSite FAR* lpClientSite,
  186. IStorage FAR* lpStg,
  187. void FAR* FAR* lplpObj
  188. )
  189. {
  190. DWORD advf = ADVF_PRIMEFIRST;
  191. return OleCreateEx(rclsid, iid, 0, renderopt,
  192. (lpFormatEtc ? 1 : 0), (lpFormatEtc ? &advf : NULL),
  193. lpFormatEtc, NULL, NULL, lpClientSite, lpStg, lplpObj);
  194. }
  195. //+-------------------------------------------------------------------------
  196. //
  197. // Function: OleCreateEx
  198. //
  199. // Synopsis: Creates and runs an object of the requested CLSID
  200. //
  201. // Effects:
  202. //
  203. // Arguments: [rclsid] -- the CLSID of the object to create
  204. // [iid] -- the interface to request on the object
  205. // [dwFlags] -- object creation flags
  206. // [renderopt] -- render options, such as OLERENDER_DRAW
  207. // [cFormats] -- the number of elements in rgFormatEtc
  208. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  209. // is specified in renderopt
  210. // [rgFormatEtc] -- array of rendering formats, if
  211. // OLERENDER_FORMAT is specified in renderopt
  212. // [lpAdviseSink] -- the advise sink for the object
  213. // [rgdwConnection]-- where to put the connection IDs for the
  214. // advisory connections
  215. // [lpClientSite] -- the client site for the object
  216. // [lpStg] -- the object's storage
  217. // [lplpObj] -- where to put the pointer to the created
  218. // object
  219. //
  220. // Requires: HRESULT
  221. //
  222. // Returns:
  223. //
  224. // Signals:
  225. //
  226. // Modifies:
  227. //
  228. // Algorithm:
  229. //
  230. // History: dd-mmm-yy Author Comment
  231. // 16-Dec-94 alexgo added call tracing
  232. // 05-May-94 alexgo fixed error case if cache initialization
  233. // fails.
  234. // 28-Oct-93 alexgo 32bit port
  235. //
  236. // Notes:
  237. //
  238. //--------------------------------------------------------------------------
  239. #pragma SEG(OleCreateEx)
  240. STDAPI OleCreateEx
  241. (
  242. REFCLSID rclsid,
  243. REFIID iid,
  244. DWORD dwFlags,
  245. DWORD renderopt,
  246. ULONG cFormats,
  247. DWORD FAR* rgAdvf,
  248. LPFORMATETC rgFormatEtc,
  249. IAdviseSink FAR* lpAdviseSink,
  250. DWORD FAR* rgdwConnection,
  251. IOleClientSite FAR* lpClientSite,
  252. IStorage FAR* lpStg,
  253. void FAR* FAR* lplpObj
  254. )
  255. {
  256. OLETRACEIN((API_OleCreateEx,
  257. PARAMFMT("rclsid= %I, iid= %I, dwFlags= %x, renderopt= %x, cFormats= %x, rgAdvf= %te, rgFormatEtc= %p, lpAdviseSink= %p, rgdwConnection= %p, lpClientSite= %p, lpStg= %p, lplpObj= %p"),
  258. &rclsid, &iid, dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj));
  259. VDATEHEAP();
  260. HRESULT error;
  261. FORMATETC formatEtc;
  262. LPFORMATETC lpFormatEtc;
  263. BOOL fAlloced = FALSE;
  264. LEDebugOut((DEB_TRACE, "%p _IN OleCreateEx ( %p , %p , %lx , %lx , %lx ,"
  265. "%p , %p , %p , %p , %p , %p , %p )\n", 0, &rclsid, &iid, dwFlags,
  266. renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection,
  267. lpClientSite, lpStg, lplpObj));
  268. VDATEPTROUT_LABEL( lplpObj, LPVOID, errRtn, error );
  269. *lplpObj = NULL;
  270. VDATEIID_LABEL( iid, errRtn, error);
  271. error = wValidateCreateParams(dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg);
  272. if (error != NOERROR)
  273. goto errRtn;
  274. if ((error = wValidateFormatEtcEx(renderopt, &cFormats, rgFormatEtc,
  275. &formatEtc, &lpFormatEtc, &fAlloced)) != NOERROR)
  276. goto LExit;
  277. if ((error = wCreateObject(rclsid, FALSE,
  278. iid, lpClientSite, lpStg,
  279. STG_INITNEW, lplpObj)) != NOERROR)
  280. goto LExit;
  281. // No need to Run the object if no caches are requested.
  282. if ((renderopt != OLERENDER_NONE) && (renderopt != OLERENDER_ASIS))
  283. {
  284. if ((error = OleRun((LPUNKNOWN) *lplpObj)) != NOERROR)
  285. goto LExit;
  286. if ((error = wInitializeCacheEx(NULL, rclsid, renderopt,
  287. cFormats, rgAdvf, lpFormatEtc, lpAdviseSink, rgdwConnection,
  288. *lplpObj))
  289. != NOERROR)
  290. {
  291. // if this fails, we need to call Close
  292. // to shut down the embedding (the reverse of Run).
  293. // the final release below will be the final
  294. // one to nuke the memory image.
  295. IOleObject * lpOleObject;
  296. if( ((IUnknown *)*lplpObj)->QueryInterface(
  297. IID_IOleObject, (void **)&lpOleObject) == NOERROR )
  298. {
  299. Assert(lpOleObject);
  300. lpOleObject->Close(OLECLOSE_NOSAVE);
  301. lpOleObject->Release();
  302. }
  303. }
  304. }
  305. LExit:
  306. if (fAlloced)
  307. PubMemFree(lpFormatEtc);
  308. if (error != NOERROR && *lplpObj) {
  309. ((IUnknown FAR*) *lplpObj)->Release();
  310. *lplpObj = NULL;
  311. }
  312. LEDebugOut((DEB_TRACE, "%p OUT OleCreateEx ( %lx ) [ %p ]\n", 0,
  313. error, *lplpObj));
  314. error = wReturnCreationError(error);
  315. errRtn:
  316. OLETRACEOUT((API_OleCreateEx, error));
  317. return error;
  318. }
  319. //+-------------------------------------------------------------------------
  320. //
  321. // Function: OleCreateFromData
  322. //
  323. // Synopsis: Creates an embedded object from an IDataObject pointer
  324. // (such as an data object from the clipboard or from a drag
  325. // and drop operation)
  326. //
  327. // Effects:
  328. //
  329. // Arguments: [lpSrcDataObj] -- pointer to the data object from which
  330. // the object should be created
  331. // [iid] -- interface ID to request
  332. // [renderopt] -- rendering options (same as OleCreate)
  333. // [lpFormatEtc] -- render format options (same as OleCreate)
  334. // [lpClientSite] -- client site for the object
  335. // [lpStg] -- storage for the object
  336. // [lplpObj] -- where to put the object
  337. //
  338. // Requires:
  339. //
  340. // Returns: HRESULT
  341. //
  342. // Signals:
  343. //
  344. // Modifies:
  345. //
  346. // Algorithm:
  347. //
  348. // History: dd-mmm-yy Author Comment
  349. // 16-Dec-94 alexgo added call tracing
  350. // 28-Oct-93 alexgo 32bit port
  351. //
  352. // Notes:
  353. //
  354. //--------------------------------------------------------------------------
  355. #pragma SEG(OleCreateFromData)
  356. STDAPI OleCreateFromData
  357. (
  358. IDataObject FAR* lpSrcDataObj,
  359. REFIID iid,
  360. DWORD renderopt,
  361. LPFORMATETC lpFormatEtc,
  362. IOleClientSite FAR* lpClientSite,
  363. IStorage FAR* lpStg,
  364. void FAR* FAR* lplpObj
  365. )
  366. {
  367. DWORD advf = ADVF_PRIMEFIRST;
  368. return OleCreateFromDataEx(lpSrcDataObj, iid, 0, renderopt,
  369. (lpFormatEtc ? 1 : 0), (lpFormatEtc ? &advf : NULL),
  370. lpFormatEtc, NULL, NULL, lpClientSite, lpStg, lplpObj);
  371. }
  372. //+-------------------------------------------------------------------------
  373. //
  374. // Function: OleCreateFromDataEx
  375. //
  376. // Synopsis: Creates an embedded object from an IDataObject pointer
  377. // (such as an data object from the clipboard or from a drag
  378. // and drop operation)
  379. //
  380. // Effects:
  381. //
  382. // Arguments: [lpSrcDataObj] -- pointer to the data object from which
  383. // the object should be created
  384. // [iid] -- interface ID to request
  385. // [dwFlags] -- object creation flags
  386. // [renderopt] -- render options, such as OLERENDER_DRAW
  387. // [cFormats] -- the number of elements in rgFormatEtc
  388. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  389. // is specified in renderopt
  390. // [rgFormatEtc] -- array of rendering formats, if
  391. // OLERENDER_FORMAT is specified in renderopt
  392. // [lpAdviseSink] -- the advise sink for the object
  393. // [rgdwConnection]-- where to put the connection IDs for the
  394. // advisory connections
  395. // [lpClientSite] -- client site for the object
  396. // [lpStg] -- storage for the object
  397. // [lplpObj] -- where to put the object
  398. //
  399. // Requires:
  400. //
  401. // Returns: HRESULT
  402. //
  403. // Signals:
  404. //
  405. // Modifies:
  406. //
  407. // Algorithm:
  408. //
  409. // History: dd-mmm-yy Author Comment
  410. // 16-Dec-94 alexgo added call tracing
  411. // 28-Oct-93 alexgo 32bit port
  412. //
  413. // Notes:
  414. //
  415. //--------------------------------------------------------------------------
  416. #pragma SEG(OleCreateFromDataEx)
  417. STDAPI OleCreateFromDataEx
  418. (
  419. IDataObject FAR* lpSrcDataObj,
  420. REFIID iid,
  421. DWORD dwFlags,
  422. DWORD renderopt,
  423. ULONG cFormats,
  424. DWORD FAR* rgAdvf,
  425. LPFORMATETC rgFormatEtc,
  426. IAdviseSink FAR* lpAdviseSink,
  427. DWORD FAR* rgdwConnection,
  428. IOleClientSite FAR* lpClientSite,
  429. IStorage FAR* lpStg,
  430. void FAR* FAR* lplpObj
  431. )
  432. {
  433. HRESULT hresult;
  434. CLIPFORMAT cfFormat;
  435. WORD wStatus;
  436. OLETRACEIN((API_OleCreateFromDataEx,
  437. PARAMFMT("lpSrcDataObj= %p, iid= %I, dwFlags= %x, renderopt= %x, cFormats= %x, rgAdvf= %te, rgFormatEtc= %p, lpAdviseSink= %p, rgdwConnection= %p, lpClientSite= %p, lpStg= %p, lplpObj= %p"),
  438. lpSrcDataObj, &iid, dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj));
  439. VDATEHEAP();
  440. LEDebugOut((DEB_TRACE, "%p _IN OleCreateFromDataEx ( %p , %p , %lx , %lx ,"
  441. " %lx , %p , %p , %p , %p , %p , %p , %p )\n", 0, lpSrcDataObj, &iid,
  442. dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink,
  443. rgdwConnection, lpClientSite, lpStg, lplpObj));
  444. VDATEPTROUT_LABEL( lplpObj, LPVOID, safeRtn, hresult );
  445. *lplpObj = NULL;
  446. VDATEIFACE_LABEL( lpSrcDataObj, errRtn, hresult );
  447. VDATEIID_LABEL( iid, errRtn, hresult );
  448. hresult = wValidateCreateParams(dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg);
  449. if (hresult != NOERROR)
  450. goto errRtn;
  451. wStatus = wQueryEmbedFormats(lpSrcDataObj, &cfFormat);
  452. if (!(wStatus & QUERY_CREATE_OLE))
  453. {
  454. if (wStatus & QUERY_CREATE_STATIC)
  455. {
  456. hresult = OLE_E_STATIC;
  457. }
  458. else
  459. {
  460. hresult = DV_E_FORMATETC;
  461. }
  462. goto errRtn;
  463. }
  464. // We can create an OLE object.
  465. // See whether we have to create a package
  466. if (cfFormat == g_cfFileName || cfFormat == g_cfFileNameW)
  467. {
  468. hresult = wCreatePackageEx(lpSrcDataObj, iid, dwFlags, renderopt,
  469. cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection,
  470. lpClientSite, lpStg, FALSE /*fLink*/, lplpObj);
  471. }
  472. else
  473. {
  474. hresult = wCreateFromDataEx(lpSrcDataObj, iid, dwFlags, renderopt,
  475. cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection,
  476. lpClientSite, lpStg, lplpObj);
  477. }
  478. errRtn:
  479. LEDebugOut((DEB_TRACE, "%p OUT OleCreateFromDataEx ( %lx ) [ %p ]\n",
  480. 0, hresult, *lplpObj));
  481. safeRtn:
  482. OLETRACEOUT((API_OleCreateFromDataEx, hresult));
  483. return hresult;
  484. }
  485. //+-------------------------------------------------------------------------
  486. //
  487. // Function: OleCreateLinkFromData
  488. //
  489. // Synopsis: Creates a link from a data object (e.g. for Paste->Link)
  490. //
  491. // Effects:
  492. //
  493. // Arguments: [lpSrcDataObj] -- pointer to the data object
  494. // [iid] -- requested interface ID
  495. // [renderopt] -- rendering options
  496. // [lpFormatEtc] -- format to render (if renderopt ==
  497. // OLERENDER_FORMAT)
  498. // [lpClientSite] -- pointer to the client site
  499. // [lpStg] -- pointer to the storage
  500. // [lplpObj] -- where to put the object
  501. //
  502. // Requires:
  503. //
  504. // Returns: HRESULT
  505. //
  506. // Signals:
  507. //
  508. // Modifies:
  509. //
  510. // Algorithm:
  511. //
  512. // History: dd-mmm-yy Author Comment
  513. // 16-Dec-94 alexgo added call tracing
  514. // 28-Oct-93 alexgo 32bit port
  515. //
  516. // Notes:
  517. //
  518. //--------------------------------------------------------------------------
  519. #pragma SEG(OleCreateLinkFromData)
  520. STDAPI OleCreateLinkFromData
  521. (
  522. IDataObject FAR* lpSrcDataObj,
  523. REFIID iid,
  524. DWORD renderopt,
  525. LPFORMATETC lpFormatEtc,
  526. IOleClientSite FAR* lpClientSite,
  527. IStorage FAR* lpStg,
  528. void FAR* FAR* lplpObj
  529. )
  530. {
  531. DWORD advf = ADVF_PRIMEFIRST;
  532. return OleCreateLinkFromDataEx(lpSrcDataObj, iid, 0, renderopt,
  533. (lpFormatEtc ? 1 : 0), (lpFormatEtc ? &advf : NULL),
  534. lpFormatEtc, NULL, NULL, lpClientSite, lpStg, lplpObj);
  535. }
  536. //+-------------------------------------------------------------------------
  537. //
  538. // Function: OleCreateLinkFromDataEx
  539. //
  540. // Synopsis: Creates a link from a data object (e.g. for Paste->Link)
  541. //
  542. // Effects:
  543. //
  544. // Arguments: [lpSrcDataObj] -- pointer to the data object
  545. // [iid] -- requested interface ID
  546. // [dwFlags] -- object creation flags
  547. // [renderopt] -- render options, such as OLERENDER_DRAW
  548. // [cFormats] -- the number of elements in rgFormatEtc
  549. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  550. // is specified in renderopt
  551. // [rgFormatEtc] -- array of rendering formats, if
  552. // OLERENDER_FORMAT is specified in renderopt
  553. // [lpAdviseSink] -- the advise sink for the object
  554. // [rgdwConnection]-- where to put the connection IDs for the
  555. // advisory connections
  556. // [lpClientSite] -- pointer to the client site
  557. // [lpStg] -- pointer to the storage
  558. // [lplpObj] -- where to put the object
  559. //
  560. // Requires:
  561. //
  562. // Returns: HRESULT
  563. //
  564. // Signals:
  565. //
  566. // Modifies:
  567. //
  568. // Algorithm:
  569. //
  570. // History: dd-mmm-yy Author Comment
  571. // 16-Dec-94 alexgo added call tracing
  572. // 28-Oct-93 alexgo 32bit port
  573. //
  574. // Notes:
  575. //
  576. //--------------------------------------------------------------------------
  577. #pragma SEG(OleCreateLinkFromDataEx)
  578. STDAPI OleCreateLinkFromDataEx
  579. (
  580. IDataObject FAR* lpSrcDataObj,
  581. REFIID iid,
  582. DWORD dwFlags,
  583. DWORD renderopt,
  584. ULONG cFormats,
  585. DWORD FAR* rgAdvf,
  586. LPFORMATETC rgFormatEtc,
  587. IAdviseSink FAR* lpAdviseSink,
  588. DWORD FAR* rgdwConnection,
  589. IOleClientSite FAR* lpClientSite,
  590. IStorage FAR* lpStg,
  591. void FAR* FAR* lplpObj
  592. )
  593. {
  594. OLETRACEIN((API_OleCreateLinkFromDataEx,
  595. PARAMFMT("lpSrcDataObj= %p, iid= %I, dwFlags= %x, renderopt= %x, cFormats= %x, rgAdvf= %te, rgFormatEtc= %p, lpAdviseSink= %p, rgdwConnection= %p, lpClientSite= %p, lpStg= %p, lplpObj= %p"),
  596. lpSrcDataObj, &iid, dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj));
  597. VDATEHEAP();
  598. HRESULT error;
  599. FORMATETC formatEtc;
  600. LPFORMATETC lpFormatEtc;
  601. BOOL fAlloced = FALSE;
  602. CLIPFORMAT cfFormat;
  603. LEDebugOut((DEB_TRACE, "%p _IN OleCreateLinkFromDataEx ( %p , %p , %lx,"
  604. " %lx, %lx , %p , %p , %p, %p , %p , %p, %p )\n", NULL, lpSrcDataObj,
  605. &iid, dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink,
  606. rgdwConnection, lpClientSite, lpStg, lplpObj));
  607. VDATEPTROUT_LABEL( lplpObj, LPVOID, safeRtn, error );
  608. *lplpObj = NULL;
  609. VDATEIFACE_LABEL( lpSrcDataObj, errRtn, error );
  610. VDATEIID_LABEL( iid, errRtn, error );
  611. error = wValidateCreateParams(dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg);
  612. if (error != NOERROR)
  613. goto errRtn;
  614. cfFormat = wQueryLinkFormats(lpSrcDataObj);
  615. if (cfFormat == g_cfLinkSource) {
  616. CLSID clsidLast;
  617. LPMONIKER lpmkSrc;
  618. LPDATAOBJECT lpBoundDataObj = NULL;
  619. // we are going to create a normal link
  620. if ((error = wValidateFormatEtcEx(renderopt, &cFormats, rgFormatEtc,
  621. &formatEtc, &lpFormatEtc, &fAlloced)) != NOERROR)
  622. {
  623. goto errRtn;
  624. }
  625. if ((error = wGetMonikerAndClassFromObject(lpSrcDataObj,
  626. &lpmkSrc, &clsidLast)) != NOERROR)
  627. {
  628. goto errRtn;
  629. }
  630. if (wQueryUseCustomLink(clsidLast)) {
  631. // the object supports Custom Link Source, so bind
  632. // to the object and pass its IDataObject pointer
  633. // to wCreateLinkEx()
  634. if (BindMoniker(lpmkSrc, NULL /*grfOpt*/, IID_IDataObject,
  635. (LPLPVOID) &lpBoundDataObj) == NOERROR)
  636. {
  637. lpSrcDataObj = lpBoundDataObj;
  638. }
  639. }
  640. // otherwise continue to use StdOleLink implementation
  641. error = wCreateLinkEx(lpmkSrc, clsidLast, lpSrcDataObj, iid,
  642. dwFlags, renderopt, cFormats, rgAdvf, lpFormatEtc, lpAdviseSink,
  643. rgdwConnection, lpClientSite, lpStg, lplpObj);
  644. // we don't need the moniker anymore
  645. lpmkSrc->Release();
  646. // we would have bound in the custom link source case,
  647. // release the pointer
  648. if (lpBoundDataObj)
  649. {
  650. if (error == NOERROR && (dwFlags & OLECREATE_LEAVERUNNING))
  651. OleRun((LPUNKNOWN)*lplpObj);
  652. lpBoundDataObj->Release();
  653. }
  654. } else if (cfFormat == g_cfFileName || cfFormat == g_cfFileNameW) {
  655. // See whether we have to create a packaged link
  656. error = wCreatePackageEx(lpSrcDataObj, iid, dwFlags, renderopt,
  657. cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection,
  658. lpClientSite, lpStg, TRUE /*fLink*/, lplpObj);
  659. }
  660. else
  661. {
  662. error = DV_E_FORMATETC;
  663. }
  664. errRtn:
  665. if (fAlloced)
  666. PubMemFree(lpFormatEtc);
  667. LEDebugOut((DEB_TRACE, "%p OUT OleCreateLinkFromDataEx ( %lx ) [ %p ]\n",
  668. NULL, error, *lplpObj));
  669. safeRtn:
  670. OLETRACEOUT((API_OleCreateLinkFromDataEx, error));
  671. return error;
  672. }
  673. //+-------------------------------------------------------------------------
  674. //
  675. // Function: OleCreateLink
  676. //
  677. // Synopsis: Create a link to the object referred to by a moniker
  678. //
  679. // Effects:
  680. //
  681. // Arguments: [lpmkSrc] -- source of the link
  682. // [iid] -- interface requested
  683. // [renderopt] -- rendering options
  684. // [lpFormatEtc] -- rendering format (if needed)
  685. // [lpClientSite] -- pointer to the client site for the link
  686. // [lpStg] -- storage for the link
  687. // [lplpObj] -- where to put the link object
  688. //
  689. // Requires:
  690. //
  691. // Returns: HRESULT
  692. //
  693. // Signals:
  694. //
  695. // Modifies:
  696. //
  697. // Algorithm:
  698. //
  699. // History: dd-mmm-yy Author Comment
  700. // 16-Dec-94 alexgo added call tracing
  701. // 28-Oct-93 alexgo 32bit port
  702. //
  703. // Notes:
  704. //
  705. //--------------------------------------------------------------------------
  706. #pragma SEG(OleCreateLink)
  707. STDAPI OleCreateLink
  708. (
  709. IMoniker FAR* lpmkSrc,
  710. REFIID iid,
  711. DWORD renderopt,
  712. LPFORMATETC lpFormatEtc,
  713. IOleClientSite FAR* lpClientSite,
  714. IStorage FAR* lpStg,
  715. void FAR* FAR* lplpObj
  716. )
  717. {
  718. DWORD advf = ADVF_PRIMEFIRST;
  719. return OleCreateLinkEx(lpmkSrc, iid, 0, renderopt,
  720. (lpFormatEtc ? 1 : 0), (lpFormatEtc ? &advf : NULL),
  721. lpFormatEtc, NULL, NULL, lpClientSite, lpStg, lplpObj);
  722. }
  723. //+-------------------------------------------------------------------------
  724. //
  725. // Function: OleCreateLinkEx
  726. //
  727. // Synopsis: Create a link to the object referred to by a moniker
  728. //
  729. // Effects:
  730. //
  731. // Arguments: [lpmkSrc] -- source of the link
  732. // [iid] -- interface requested
  733. // [dwFlags] -- object creation flags
  734. // [renderopt] -- render options, such as OLERENDER_DRAW
  735. // [cFormats] -- the number of elements in rgFormatEtc
  736. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  737. // is specified in renderopt
  738. // [rgFormatEtc] -- array of rendering formats, if
  739. // OLERENDER_FORMAT is specified in renderopt
  740. // [lpAdviseSink] -- the advise sink for the object
  741. // [rgdwConnection]-- where to put the connection IDs for the
  742. // advisory connections
  743. // [lpClientSite] -- pointer to the client site for the link
  744. // [lpStg] -- storage for the link
  745. // [lplpObj] -- where to put the link object
  746. //
  747. // Requires:
  748. //
  749. // Returns: HRESULT
  750. //
  751. // Signals:
  752. //
  753. // Modifies:
  754. //
  755. // Algorithm:
  756. //
  757. // History: dd-mmm-yy Author Comment
  758. // 16-Dec-94 alexgo added call tracing
  759. // 28-Oct-93 alexgo 32bit port
  760. //
  761. // Notes:
  762. //
  763. //--------------------------------------------------------------------------
  764. #pragma SEG(OleCreateLinkEx)
  765. STDAPI OleCreateLinkEx
  766. (
  767. IMoniker FAR* lpmkSrc,
  768. REFIID iid,
  769. DWORD dwFlags,
  770. DWORD renderopt,
  771. ULONG cFormats,
  772. DWORD FAR* rgAdvf,
  773. LPFORMATETC rgFormatEtc,
  774. IAdviseSink FAR* lpAdviseSink,
  775. DWORD FAR* rgdwConnection,
  776. IOleClientSite FAR* lpClientSite,
  777. IStorage FAR* lpStg,
  778. void FAR* FAR* lplpObj
  779. )
  780. {
  781. OLETRACEIN((API_OleCreateLinkEx,
  782. PARAMFMT("lpmkSrc= %p, iid= %I, dwFlags= %x, renderopt= %x, cFormats= %x, rgAdvf= %te, rgFormatEtc= %p, lpAdviseSink= %p, rgdwConnection= %p, lpClientSite= %p, lpStg= %p, lplpObj= %p"),
  783. lpmkSrc, &iid, dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj));
  784. VDATEHEAP();
  785. FORMATETC formatEtc;
  786. LPFORMATETC lpFormatEtc;
  787. BOOL fAlloced = FALSE;
  788. HRESULT error;
  789. LEDebugOut((DEB_TRACE, "%p _IN OleCreateLinkEx ( %p , %p , %lx, %lx,"
  790. " %lx , %p , %p , %p, %p , %p , %p , %p )\n", NULL, lpmkSrc, &iid,
  791. dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink,
  792. rgdwConnection, lpClientSite, lpStg, lplpObj));
  793. VDATEPTROUT_LABEL( lplpObj, LPVOID, errRtn, error );
  794. *lplpObj = NULL;
  795. VDATEIFACE_LABEL( lpmkSrc, errRtn, error);
  796. VDATEIID_LABEL( iid, errRtn, error );
  797. error = wValidateCreateParams(dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg);
  798. if (error != NOERROR)
  799. goto errRtn;
  800. if ((error = wValidateFormatEtcEx(renderopt, &cFormats, rgFormatEtc,
  801. &formatEtc, &lpFormatEtc, &fAlloced)) == NOERROR)
  802. {
  803. error = wCreateLinkEx(lpmkSrc, CLSID_NULL, NULL /* lpSrcDataObj */,
  804. iid, dwFlags, renderopt, cFormats, rgAdvf, lpFormatEtc,
  805. lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj);
  806. if (fAlloced)
  807. PubMemFree(lpFormatEtc);
  808. }
  809. LEDebugOut((DEB_TRACE, "%p OUT OleCreateLinkEx ( %lx ) [ %p ]\n", NULL,
  810. error, *lplpObj));
  811. errRtn:
  812. OLETRACEOUT((API_OleCreateLinkEx, error));
  813. return error;
  814. }
  815. //+-------------------------------------------------------------------------
  816. //
  817. // Function: OleCreateLinkToFile
  818. //
  819. // Synopsis: Creates a link object to the file specified in [lpszFileName]
  820. //
  821. // Effects:
  822. //
  823. // Arguments: [lpszFileName] -- the name of the file
  824. // [iid] -- interface ID requested
  825. // [renderopt] -- rendering options
  826. // [lpFormatEtc] -- format in which to render (if [renderopt]
  827. // == OLERENDER_FORMAT);
  828. // [lpClientSite] -- pointer to the client site for the link
  829. // [lpStg] -- pointer to the storage for the object
  830. // [lplpObj] -- where to put a pointer to new link object
  831. //
  832. // Requires:
  833. //
  834. // Returns: HRESULT
  835. //
  836. // Signals:
  837. //
  838. // Modifies:
  839. //
  840. // Algorithm:
  841. //
  842. // History: dd-mmm-yy Author Comment
  843. // 16-Dec-94 alexgo added call tracing
  844. // 28-Oct-93 alexgo 32bit port, fixed memory leak in error
  845. // case
  846. //
  847. // Notes:
  848. //
  849. //--------------------------------------------------------------------------
  850. #pragma SEG(OleCreateLinkToFile)
  851. STDAPI OleCreateLinkToFile
  852. (
  853. LPCOLESTR lpszFileName,
  854. REFIID iid,
  855. DWORD renderopt,
  856. LPFORMATETC lpFormatEtc,
  857. IOleClientSite FAR* lpClientSite,
  858. IStorage FAR* lpStg,
  859. void FAR* FAR* lplpObj
  860. )
  861. {
  862. DWORD advf = ADVF_PRIMEFIRST;
  863. return OleCreateLinkToFileEx(lpszFileName, iid, 0, renderopt,
  864. (lpFormatEtc ? 1 : 0), (lpFormatEtc ? &advf : NULL),
  865. lpFormatEtc, NULL, NULL, lpClientSite, lpStg, lplpObj);
  866. }
  867. //+-------------------------------------------------------------------------
  868. //
  869. // Function: OleCreateLinkToFileEx
  870. //
  871. // Synopsis: Creates a link object to the file specified in [lpszFileName]
  872. //
  873. // Effects:
  874. //
  875. // Arguments: [lpszFileName] -- the name of the file
  876. // [iid] -- interface ID requested
  877. // [dwFlags] -- object creation flags
  878. // [renderopt] -- render options, such as OLERENDER_DRAW
  879. // [cFormats] -- the number of elements in rgFormatEtc
  880. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  881. // is specified in renderopt
  882. // [rgFormatEtc] -- array of rendering formats, if
  883. // OLERENDER_FORMAT is specified in renderopt
  884. // [lpAdviseSink] -- the advise sink for the object
  885. // [rgdwConnection]-- where to put the connection IDs for the
  886. // advisory connections
  887. // [lpClientSite] -- pointer to the client site for the link
  888. // [lpStg] -- pointer to the storage for the object
  889. // [lplpObj] -- where to put a pointer to new link object
  890. //
  891. // Requires:
  892. //
  893. // Returns: HRESULT
  894. //
  895. // Signals:
  896. //
  897. // Modifies:
  898. //
  899. // Algorithm:
  900. //
  901. // History: dd-mmm-yy Author Comment
  902. // 16-Dec-94 alexgo added call tracing
  903. // 28-Oct-93 alexgo 32bit port, fixed memory leak in error
  904. // case
  905. //
  906. // Notes:
  907. //
  908. //--------------------------------------------------------------------------
  909. #pragma SEG(OleCreateLinkToFileEx)
  910. STDAPI OleCreateLinkToFileEx
  911. (
  912. LPCOLESTR lpszFileName,
  913. REFIID iid,
  914. DWORD dwFlags,
  915. DWORD renderopt,
  916. ULONG cFormats,
  917. DWORD FAR* rgAdvf,
  918. LPFORMATETC rgFormatEtc,
  919. IAdviseSink FAR* lpAdviseSink,
  920. DWORD FAR* rgdwConnection,
  921. IOleClientSite FAR* lpClientSite,
  922. IStorage FAR* lpStg,
  923. void FAR* FAR* lplpObj
  924. )
  925. {
  926. OLETRACEIN((API_OleCreateLinkToFileEx,
  927. PARAMFMT("lpszFileName= %ws, iid= %I, dwFlags= %x, renderopt= %x, cFormats= %x, rgAdvf= %te, rgFormatEtc= %p, lpAdviseSink= %p, rgdwConnection= %p, lpClientSite= %p, lpStg= %p, lplpObj= %p"),
  928. lpszFileName, &iid, dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj));
  929. VDATEHEAP();
  930. LPMONIKER lpmkFile = NULL;
  931. LPDATAOBJECT lpDataObject = NULL;
  932. HRESULT error;
  933. BOOL fPackagerMoniker = FALSE;
  934. CLSID clsidFile;
  935. LEDebugOut((DEB_TRACE, "%p _IN OleCreateLinkToFileEx ( \"%s\" , %p , %lx ,"
  936. " %lx , %lx , %p , %p , %p, %p , %p , %p , %p )\n", NULL, lpszFileName,
  937. &iid, dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink,
  938. rgdwConnection, lpClientSite, lpStg, lplpObj));
  939. VDATEPTROUT_LABEL( lplpObj, LPVOID, safeRtn, error );
  940. *lplpObj = NULL;
  941. VDATEPTRIN_LABEL( (LPVOID)lpszFileName, OLECHAR, logRtn, error );
  942. VDATEIID_LABEL( iid, logRtn, error );
  943. error = wValidateCreateParams(dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg);
  944. if (error != NOERROR)
  945. goto logRtn;
  946. if (((error = wGetMonikerAndClassFromFile(lpszFileName,
  947. TRUE /*fLink*/, &lpmkFile, &fPackagerMoniker, &clsidFile,&lpDataObject))
  948. != NOERROR))
  949. {
  950. goto logRtn;
  951. }
  952. Verify(lpmkFile);
  953. if (fPackagerMoniker) {
  954. // wValidateFormatEtc() will be done in wCreateFromFile()
  955. Assert(NULL == lpDataObject); // Shouldn't be a BoundDataObject for Packager.
  956. error = wCreateFromFileEx(lpmkFile,lpDataObject, iid, dwFlags, renderopt,
  957. cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection,
  958. lpClientSite, lpStg, lplpObj);
  959. } else {
  960. FORMATETC formatEtc;
  961. LPFORMATETC lpFormatEtc;
  962. BOOL fAlloced = FALSE;
  963. if ((error = wValidateFormatEtcEx(renderopt, &cFormats, rgFormatEtc,
  964. &formatEtc, &lpFormatEtc, &fAlloced)) != NOERROR)
  965. {
  966. goto ErrRtn;
  967. }
  968. error = wCreateLinkEx(lpmkFile, clsidFile, lpDataObject,
  969. iid, dwFlags, renderopt, cFormats, rgAdvf, lpFormatEtc,
  970. lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj);
  971. if (fAlloced)
  972. PubMemFree(lpFormatEtc);
  973. }
  974. ErrRtn:
  975. if (lpmkFile)
  976. {
  977. lpmkFile->Release();
  978. }
  979. // if the moniker was bound in CreateFromFile, release it now.
  980. if (lpDataObject)
  981. {
  982. lpDataObject->Release();
  983. }
  984. if (error == NOERROR && !lpAdviseSink) {
  985. wStuffIconOfFileEx(lpszFileName, TRUE /*fAddLabel*/,
  986. renderopt, cFormats, rgFormatEtc, (LPUNKNOWN) *lplpObj);
  987. }
  988. logRtn:
  989. LEDebugOut((DEB_TRACE, "%p OUT OleCreateLinkToFileEx ( %lx ) [ %p ]\n",
  990. NULL, error, *lplpObj));
  991. safeRtn:
  992. OLETRACEOUT((API_OleCreateLinkToFileEx, error));
  993. return error;
  994. }
  995. //+-------------------------------------------------------------------------
  996. //
  997. // Function: OleCreateFromFile
  998. //
  999. // Synopsis: Creates an ole object for embedding from a file (for
  1000. // InstertObject->From File type things)
  1001. //
  1002. // Effects:
  1003. //
  1004. // Arguments: [rclsid] -- CLSID to use for creating the object
  1005. // [lpszFileName] -- the filename
  1006. // [iid] -- the requested interface ID
  1007. // [renderopt] -- rendering options
  1008. // [lpFormatEtc] -- rendering format (if needed)
  1009. // [lpClientSite] -- pointer to the object's client site
  1010. // [lpStg] -- pointer to the storage for the object
  1011. // [lplpObj] -- where to put the pointer to the new object
  1012. //
  1013. // Requires:
  1014. //
  1015. // Returns: HRESULT
  1016. //
  1017. // Signals:
  1018. //
  1019. // Modifies:
  1020. //
  1021. // Algorithm:
  1022. //
  1023. // History: dd-mmm-yy Author Comment
  1024. // 16-Dec-94 alexgo added call tracing
  1025. // 28-Oct-93 alexgo 32bit port
  1026. //
  1027. // Notes:
  1028. //
  1029. //--------------------------------------------------------------------------
  1030. #pragma SEG(OleCreateFromFile)
  1031. STDAPI OleCreateFromFile
  1032. (
  1033. REFCLSID rclsid,
  1034. LPCOLESTR lpszFileName,
  1035. REFIID iid,
  1036. DWORD renderopt,
  1037. LPFORMATETC lpFormatEtc,
  1038. IOleClientSite FAR* lpClientSite,
  1039. IStorage FAR* lpStg,
  1040. void FAR* FAR* lplpObj
  1041. )
  1042. {
  1043. DWORD advf = ADVF_PRIMEFIRST;
  1044. return OleCreateFromFileEx(rclsid, lpszFileName, iid, 0, renderopt,
  1045. (lpFormatEtc ? 1 : 0), (lpFormatEtc ? &advf : NULL),
  1046. lpFormatEtc, NULL, NULL, lpClientSite, lpStg, lplpObj);
  1047. }
  1048. //+-------------------------------------------------------------------------
  1049. //
  1050. // Function: OleCreateFromFileEx
  1051. //
  1052. // Synopsis: Creates an ole object for embedding from a file (for
  1053. // InstertObject->From File type things)
  1054. //
  1055. // Effects:
  1056. //
  1057. // Arguments: [rclsid] -- CLSID to use for creating the object
  1058. // [lpszFileName] -- the filename
  1059. // [iid] -- the requested interface ID
  1060. // [dwFlags] -- object creation flags
  1061. // [renderopt] -- render options, such as OLERENDER_DRAW
  1062. // [cFormats] -- the number of elements in rgFormatEtc
  1063. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  1064. // is specified in renderopt
  1065. // [rgFormatEtc] -- array of rendering formats, if
  1066. // OLERENDER_FORMAT is specified in renderopt
  1067. // [lpAdviseSink] -- the advise sink for the object
  1068. // [rgdwConnection]-- where to put the connection IDs for the
  1069. // advisory connections
  1070. // [lpClientSite] -- pointer to the object's client site
  1071. // [lpStg] -- pointer to the storage for the object
  1072. // [lplpObj] -- where to put the pointer to the new object
  1073. //
  1074. // Requires:
  1075. //
  1076. // Returns: HRESULT
  1077. //
  1078. // Signals:
  1079. //
  1080. // Modifies:
  1081. //
  1082. // Algorithm:
  1083. //
  1084. // History: dd-mmm-yy Author Comment
  1085. // 16-Dec-94 alexgo added call tracing
  1086. // 28-Oct-93 alexgo 32bit port
  1087. //
  1088. // Notes:
  1089. //
  1090. //--------------------------------------------------------------------------
  1091. #pragma SEG(OleCreateFromFileEx)
  1092. STDAPI OleCreateFromFileEx
  1093. (
  1094. REFCLSID rclsid,
  1095. LPCOLESTR lpszFileName,
  1096. REFIID iid,
  1097. DWORD dwFlags,
  1098. DWORD renderopt,
  1099. ULONG cFormats,
  1100. DWORD FAR* rgAdvf,
  1101. LPFORMATETC rgFormatEtc,
  1102. IAdviseSink FAR* lpAdviseSink,
  1103. DWORD FAR* rgdwConnection,
  1104. IOleClientSite FAR* lpClientSite,
  1105. IStorage FAR* lpStg,
  1106. void FAR* FAR* lplpObj
  1107. )
  1108. {
  1109. OLETRACEIN((API_OleCreateFromFileEx,
  1110. PARAMFMT("rclsid= %I, lpszFileName= %ws, iid= %I, dwFlags= %x, renderopt= %x, cFormats= %x, rgAdvf= %te, rgFormatEtc= %p, lpAdviseSink= %p, rgdwConnection= %p, lpClientSite= %p, lpStg= %p, lplpObj= %p"),
  1111. &rclsid, lpszFileName, &iid, dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj));
  1112. VDATEHEAP();
  1113. LPMONIKER lpmkFile = NULL;
  1114. LPDATAOBJECT lpDataObject = NULL;
  1115. HRESULT error;
  1116. CLSID clsid;
  1117. LEDebugOut((DEB_TRACE, "%p _IN OleCreateFromFileEx ( %p , \"%s\" , %p ,"
  1118. " %lx , %lx , %lx , %p , %p , %p , %p , %p , %p , %p )\n", NULL,
  1119. &rclsid, lpszFileName, &iid, dwFlags, renderopt, cFormats, rgAdvf,
  1120. rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg,
  1121. lplpObj));
  1122. VDATEPTROUT_LABEL( lplpObj, LPVOID, safeRtn, error );
  1123. *lplpObj = NULL;
  1124. VDATEPTRIN_LABEL( (LPVOID)lpszFileName, char, errRtn, error );
  1125. VDATEIID_LABEL( iid, errRtn, error );
  1126. error = wValidateCreateParams(dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite, lpStg);
  1127. if (error != NOERROR)
  1128. goto errRtn;
  1129. if (((error = wGetMonikerAndClassFromFile(lpszFileName,
  1130. FALSE /*fLink*/, &lpmkFile, NULL /*lpfPackagerMoniker*/,
  1131. &clsid,&lpDataObject)) != NOERROR))
  1132. {
  1133. goto errRtn;
  1134. }
  1135. Verify(lpmkFile);
  1136. // wValidateFormatEtc() will be done in wCreateFromFile()
  1137. error = wCreateFromFileEx(lpmkFile,lpDataObject, iid, dwFlags, renderopt, cFormats,
  1138. rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite,
  1139. lpStg, lplpObj);
  1140. if (lpDataObject)
  1141. {
  1142. lpDataObject->Release();
  1143. }
  1144. if (lpmkFile)
  1145. {
  1146. lpmkFile->Release();
  1147. }
  1148. if (error == NOERROR && !lpAdviseSink) {
  1149. wStuffIconOfFileEx(lpszFileName, FALSE /*fAddLabel*/,
  1150. renderopt, cFormats, rgFormatEtc, (LPUNKNOWN) *lplpObj);
  1151. }
  1152. errRtn:
  1153. LEDebugOut((DEB_TRACE, "%p OUT OleCreateFromFileEx ( %lx ) [ %p ]\n",
  1154. NULL, error, *lplpObj));
  1155. safeRtn:
  1156. OLETRACEOUT((API_OleCreateFromFileEx, error));
  1157. return error;
  1158. }
  1159. //+-------------------------------------------------------------------------
  1160. //
  1161. // Function: OleDoAutoConvert
  1162. //
  1163. // Synopsis: Converts the storage to use the clsid given in
  1164. // [pClsidNew]. Private ole streams are updated with the new
  1165. // info
  1166. //
  1167. // Effects:
  1168. //
  1169. // Arguments: [pStg] -- storage to modify
  1170. // [pClsidNew] -- pointer to the new class ID
  1171. //
  1172. // Requires:
  1173. //
  1174. // Returns: HRESULT
  1175. //
  1176. // Signals:
  1177. //
  1178. // Modifies:
  1179. //
  1180. // Algorithm:
  1181. //
  1182. // History: dd-mmm-yy Author Comment
  1183. // 28-Oct-93 alexgo 32bit port
  1184. //
  1185. // Notes: REVIEW32: this function should be rewritten to use
  1186. // the new internal API for writing to ole-private streams
  1187. //
  1188. //--------------------------------------------------------------------------
  1189. #pragma SEG(OleDoAutoConvert)
  1190. STDAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew)
  1191. {
  1192. OLETRACEIN((API_OleDoAutoConvert, PARAMFMT("pStg= %p, pClsidNew= %I"),
  1193. pStg, pClsidNew));
  1194. VDATEHEAP();
  1195. HRESULT error;
  1196. CLSID clsidOld;
  1197. CLIPFORMAT cfOld;
  1198. LPOLESTR lpszOld = NULL;
  1199. LPOLESTR lpszNew = NULL;
  1200. if ((error = ReadClassStg(pStg, &clsidOld)) != NOERROR) {
  1201. clsidOld = CLSID_NULL;
  1202. goto errRtn;
  1203. }
  1204. if ((error = OleGetAutoConvert(clsidOld, pClsidNew)) != NOERROR)
  1205. goto errRtn;
  1206. // read old fmt/old user type; sets out params to NULL on error
  1207. error = ReadFmtUserTypeStg(pStg, &cfOld, &lpszOld);
  1208. Assert(error == NOERROR || (cfOld == NULL && lpszOld == NULL));
  1209. // get new user type name; if error, set to NULL string
  1210. if ((error = OleRegGetUserType(*pClsidNew, USERCLASSTYPE_FULL,
  1211. &lpszNew)) != NOERROR)
  1212. lpszNew = NULL;
  1213. // write class stg
  1214. if ((error = WriteClassStg(pStg, *pClsidNew)) != NOERROR)
  1215. goto errRtn;
  1216. // write old fmt/new user type;
  1217. if ((error = WriteFmtUserTypeStg(pStg, cfOld, lpszNew)) != NOERROR)
  1218. goto errRewriteInfo;
  1219. // set convert bit
  1220. if ((error = SetConvertStg(pStg, TRUE)) != NOERROR)
  1221. goto errRewriteInfo;
  1222. goto okRtn;
  1223. errRewriteInfo:
  1224. (void)WriteClassStg(pStg, clsidOld);
  1225. (void)WriteFmtUserTypeStg(pStg, cfOld, lpszOld);
  1226. errRtn:
  1227. *pClsidNew = clsidOld;
  1228. okRtn:
  1229. PubMemFree(lpszOld);
  1230. PubMemFree(lpszNew);
  1231. OLETRACEOUT((API_OleDoAutoConvert, error));
  1232. return error;
  1233. }
  1234. //+-------------------------------------------------------------------------
  1235. //
  1236. // Function: OleLoad
  1237. //
  1238. // Synopsis: Loads an object from the given storage
  1239. //
  1240. // Effects:
  1241. //
  1242. // Arguments: [lpStg] -- the storage to load from
  1243. // [iid] -- the requested interface ID
  1244. // [lpClientSite] -- client site for the object
  1245. // [lplpObj] -- where to put the pointer to the
  1246. // new object
  1247. //
  1248. // Requires:
  1249. //
  1250. // Returns: HRESULT
  1251. //
  1252. // Signals:
  1253. //
  1254. // Modifies:
  1255. //
  1256. // Algorithm:
  1257. //
  1258. // History: dd-mmm-yy Author Comment
  1259. // 16-Dec-94 alexgo added call tracing
  1260. // 28-Oct-93 alexgo 32bit port
  1261. //
  1262. // Notes:
  1263. //
  1264. //--------------------------------------------------------------------------
  1265. #pragma SEG(OleLoad)
  1266. STDAPI OleLoad
  1267. (
  1268. IStorage FAR* lpStg,
  1269. REFIID iid,
  1270. IOleClientSite FAR* lpClientSite,
  1271. void FAR* FAR* lplpObj
  1272. )
  1273. {
  1274. OLETRACEIN((API_OleLoad, PARAMFMT("lpStg= %p, iid= %I, lpClientSite= %p, lplpObj= %p"),
  1275. lpStg, &iid, lpClientSite, lplpObj));
  1276. VDATEHEAP();
  1277. HRESULT error;
  1278. LEDebugOut((DEB_TRACE, "%p _IN OleLoad ( %p , %p , %p , %p )\n",
  1279. NULL, lpStg, &iid, lpClientSite, lplpObj));
  1280. if ((error = OleLoadWithoutBinding(lpStg, FALSE, iid, lpClientSite, lplpObj))
  1281. == NOERROR) {
  1282. // The caller specify that he want a disconnected object by
  1283. // passing NULL for pClientSite
  1284. if (lpClientSite != NULL)
  1285. wBindIfRunning((LPUNKNOWN) *lplpObj);
  1286. }
  1287. LEDebugOut((DEB_TRACE, "%p OUT OleLoad ( %lx ) [ %p ]\n", NULL, error,
  1288. (error == NOERROR ? *lplpObj : NULL)));
  1289. OLETRACEOUT((API_OleLoad, error));
  1290. return error;
  1291. }
  1292. //+-------------------------------------------------------------------------
  1293. //
  1294. // Function: OleLoadWithoutBinding
  1295. //
  1296. // Synopsis: Internal function to load/create an object from a storage
  1297. // called by OleLoad, etc.
  1298. //
  1299. // Effects:
  1300. //
  1301. // Arguments: [lpStg] -- storage to load from
  1302. // [iid] -- requested interface ID
  1303. // [lpClientSite] -- pointer to the client site
  1304. // [lplpObj] -- where to put the pointer to the object
  1305. //
  1306. // Requires:
  1307. //
  1308. // Returns: HRESULT
  1309. //
  1310. // Signals:
  1311. //
  1312. // Modifies:
  1313. //
  1314. // Algorithm:
  1315. //
  1316. // History: dd-mmm-yy Author Comment
  1317. // 28-Oct-93 alexgo 32bit port
  1318. //
  1319. // Notes: REVIEW32: this function is only used in a few, known
  1320. // places. we can maybe get rid of the VDATEPTR's.
  1321. //
  1322. //--------------------------------------------------------------------------
  1323. INTERNAL OleLoadWithoutBinding
  1324. (
  1325. IStorage FAR* lpStg,
  1326. BOOL fPermitCodeDownload, //new parameter to control whether code download occurs or not -RahulTh (11/20/97)
  1327. REFIID iid,
  1328. IOleClientSite FAR* lpClientSite,
  1329. void FAR* FAR* lplpObj
  1330. )
  1331. {
  1332. VDATEHEAP();
  1333. HRESULT error;
  1334. CLSID clsid;
  1335. VDATEPTROUT( lplpObj, LPVOID );
  1336. *lplpObj = NULL;
  1337. VDATEIID( iid );
  1338. VDATEIFACE( lpStg );
  1339. if (lpClientSite)
  1340. VDATEIFACE( lpClientSite );
  1341. error = OleDoAutoConvert(lpStg, &clsid);
  1342. // error only used when clsid could not be read (when CLSID_NULL)
  1343. if (IsEqualCLSID(clsid, CLSID_NULL))
  1344. return error;
  1345. return wCreateObject (clsid, fPermitCodeDownload, iid, lpClientSite, lpStg, STG_LOAD,
  1346. lplpObj);
  1347. }
  1348. //+-------------------------------------------------------------------------
  1349. //
  1350. // Function: OleCreateStaticFromData
  1351. //
  1352. // Synopsis: Creates a static ole object from the data in [lpSrcDataObject]
  1353. // If [lpFormatEtcIn] is NULL, then the best possible
  1354. // presentation is extracted.
  1355. //
  1356. // Effects:
  1357. //
  1358. // Arguments: [lpSrcDataObj] -- pointer to the data object
  1359. // [iid] -- requested interface ID for the new object
  1360. // [renderopt] -- redering options
  1361. // [lpClientSite] -- pointer to the client site
  1362. // [lpStg] -- pointer to the storage for the object
  1363. // [lplpObj] -- where to put the pointer to the object
  1364. //
  1365. // Requires:
  1366. //
  1367. // Returns: HRESULT
  1368. //
  1369. // Signals:
  1370. //
  1371. // Modifies:
  1372. //
  1373. // Algorithm:
  1374. //
  1375. // History: dd-mmm-yy Author Comment
  1376. // 16-Dec-94 alexgo added call tracing
  1377. // 08-Jun-94 davepl Added EMF support
  1378. // 28-Oct-93 alexgo 32bit port
  1379. //
  1380. //--------------------------------------------------------------------------
  1381. #pragma SEG(OleCreateStaticFromData)
  1382. STDAPI OleCreateStaticFromData(
  1383. IDataObject FAR* lpSrcDataObj,
  1384. REFIID iid,
  1385. DWORD renderopt,
  1386. LPFORMATETC lpFormatEtcIn,
  1387. IOleClientSite FAR* lpClientSite,
  1388. IStorage FAR* lpStg,
  1389. void FAR* FAR* lplpObj
  1390. )
  1391. {
  1392. OLETRACEIN((API_OleCreateStaticFromData,
  1393. PARAMFMT("lpSrcDataObj= %p, iid= %I, renderopt= %x, lpFormatEtcIn= %te, lpClientSite= %p, lpStg= %p, lplpObj= %p"),
  1394. lpSrcDataObj, &iid, renderopt, lpFormatEtcIn, lpClientSite, lpStg, lplpObj));
  1395. VDATEHEAP();
  1396. IOleObject FAR* lpOleObj = NULL;
  1397. IOleCache FAR* lpOleCache = NULL;
  1398. HRESULT error;
  1399. FORMATETC foretc;
  1400. FORMATETC foretcCache;
  1401. STGMEDIUM stgmed;
  1402. CLSID clsid;
  1403. BOOL fReleaseStgMed = TRUE;
  1404. LPOLESTR lpszUserType = NULL;
  1405. LEDebugOut((DEB_TRACE, "%p _IN OleCreateStaticFromData ( %p , %p , %lx ,"
  1406. " %p , %p , %p , %p , %p )\n", NULL, lpSrcDataObj, &iid, renderopt,
  1407. lpFormatEtcIn, lpClientSite, lpStg, lplpObj));
  1408. VDATEPTROUT_LABEL(lplpObj, LPVOID, safeRtn, error);
  1409. *lplpObj = NULL;
  1410. VDATEIFACE_LABEL( lpSrcDataObj, logRtn, error );
  1411. VDATEIID_LABEL(iid, logRtn, error);
  1412. //VDATEPTRIN rejects NULL
  1413. if ( lpFormatEtcIn )
  1414. VDATEPTRIN_LABEL( lpFormatEtcIn, FORMATETC, logRtn, error );
  1415. VDATEIFACE_LABEL(lpStg, logRtn, error);
  1416. if (lpClientSite)
  1417. VDATEIFACE_LABEL(lpClientSite, logRtn, error);
  1418. if (renderopt == OLERENDER_NONE || renderopt == OLERENDER_ASIS)
  1419. {
  1420. error = E_INVALIDARG;
  1421. goto logRtn;
  1422. }
  1423. if ((error = wValidateFormatEtc (renderopt, lpFormatEtcIn, &foretc))
  1424. != NOERROR)
  1425. {
  1426. goto logRtn;
  1427. }
  1428. if (renderopt == OLERENDER_DRAW)
  1429. {
  1430. if (!UtQueryPictFormat(lpSrcDataObj, &foretc))
  1431. {
  1432. error = DV_E_CLIPFORMAT;
  1433. goto logRtn;
  1434. }
  1435. }
  1436. // Set the proper CLSID, or return error if that isn't possible
  1437. if (foretc.cfFormat == CF_METAFILEPICT)
  1438. {
  1439. clsid = CLSID_StaticMetafile;
  1440. }
  1441. else if (foretc.cfFormat == CF_BITMAP || foretc.cfFormat == CF_DIB)
  1442. {
  1443. clsid = CLSID_StaticDib;
  1444. }
  1445. else if (foretc.cfFormat == CF_ENHMETAFILE)
  1446. {
  1447. clsid = CLSID_Picture_EnhMetafile;
  1448. }
  1449. else
  1450. {
  1451. error = DV_E_CLIPFORMAT;
  1452. goto logRtn;
  1453. }
  1454. error = lpSrcDataObj->GetData(&foretc, &stgmed);
  1455. if (NOERROR != error)
  1456. {
  1457. // We should support the case where the caller wants one of
  1458. // CF_BITMAP and CF_DIB, and the object supports the other
  1459. // one those 2 formats. In this case we should do the proper
  1460. // conversion. Finally the cache that is going to be created
  1461. // would be a DIB cache.
  1462. AssertOutStgmedium(error, &stgmed);
  1463. if (foretc.cfFormat == CF_DIB)
  1464. {
  1465. foretc.cfFormat = CF_BITMAP;
  1466. foretc.tymed = TYMED_GDI;
  1467. }
  1468. else if (foretc.cfFormat == CF_BITMAP)
  1469. {
  1470. foretc.cfFormat = CF_DIB;
  1471. foretc.tymed = TYMED_HGLOBAL;
  1472. }
  1473. else
  1474. {
  1475. goto logRtn;
  1476. }
  1477. error = lpSrcDataObj->GetData(&foretc, &stgmed);
  1478. if (NOERROR != error)
  1479. {
  1480. AssertOutStgmedium(error, &stgmed);
  1481. goto logRtn;
  1482. }
  1483. }
  1484. AssertOutStgmedium(error, &stgmed);
  1485. foretcCache = foretc;
  1486. foretcCache.dwAspect = foretc.dwAspect = DVASPECT_CONTENT;
  1487. foretcCache.ptd = NULL;
  1488. // Even when the caller asks for bitmap cache we create the DIB cache.
  1489. BITMAP_TO_DIB(foretcCache);
  1490. error = wCreateObject (clsid, FALSE,
  1491. IID_IOleObject, lpClientSite,
  1492. lpStg, STG_INITNEW, (LPLPVOID) &lpOleObj);
  1493. if (NOERROR != error)
  1494. {
  1495. goto errRtn;
  1496. }
  1497. if (lpOleObj->QueryInterface(IID_IOleCache, (LPLPVOID) &lpOleCache)
  1498. != NOERROR)
  1499. {
  1500. goto errRtn;
  1501. }
  1502. error = lpOleCache->Cache (&foretcCache, ADVF_PRIMEFIRST,
  1503. NULL /*pdwConnection*/);
  1504. if (FAILED(error))
  1505. {
  1506. goto errRtn;
  1507. }
  1508. //REVIEW32: err, are we sure this is a good idea???
  1509. //clearing out the error, that is
  1510. error = NOERROR;
  1511. // take ownership of the data
  1512. foretc.ptd = NULL;
  1513. if ((error = lpOleCache->SetData (&foretc, &stgmed,
  1514. TRUE)) != NOERROR)
  1515. goto errRtn;
  1516. // Write format and user type
  1517. error = lpOleObj->GetUserType(USERCLASSTYPE_FULL, &lpszUserType);
  1518. AssertOutPtrParam(error, lpszUserType);
  1519. WriteFmtUserTypeStg(lpStg, foretcCache.cfFormat, lpszUserType);
  1520. if (lpszUserType)
  1521. PubMemFree(lpszUserType);
  1522. fReleaseStgMed = FALSE;
  1523. error = lpOleObj->QueryInterface (iid, lplpObj);
  1524. errRtn:
  1525. if (fReleaseStgMed)
  1526. ReleaseStgMedium(&stgmed);
  1527. if (lpOleCache)
  1528. lpOleCache->Release();
  1529. if (error != NOERROR && *lplpObj) {
  1530. ((IUnknown FAR*) *lplpObj)->Release();
  1531. *lplpObj = NULL;
  1532. }
  1533. if (lpOleObj)
  1534. lpOleObj->Release();
  1535. logRtn:
  1536. LEDebugOut((DEB_TRACE, "%p OUT OleCreateStaticFromData ( %lx ) [ %p ]\n",
  1537. NULL, error, *lplpObj));
  1538. safeRtn:
  1539. OLETRACEOUT((API_OleCreateStaticFromData, error));
  1540. return error;
  1541. }
  1542. //+-------------------------------------------------------------------------
  1543. //
  1544. // Function: OleQueryCreateFromData
  1545. //
  1546. // Synopsis: Finds out what we can create from a data object (if anything)
  1547. //
  1548. // Effects:
  1549. //
  1550. // Arguments: [lpSrcDataObj] -- pointer to the data object of interest
  1551. //
  1552. // Requires:
  1553. //
  1554. // Returns: NOERROR -- an OLE object can be created
  1555. // QUERY_CREATE_STATIC -- a static object can be created
  1556. // S_FALSE -- nothing can be created
  1557. //
  1558. // Signals:
  1559. //
  1560. // Modifies:
  1561. //
  1562. // Algorithm:
  1563. //
  1564. // History: dd-mmm-yy Author Comment
  1565. // 28-Oct-93 alexgo 32bit port
  1566. //
  1567. // Notes:
  1568. //
  1569. //--------------------------------------------------------------------------
  1570. #pragma SEG(OleQueryCreateFromData)
  1571. STDAPI OleQueryCreateFromData (LPDATAOBJECT lpSrcDataObj)
  1572. {
  1573. OLETRACEIN((API_OleQueryCreateFromData, PARAMFMT("lpSrcDataObj= %p"), lpSrcDataObj));
  1574. VDATEHEAP();
  1575. VDATEIFACE( lpSrcDataObj );
  1576. CALLHOOKOBJECT(S_OK,CLSID_NULL,IID_IDataObject,(IUnknown **)&lpSrcDataObj);
  1577. CLIPFORMAT cfFormat;
  1578. WORD wStatus = wQueryEmbedFormats(lpSrcDataObj, &cfFormat);
  1579. HRESULT hr;
  1580. if (wStatus & QUERY_CREATE_OLE)
  1581. // OLE object can be created
  1582. hr = NOERROR;
  1583. else if (wStatus & QUERY_CREATE_STATIC)
  1584. // static object can be created
  1585. hr = ResultFromScode(OLE_S_STATIC);
  1586. else // no object can be created
  1587. hr = ResultFromScode(S_FALSE);
  1588. OLETRACEOUT((API_OleQueryCreateFromData, hr));
  1589. return hr;
  1590. }
  1591. //+-------------------------------------------------------------------------
  1592. //
  1593. // Function: wQueryEmbedFormats
  1594. //
  1595. // Synopsis: Enumerates the formats of the object and looks for
  1596. // ones that let us create either an embeded or static object
  1597. //
  1598. // Effects:
  1599. //
  1600. // Arguments: [lpSrcDataObj] -- pointer to the data object
  1601. // [lpcfFormat] -- place to put the clipboard format
  1602. // of the object
  1603. // Returns: WORD -- bit flag of QUERY_CREATE_NONE, QUERY_CREATE_STATIC
  1604. // and QUERY_CREATE_OLE
  1605. //
  1606. // History: dd-mmm-yy Author Comment
  1607. // 28-Oct-93 alexgo 32bit port
  1608. // 08-Jun-94 davepl Optimized by unwinding while() loop
  1609. // 22-Aug-94 alexgo added MFC hack
  1610. //
  1611. //--------------------------------------------------------------------------
  1612. static const unsigned int MAX_ENUM_STEP = 20;
  1613. INTERNAL_(WORD) wQueryEmbedFormats
  1614. (
  1615. LPDATAOBJECT lpSrcDataObj,
  1616. CLIPFORMAT FAR* lpcfFormat
  1617. )
  1618. {
  1619. VDATEHEAP();
  1620. // This adjusts the number of formats requested per enumeration
  1621. // step. If we are running in the WOW box, we should only ask
  1622. // for one at a time since it is unknown how well old code will
  1623. // support bulk enumerations.
  1624. ULONG ulEnumSize = IsWOWThread() ? 1 : MAX_ENUM_STEP;
  1625. FORMATETC fetcarray[MAX_ENUM_STEP];
  1626. IEnumFORMATETC FAR* penm;
  1627. ULONG ulNumFetched;
  1628. HRESULT error;
  1629. WORD wStatus = QUERY_CREATE_NONE;
  1630. // no object can be created
  1631. BOOL fDone = FALSE;
  1632. *lpcfFormat = NULL;
  1633. // Grab the enumerator. If this fails, just return
  1634. // QUERY_CREATE_NONE
  1635. error = wGetEnumFormatEtc(lpSrcDataObj, DATADIR_GET, &penm);
  1636. if (error != NOERROR)
  1637. {
  1638. return QUERY_CREATE_NONE;
  1639. }
  1640. // Enumerate over the formats available in chunks for ulEnumSize. For
  1641. // each format we were able to grab, check to see if the clipformat
  1642. // indicates that we have a creation candidate (static or otherwise),
  1643. // and set bits in the bitmask as appropriate
  1644. while (!fDone && (SUCCEEDED(penm->Next(ulEnumSize, fetcarray, &ulNumFetched))))
  1645. {
  1646. // We will normally get at least one, unless there are 0,
  1647. // ulEnumSize, 2*ulEnumSize, and so on...
  1648. if (ulNumFetched == 0)
  1649. break;
  1650. for (ULONG c=0; c<ulNumFetched; c++)
  1651. {
  1652. // We care not about the target device
  1653. if (NULL != fetcarray[c].ptd)
  1654. {
  1655. PubMemFree(fetcarray[c].ptd);
  1656. }
  1657. CLIPFORMAT cf = fetcarray[c].cfFormat;
  1658. // In these cases it is an internal
  1659. // format which is a candidate for
  1660. // OLE creation directly.
  1661. if (cf == g_cfEmbedSource ||
  1662. cf == g_cfEmbeddedObject ||
  1663. cf == g_cfFileName ||
  1664. cf == g_cfFileNameW)
  1665. {
  1666. wStatus |= QUERY_CREATE_OLE;
  1667. *lpcfFormat = cf;
  1668. fDone = TRUE;
  1669. break;
  1670. }
  1671. // These formats indicate it is a
  1672. // candidate for static creation.
  1673. else if (cf == CF_METAFILEPICT ||
  1674. cf == CF_DIB ||
  1675. cf == CF_BITMAP ||
  1676. cf == CF_ENHMETAFILE)
  1677. {
  1678. wStatus = QUERY_CREATE_STATIC;
  1679. *lpcfFormat = cf;
  1680. }
  1681. } // end for
  1682. if (fDone)
  1683. {
  1684. // Starting at the _next_ formatetc, free up
  1685. // any remaining target devices among the
  1686. // fetcs we got in the enumeration step.
  1687. for (++c; c<ulNumFetched; c++)
  1688. {
  1689. if(fetcarray[c].ptd)
  1690. {
  1691. PubMemFree(fetcarray[c].ptd);
  1692. }
  1693. }
  1694. }
  1695. } // end while
  1696. if (!(wStatus & QUERY_CREATE_OLE))
  1697. {
  1698. // MFC HACK ALERT!! MFC3.0 used to re-implement
  1699. // OleQueryCreateFromData themselves because they did not
  1700. // want to make the QI RPC below. Since they do a great
  1701. // many of these calls, making the RPC can be expensive
  1702. // and destabilising for them (as this hack is being put
  1703. // in just weeks before final release of Windows NT 3.5).
  1704. //
  1705. // Note that this changes the behaviour of clipboard from
  1706. // 16bit. You will no longer know that you can paste objects
  1707. // that only support IPersistStorage but offer no data in
  1708. // in their IDataOjbect implementation.
  1709. CClipDataObject ClipDataObject; // just allocate one of these
  1710. // on the stack. We won't
  1711. // do any real work with
  1712. // this except look at the
  1713. // vtable.
  1714. IPersistStorage FAR* lpPS;
  1715. // MFC HACK (continued): If we are working with a clipboard
  1716. // data object, then we do not want to make the QI call
  1717. // below. We determine if the given data object is a
  1718. // clipboard data object by comparing vtable addresses.
  1719. // REVIEW: this will potentially break if we make all objects
  1720. // use the same IUnknown implementation
  1721. if( (*(DWORD *)lpSrcDataObj) !=
  1722. (*(DWORD *)((IDataObject *)&ClipDataObject)) )
  1723. {
  1724. if (lpSrcDataObj->QueryInterface(IID_IPersistStorage,
  1725. (LPLPVOID)&lpPS) == NOERROR)
  1726. {
  1727. lpPS->Release();
  1728. wStatus |= QUERY_CREATE_OLE;
  1729. // OLE object can be created
  1730. }
  1731. }
  1732. }
  1733. penm->Release();
  1734. return wStatus;
  1735. }
  1736. //+-------------------------------------------------------------------------
  1737. //
  1738. // Function: OleQueryLinkFromData
  1739. //
  1740. // Synopsis: Calls wQueryLinkFormats to determine if a link could be
  1741. // created from this data object.
  1742. //
  1743. // Arguments: [lpSrcDataObj] -- the data object
  1744. //
  1745. // Returns: NOERROR, if a link can be created, S_FALSE otherwise
  1746. //
  1747. // History: dd-mmm-yy Author Comment
  1748. // 28-Oct-93 alexgo 32bit port
  1749. //
  1750. //--------------------------------------------------------------------------
  1751. STDAPI OleQueryLinkFromData (LPDATAOBJECT lpSrcDataObj)
  1752. {
  1753. OLETRACEIN((API_OleQueryLinkFromData, PARAMFMT("lpSrcDataObj= %p"),
  1754. lpSrcDataObj));
  1755. VDATEHEAP();
  1756. VDATEIFACE( lpSrcDataObj );
  1757. CALLHOOKOBJECT(S_OK,CLSID_NULL,IID_IDataObject,(IUnknown **)&lpSrcDataObj);
  1758. HRESULT hr = NOERROR;
  1759. if(wQueryLinkFormats(lpSrcDataObj) == NULL)
  1760. {
  1761. hr = ResultFromScode(S_FALSE);
  1762. }
  1763. OLETRACEOUT((API_OleQueryLinkFromData, hr));
  1764. return hr;
  1765. }
  1766. //+-------------------------------------------------------------------------
  1767. //
  1768. // Function: wQueryLinkFormats
  1769. //
  1770. // Synopsis: Enumerates the formats of a data object to see if
  1771. // a link object could be created from one of them
  1772. //
  1773. // Arguments: [lpSrcDataObj] -- pointer to the data object
  1774. //
  1775. // Returns: CLIPFORMAT of the data in the object that would enable
  1776. // link object creation.
  1777. //
  1778. // History: dd-mmm-yy Author Comment
  1779. // 28-Oct-93 alexgo 32bit port
  1780. // 14-Jun-94 davepl Added bulk enumeration for non-Wow runs
  1781. //
  1782. //--------------------------------------------------------------------------
  1783. INTERNAL_(CLIPFORMAT) wQueryLinkFormats(LPDATAOBJECT lpSrcDataObj)
  1784. {
  1785. VDATEHEAP();
  1786. // This adjusts the number of formats requested per enumeration
  1787. // step. If we are running in the WOW box, we should only ask
  1788. // for one at a time since it is unknown how well old code will
  1789. // support bulk enumerations.
  1790. ULONG ulEnumSize = IsWOWThread() ? 1 : MAX_ENUM_STEP;
  1791. FORMATETC fetcarray[MAX_ENUM_STEP];
  1792. IEnumFORMATETC FAR* penm;
  1793. ULONG ulNumFetched;
  1794. HRESULT error;
  1795. BOOL fDone = FALSE;
  1796. CLIPFORMAT cf = 0;
  1797. // Grab the enumerator. If this fails, just return
  1798. // QUERY_CREATE_NONE
  1799. error = wGetEnumFormatEtc(lpSrcDataObj, DATADIR_GET, &penm);
  1800. if (error != NOERROR)
  1801. {
  1802. return (CLIPFORMAT) 0;
  1803. }
  1804. // Enumerate over the formats available in chunks for ulEnumSize. For
  1805. // each format we were able to grab, check to see if the clipformat
  1806. // indicates that we have a creation candidate (static or otherwise),
  1807. // and set bits in the bitmask as appropriate
  1808. while (!fDone && (SUCCEEDED(penm->Next(ulEnumSize, fetcarray, &ulNumFetched))))
  1809. {
  1810. // We will normally get at least one, unless there are 0,
  1811. // ulEnumSize, 2*ulEnumSize, and so on...
  1812. if (ulNumFetched == 0)
  1813. break;
  1814. for (ULONG c=0; c<ulNumFetched; c++)
  1815. {
  1816. // We care not about the target device
  1817. if (NULL != fetcarray[c].ptd)
  1818. {
  1819. PubMemFree(fetcarray[c].ptd);
  1820. }
  1821. CLIPFORMAT cfTemp = fetcarray[c].cfFormat;
  1822. // In these cases it is an internal
  1823. // format which is a candidate for
  1824. // OLE creation directly.
  1825. if (cfTemp == g_cfLinkSource ||
  1826. cfTemp == g_cfFileName ||
  1827. cfTemp == g_cfFileNameW)
  1828. {
  1829. cf = cfTemp;
  1830. fDone = TRUE;
  1831. break;
  1832. }
  1833. } // end for
  1834. if (fDone)
  1835. {
  1836. // Starting at the _next_ formatetc, free up
  1837. // any remaining target devices among the
  1838. // fetcs we got in the enumeration step.
  1839. for (++c; c<ulNumFetched; c++)
  1840. {
  1841. if(fetcarray[c].ptd)
  1842. {
  1843. PubMemFree(fetcarray[c].ptd);
  1844. }
  1845. }
  1846. } // end if
  1847. } // end while
  1848. penm->Release();
  1849. return cf;
  1850. }
  1851. //+-------------------------------------------------------------------------
  1852. //
  1853. // Function: wClearRelativeMoniker
  1854. //
  1855. // Synopsis: Replaces an old relative moniker with the absolute moniker
  1856. // Internal function
  1857. //
  1858. // Effects:
  1859. //
  1860. // Arguments: [pInitObj] -- the original object
  1861. // [pNewObj] -- the object to which to set the new
  1862. // absolute moniker
  1863. //
  1864. // Requires:
  1865. //
  1866. // Returns: void
  1867. //
  1868. // Signals:
  1869. //
  1870. // Modifies:
  1871. //
  1872. // Algorithm:
  1873. //
  1874. // History: dd-mmm-yy Author Comment
  1875. // 28-Oct-93 alexgo 32bit port
  1876. //
  1877. // Notes:
  1878. //
  1879. //--------------------------------------------------------------------------
  1880. #pragma SEG(wClearRelativeMoniker)
  1881. INTERNAL_(void) wClearRelativeMoniker
  1882. (LPUNKNOWN pInitObj,
  1883. LPUNKNOWN pNewObj)
  1884. {
  1885. VDATEHEAP();
  1886. LPOLELINK pOleLink = NULL;
  1887. LPMONIKER pmkAbsolute = NULL;
  1888. CLSID clsidLink = CLSID_NULL;
  1889. LPOLEOBJECT pOleObj=NULL;
  1890. if (NOERROR==pInitObj->QueryInterface (IID_IOleLink,
  1891. (LPLPVOID) &pOleLink))
  1892. {
  1893. // Get absolute moniker ...
  1894. pOleLink->GetSourceMoniker (&pmkAbsolute);
  1895. Assert(pmkAbsolute == NULL || IsValidInterface(pmkAbsolute));
  1896. if (NOERROR==pInitObj->QueryInterface (IID_IOleObject,
  1897. (LPLPVOID) &pOleObj))
  1898. {
  1899. // .. and its class
  1900. pOleObj->GetUserClassID (&clsidLink);
  1901. pOleObj->Release();
  1902. pOleObj = NULL;
  1903. }
  1904. pOleLink->Release();
  1905. pOleLink = NULL;
  1906. }
  1907. if (pmkAbsolute &&
  1908. NOERROR==pNewObj->QueryInterface (IID_IOleLink,
  1909. (LPLPVOID) &pOleLink))
  1910. {
  1911. // Restore the absolute moniker. This will effectively
  1912. // overwrite the old relative moniker.
  1913. // This is important because when copying and pasting a link
  1914. // object between documents, the relative moniker is never
  1915. // correct. Sometimes, though, it might happen to bind
  1916. // to a different object, which is confusing to say the least.
  1917. pOleLink->SetSourceMoniker (pmkAbsolute, clsidLink);
  1918. }
  1919. if (pOleLink)
  1920. pOleLink->Release();
  1921. if (pOleObj)
  1922. pOleObj->Release();
  1923. if (pmkAbsolute)
  1924. pmkAbsolute->Release();
  1925. }
  1926. //+-------------------------------------------------------------------------
  1927. //
  1928. // Function: wCreateFromDataEx
  1929. //
  1930. // Synopsis: This function does the real work of creating from data.
  1931. // Basically, the data is GetData'ed from the data object,
  1932. // copied into a storage, and then loaded
  1933. //
  1934. // Effects:
  1935. //
  1936. // Arguments: [lpSrcDataObj] -- pointer to the data object
  1937. // [iid] -- requested interface
  1938. // [dwFlags] -- object creation flags
  1939. // [renderopt] -- render options, such as OLERENDER_DRAW
  1940. // [cFormats] -- the number of elements in rgFormatEtc
  1941. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  1942. // is specified in renderopt
  1943. // [rgFormatEtc] -- array of rendering formats, if
  1944. // OLERENDER_FORMAT is specified in renderopt
  1945. // [lpAdviseSink] -- the advise sink for the object
  1946. // [rgdwConnection]-- where to put the connection IDs for the
  1947. // advisory connections
  1948. // [lpClientSite] -- pointer to the client site
  1949. // [lpStg] -- pointer to the storage for the object
  1950. // [lplpObj] -- where to put the pointer to the object
  1951. //
  1952. // Requires:
  1953. //
  1954. // Returns: HRESULT
  1955. //
  1956. // Signals:
  1957. //
  1958. // Modifies:
  1959. //
  1960. // Algorithm:
  1961. //
  1962. // History: dd-mmm-yy Author Comment
  1963. // 28-Oct-93 alexgo 32bit port
  1964. //
  1965. // Notes:
  1966. //
  1967. //--------------------------------------------------------------------------
  1968. #pragma SEG(wCreateFromDataEx)
  1969. INTERNAL wCreateFromDataEx
  1970. (
  1971. IDataObject FAR* lpSrcDataObj,
  1972. REFIID iid,
  1973. DWORD dwFlags,
  1974. DWORD renderopt,
  1975. ULONG cFormats,
  1976. DWORD FAR* rgAdvf,
  1977. LPFORMATETC rgFormatEtc,
  1978. IAdviseSink FAR* lpAdviseSink,
  1979. DWORD FAR* rgdwConnection,
  1980. IOleClientSite FAR* lpClientSite,
  1981. IStorage FAR* lpStg,
  1982. void FAR* FAR* lplpObj
  1983. )
  1984. {
  1985. VDATEHEAP();
  1986. #define OLE_TEMP_STG "\1OleTempStg"
  1987. HRESULT error = NOERROR;
  1988. IPersistStorage FAR* lpPS = NULL;
  1989. FORMATETC formatEtc;
  1990. LPFORMATETC lpFormatEtc;
  1991. BOOL fAlloced = FALSE;
  1992. FORMATETC foretcTmp;
  1993. STGMEDIUM medTmp;
  1994. if ((error = wValidateFormatEtcEx(renderopt, &cFormats, rgFormatEtc,
  1995. &formatEtc, &lpFormatEtc, &fAlloced)) != NOERROR)
  1996. {
  1997. return error;
  1998. }
  1999. *lplpObj = NULL;
  2000. INIT_FORETC(foretcTmp);
  2001. medTmp.pUnkForRelease = NULL;
  2002. // try to get "EmbeddedObject" data
  2003. LPSTORAGE lpstgSrc = NULL;
  2004. foretcTmp.cfFormat = g_cfEmbeddedObject;
  2005. foretcTmp.tymed = TYMED_ISTORAGE;
  2006. if (lpSrcDataObj->QueryGetData(&foretcTmp) != NOERROR)
  2007. goto Next;
  2008. if ((error = StgCreateDocfile (NULL,
  2009. STGM_SALL|STGM_CREATE|STGM_DELETEONRELEASE,
  2010. NULL, &lpstgSrc)) != NOERROR)
  2011. goto errRtn;
  2012. medTmp.tymed = TYMED_ISTORAGE;
  2013. medTmp.pstg = lpstgSrc;
  2014. if ((error = lpSrcDataObj->GetDataHere(&foretcTmp, &medTmp))
  2015. == NOERROR)
  2016. {
  2017. // lpSrcDataObj passed to this api is a wrapper object
  2018. // (which offers g_cfEmbeddedObject) for the original
  2019. // embedded object. Now we got the original embedded object
  2020. // data into medTmp.pstg.
  2021. // copy the source data into lpStg.
  2022. if ((error = lpstgSrc->CopyTo (0, NULL, NULL, lpStg))
  2023. != NOERROR)
  2024. goto errEmbeddedObject;
  2025. // By doing the following we will be getting a data object
  2026. // pointer to original embedded object, which we can use to
  2027. // initialize the cache of the object that we are going to
  2028. // create. We can not use the lpSrcDataObj passed to this api,
  2029. // 'cause the presentation data that it may give through the
  2030. // GetData call may be the one that it generated for the
  2031. // object. (ex: the container can create an object with
  2032. // olerender_none an then draw it's own representaion
  2033. // (icon, etc) for the object.
  2034. LPDATAOBJECT lpInitDataObj = NULL;
  2035. // We pass a NULL client site so we know wClearRelativeMoniker
  2036. // will be able to get the absolute moniker, not the relative.
  2037. if ((error = OleLoadWithoutBinding (lpstgSrc, FALSE,
  2038. IID_IDataObject,
  2039. /*lpClientSite*/NULL, (LPLPVOID) &lpInitDataObj))
  2040. != NOERROR)
  2041. goto errEmbeddedObject;
  2042. if (renderopt != OLERENDER_ASIS )
  2043. UtDoStreamOperation(lpStg, /* pstgSrc */
  2044. NULL, /* pstgDst */
  2045. OPCODE_REMOVE, /* operation to performed */
  2046. STREAMTYPE_CACHE);
  2047. /* stream to be operated upon */
  2048. error = wLoadAndInitObjectEx(lpInitDataObj, iid, renderopt,
  2049. cFormats, rgAdvf, lpFormatEtc, lpAdviseSink, rgdwConnection,
  2050. lpClientSite, lpStg, lplpObj);
  2051. if (NOERROR==error)
  2052. wClearRelativeMoniker (lpInitDataObj,
  2053. (LPUNKNOWN)*lplpObj);
  2054. if (lpInitDataObj)
  2055. lpInitDataObj->Release();
  2056. // HACK ALERT!! If wLoadAndInitObject failed, it may have been
  2057. // because the little trick above with OleLoadWithoutBinding doesn't
  2058. // work with all objects. Some OLE1 objects (Clipart Gallery in
  2059. // particular) don't like offer presentions without being edited.
  2060. //
  2061. // So if there was an error, we'll just try again with the *real*
  2062. // data object passed into us. Needless to say, it would be much
  2063. // nicer to do this in the first place, but that breaks the old
  2064. // behavior.
  2065. if( error != NOERROR )
  2066. {
  2067. error = wLoadAndInitObjectEx( lpSrcDataObj, iid, renderopt,
  2068. cFormats, rgAdvf, lpFormatEtc, lpAdviseSink, rgdwConnection,
  2069. lpClientSite, lpStg, lplpObj);
  2070. }
  2071. }
  2072. errEmbeddedObject:
  2073. if (lpstgSrc)
  2074. lpstgSrc->Release();
  2075. goto errRtn;
  2076. Next:
  2077. // try to get "EmbedSource" data
  2078. foretcTmp.cfFormat = g_cfEmbedSource;
  2079. foretcTmp.tymed = TYMED_ISTORAGE;
  2080. medTmp.tymed = TYMED_ISTORAGE;
  2081. medTmp.pstg = lpStg;
  2082. if ((error = lpSrcDataObj->GetDataHere(&foretcTmp, &medTmp))
  2083. == NOERROR)
  2084. {
  2085. error = wLoadAndInitObjectEx(lpSrcDataObj, iid, renderopt,
  2086. cFormats, rgAdvf, lpFormatEtc, lpAdviseSink, rgdwConnection,
  2087. lpClientSite, lpStg, lplpObj);
  2088. goto errRtn;
  2089. }
  2090. // If we have come here, and if the object doesn't support
  2091. // IPersistStorage, then we will fail.
  2092. if ((error = wSaveObjectWithoutCommit(lpSrcDataObj, lpStg, FALSE))
  2093. != NOERROR)
  2094. goto errRtn;;
  2095. if (renderopt != OLERENDER_ASIS )
  2096. UtDoStreamOperation(lpStg, /* pstgSrc */
  2097. NULL, /* pstgDst */
  2098. OPCODE_REMOVE,
  2099. /* operation to performed */
  2100. STREAMTYPE_CACHE);
  2101. /* stream to be operated upon */
  2102. error = wLoadAndInitObjectEx(lpSrcDataObj, iid, renderopt,
  2103. cFormats, rgAdvf, lpFormatEtc, lpAdviseSink, rgdwConnection,
  2104. lpClientSite, lpStg, lplpObj);
  2105. errRtn:
  2106. if (fAlloced)
  2107. PubMemFree(lpFormatEtc);
  2108. return error;
  2109. }
  2110. //+-------------------------------------------------------------------------
  2111. //
  2112. // Function: wCreateLinkEx
  2113. //
  2114. // Synopsis: Creates a link by binding the moniker (if necessary),
  2115. // doing a GetData into a storage, and then loading the
  2116. // object from the storage.
  2117. //
  2118. // Effects:
  2119. //
  2120. // Arguments: [lpmkSrc] -- moniker to the link source
  2121. // [rclsid] -- clsid of the link source
  2122. // [lpSrcDataObj] -- pointer to the source data object
  2123. // (may be NULL)
  2124. // [iid] -- requested interface ID
  2125. // [dwFlags] -- object creation flags
  2126. // [renderopt] -- render options, such as OLERENDER_DRAW
  2127. // [cFormats] -- the number of elements in rgFormatEtc
  2128. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  2129. // is specified in renderopt
  2130. // [rgFormatEtc] -- array of rendering formats, if
  2131. // OLERENDER_FORMAT is specified in renderopt
  2132. // [lpAdviseSink] -- the advise sink for the object
  2133. // [rgdwConnection]-- where to put the connection IDs for the
  2134. // advisory connections
  2135. // [lpClientSite] -- pointer to the client site
  2136. // [lpStg] -- storage for the link object
  2137. // [lplpObj] -- where to put the pointer to the new
  2138. // link object
  2139. //
  2140. // Requires:
  2141. //
  2142. // Returns: HRESULT
  2143. //
  2144. // Signals:
  2145. //
  2146. // Modifies:
  2147. //
  2148. // Algorithm:
  2149. //
  2150. // History: dd-mmm-yy Author Comment
  2151. // 29-Oct-93 alexgo 32bit port
  2152. //
  2153. // Notes:
  2154. //
  2155. //--------------------------------------------------------------------------
  2156. #pragma SEG(wCreateLinkEx)
  2157. INTERNAL wCreateLinkEx
  2158. (
  2159. IMoniker FAR* lpmkSrc,
  2160. REFCLSID rclsid,
  2161. IDataObject FAR* lpSrcDataObj,
  2162. REFIID iid,
  2163. DWORD dwFlags,
  2164. DWORD renderopt,
  2165. ULONG cFormats,
  2166. DWORD FAR* rgAdvf,
  2167. LPFORMATETC rgFormatEtc,
  2168. IAdviseSink FAR* lpAdviseSink,
  2169. DWORD FAR* rgdwConnection,
  2170. IOleClientSite FAR* lpClientSite,
  2171. IStorage FAR* lpStg,
  2172. void FAR* FAR* lplpObj
  2173. )
  2174. {
  2175. VDATEHEAP();
  2176. IPersistStorage FAR * lpPS = NULL;
  2177. IOleLink FAR* lpLink = NULL;
  2178. IDataObject FAR* lpBoundDataObj = NULL;
  2179. HRESULT error;
  2180. CLSID clsidLast = rclsid;
  2181. BOOL fNeedsUpdate = FALSE;
  2182. if (!lpSrcDataObj && ((renderopt != OLERENDER_NONE)
  2183. || (IsEqualCLSID(rclsid,CLSID_NULL))
  2184. || wQueryUseCustomLink(rclsid))) {
  2185. // if renderopt is not OLERENDER_NONE, then we must have
  2186. // a data obj pointer which will be used to initialize cache.
  2187. // We also bind if we are not able to find from regdb whether
  2188. // the class has custom link implementation or not
  2189. if ((error = BindMoniker(lpmkSrc, NULL /* grfOpt */,
  2190. IID_IDataObject, (LPLPVOID) &lpBoundDataObj))
  2191. != NOERROR) {
  2192. if (OLERENDER_NONE != renderopt)
  2193. return ResultFromScode(
  2194. OLE_E_CANT_BINDTOSOURCE);
  2195. // else we assume StdOleLink and continue with creation
  2196. } else {
  2197. lpSrcDataObj = lpBoundDataObj;
  2198. if (IsEqualCLSID(clsidLast, CLSID_NULL))
  2199. UtGetClassID((LPUNKNOWN)lpSrcDataObj,
  2200. &clsidLast);
  2201. }
  2202. }
  2203. // Deal with CustomLinkSource
  2204. // (see notes below)
  2205. if (lpSrcDataObj) {
  2206. STGMEDIUM medTmp;
  2207. FORMATETC foretcTmp;
  2208. INIT_FORETC(foretcTmp);
  2209. foretcTmp.cfFormat = g_cfCustomLinkSource;
  2210. foretcTmp.tymed = TYMED_ISTORAGE;
  2211. if (lpSrcDataObj->QueryGetData(&foretcTmp) == NOERROR) {
  2212. medTmp.tymed = TYMED_ISTORAGE;
  2213. medTmp.pstg = lpStg;
  2214. medTmp.pUnkForRelease = NULL;
  2215. if (error = lpSrcDataObj->GetDataHere(&foretcTmp,
  2216. &medTmp))
  2217. goto errRtn;
  2218. error = wLoadAndInitObjectEx(lpSrcDataObj, iid,
  2219. renderopt, cFormats, rgAdvf, rgFormatEtc,
  2220. lpAdviseSink, rgdwConnection, lpClientSite,
  2221. lpStg, lplpObj);
  2222. // This is a really strange peice of logic,
  2223. // spaghetti code at it's finest. Basically,
  2224. // this says that if there is *NOT* a
  2225. // custom link source, then we want to do the
  2226. // logic of wCreateObject, etc. below. If we
  2227. // got to this line in the code, then we
  2228. // *did* have a custom link source, so
  2229. // don't do the stuff below (thus the goto).
  2230. // REVIEW32: If there are any bugs in here,
  2231. // then rewrite this in a more sensible fashion.
  2232. // I'm leaving as is for now due to time constraints.
  2233. goto errRtn;
  2234. }
  2235. }
  2236. // Otherwise
  2237. if ((error = wCreateObject (CLSID_StdOleLink, FALSE,
  2238. iid, lpClientSite,
  2239. lpStg, STG_INITNEW, lplpObj)) != NOERROR)
  2240. goto errRtn;
  2241. if (lpSrcDataObj)
  2242. {
  2243. BOOL fCacheNodeCreated = FALSE;
  2244. if ((error = wInitializeCacheEx(lpSrcDataObj, clsidLast,
  2245. renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink,
  2246. rgdwConnection, *lplpObj, &fCacheNodeCreated)) != NOERROR)
  2247. {
  2248. if (error != NOERROR && fCacheNodeCreated)
  2249. {
  2250. fNeedsUpdate = TRUE;
  2251. error = NOERROR;
  2252. }
  2253. }
  2254. }
  2255. errRtn:
  2256. if (error == NOERROR && *lplpObj)
  2257. error = ((LPUNKNOWN) *lplpObj)->QueryInterface(IID_IOleLink,
  2258. (LPLPVOID) &lpLink);
  2259. if (error == NOERROR && lpLink && (dwFlags & OLECREATE_LEAVERUNNING)) {
  2260. // This will connect to the object if it is already running.
  2261. lpLink->SetSourceMoniker (lpmkSrc, clsidLast);
  2262. }
  2263. // We bound to the object to initialize the cache. We don't need
  2264. // it anymore
  2265. if (lpBoundDataObj)
  2266. {
  2267. if (error == NOERROR && (dwFlags & OLECREATE_LEAVERUNNING))
  2268. OleRun((LPUNKNOWN)*lplpObj);
  2269. // this will give a chance to the object to go away, if it can
  2270. wDoLockUnlock(lpBoundDataObj);
  2271. lpBoundDataObj->Release();
  2272. }
  2273. // If the source object started running as a result of BindMoniker,
  2274. // then we would've got rid of it by now.
  2275. if (error == NOERROR && lpLink)
  2276. {
  2277. if ( !(dwFlags & OLECREATE_LEAVERUNNING) ) {
  2278. // This will connect to the object if it is already running.
  2279. lpLink->SetSourceMoniker (lpmkSrc, clsidLast);
  2280. }
  2281. if (fNeedsUpdate) {
  2282. // relevant cache data is not available from the
  2283. // lpSrcDataObj. So do Update and get the right cache
  2284. // data.
  2285. error = wDoUpdate ((LPUNKNOWN) *lplpObj);
  2286. if (GetScode(error) == CACHE_E_NOCACHE_UPDATED)
  2287. error = ReportResult(0, DV_E_FORMATETC, 0, 0);
  2288. }
  2289. // Release on lpLink is necessary only if error == NOERROR
  2290. lpLink->Release();
  2291. }
  2292. if (error != NOERROR && *lplpObj) {
  2293. ((IUnknown FAR*) *lplpObj)->Release();
  2294. *lplpObj = NULL;
  2295. }
  2296. return error;
  2297. }
  2298. //+-------------------------------------------------------------------------
  2299. //
  2300. // Function: wCreateFromFileEx
  2301. //
  2302. // Synopsis: Creates an ole object from a file by binding the given
  2303. // moniker and creating the object from the IDataObject pointer
  2304. //
  2305. // Effects:
  2306. //
  2307. // Arguments: [lpmkFile] -- moniker to the file
  2308. // [iid] -- requested interface ID
  2309. // [dwFlags] -- object creation flags
  2310. // [renderopt] -- render options, such as OLERENDER_DRAW
  2311. // [cFormats] -- the number of elements in rgFormatEtc
  2312. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  2313. // is specified in renderopt
  2314. // [rgFormatEtc] -- array of rendering formats, if
  2315. // OLERENDER_FORMAT is specified in renderopt
  2316. // [lpAdviseSink] -- the advise sink for the object
  2317. // [rgdwConnection]-- where to put the connection IDs for the
  2318. // advisory connections
  2319. // [lpClientSite] -- pointer to the client site
  2320. // [lpStg] -- pointer to the storage for the new object
  2321. // [lplpObj] -- where to put the pointer to the object
  2322. //
  2323. // Requires:
  2324. //
  2325. // Returns: HRESULT
  2326. //
  2327. // Signals:
  2328. //
  2329. // Modifies:
  2330. //
  2331. // Algorithm:
  2332. //
  2333. // History: dd-mmm-yy Author Comment
  2334. // 29-Oct-93 alexgo 32bit port
  2335. //
  2336. // Notes:
  2337. //
  2338. //--------------------------------------------------------------------------
  2339. #pragma SEG(wCreateFromFileEx)
  2340. INTERNAL wCreateFromFileEx
  2341. (
  2342. LPMONIKER lpmkFile,
  2343. LPDATAOBJECT lpDataObject,
  2344. REFIID iid,
  2345. DWORD dwFlags,
  2346. DWORD renderopt,
  2347. ULONG cFormats,
  2348. DWORD FAR* rgAdvf,
  2349. LPFORMATETC rgFormatEtc,
  2350. IAdviseSink FAR* lpAdviseSink,
  2351. DWORD FAR* rgdwConnection,
  2352. LPOLECLIENTSITE lpClientSite,
  2353. LPSTORAGE lpStg,
  2354. LPLPVOID lplpObj
  2355. )
  2356. {
  2357. VDATEHEAP();
  2358. HRESULT error;
  2359. LPDATAOBJECT lpLocalDataObj;
  2360. if (!lpDataObject)
  2361. {
  2362. if ((error = BindMoniker(lpmkFile, NULL, IID_IDataObject,
  2363. (LPLPVOID) &lpLocalDataObj)) != NOERROR)
  2364. return error;
  2365. }
  2366. else
  2367. {
  2368. lpLocalDataObj = lpDataObject;
  2369. }
  2370. Verify(lpLocalDataObj);
  2371. error = wCreateFromDataEx(lpLocalDataObj, iid, dwFlags, renderopt, cFormats,
  2372. rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection, lpClientSite,
  2373. lpStg, lplpObj);
  2374. if (error == NOERROR && (dwFlags & OLECREATE_LEAVERUNNING))
  2375. OleRun((LPUNKNOWN)*lplpObj);
  2376. // If we bound locally release it now, else it is up to the caller to do the right thing.
  2377. if (!lpDataObject)
  2378. {
  2379. wDoLockUnlock(lpLocalDataObj);
  2380. lpLocalDataObj->Release();
  2381. }
  2382. return error;
  2383. }
  2384. //+-------------------------------------------------------------------------
  2385. //
  2386. // Function: CoIsHashedOle1Class
  2387. //
  2388. // Synopsis: Determines whether or not a CLSID is an OLE1 class
  2389. //
  2390. // Effects:
  2391. //
  2392. // Arguments: [rclsid] -- the class ID in question
  2393. //
  2394. // Requires:
  2395. //
  2396. // Returns: TRUE if ole1.0, FALSE otherwise
  2397. //
  2398. // Signals:
  2399. //
  2400. // Modifies:
  2401. //
  2402. // Algorithm:
  2403. //
  2404. // History: dd-mmm-yy Author Comment
  2405. // 29-Oct-93 alexgo 32bit port
  2406. //
  2407. // Notes: REVIEW32: This is a strange function..consider nuking
  2408. // it for 32bit, we may not need it (only used in 1 place)
  2409. //
  2410. //--------------------------------------------------------------------------
  2411. #pragma SEG(CoIsHashedOle1Class)
  2412. STDAPI_(BOOL) CoIsHashedOle1Class(REFCLSID rclsid)
  2413. {
  2414. VDATEHEAP();
  2415. CLSID clsid = rclsid;
  2416. clsid.Data1 = 0L;
  2417. WORD wHiWord = HIWORD(rclsid.Data1);
  2418. return IsEqualGUID(clsid, IID_IUnknown) && wHiWord==4;
  2419. }
  2420. //+-------------------------------------------------------------------------
  2421. //
  2422. // Function: EnsureCLSIDIsRegistered
  2423. //
  2424. // Synopsis: Checks to see if the clsid is in the registration database,
  2425. // if not, puts it there
  2426. //
  2427. // Effects:
  2428. //
  2429. // Arguments: [clsid] -- the clsid in question
  2430. // [pstg] -- storage to get more info about the
  2431. // clsid if we need to register it
  2432. //
  2433. // Requires:
  2434. //
  2435. // Returns: void
  2436. //
  2437. // Signals:
  2438. //
  2439. // Modifies:
  2440. //
  2441. // Algorithm:
  2442. //
  2443. // History: dd-mmm-yy Author Comment
  2444. // 29-Oct-93 alexgo 32bit port
  2445. //
  2446. // Notes:
  2447. //
  2448. //--------------------------------------------------------------------------
  2449. #pragma SEG(EnsureCLSIDIsRegistered)
  2450. void EnsureCLSIDIsRegistered
  2451. (REFCLSID clsid,
  2452. LPSTORAGE pstg)
  2453. {
  2454. VDATEHEAP();
  2455. LPOLESTR szProgId = NULL;
  2456. if (NOERROR == ProgIDFromCLSID (clsid, &szProgId))
  2457. {
  2458. PubMemFree(szProgId);
  2459. }
  2460. else
  2461. {
  2462. // This is the case of getting a hashed CLSID from a file from
  2463. // another machine and the ProgId is not yet in the reg db,
  2464. // so we must get it from the storage.
  2465. // This code should rarely be executed.
  2466. CLIPFORMAT cf = 0;
  2467. CLSID clsidT;
  2468. OLECHAR szProgId[256];
  2469. if (ReadFmtUserTypeStg (pstg, &cf, NULL) != NOERROR)
  2470. return;
  2471. // Format is the ProgId
  2472. if (0==GetClipboardFormatName (cf, szProgId, 256))
  2473. return;
  2474. // Will force registration of the CLSID if the ProgId (the OLE1
  2475. // classname) is registered
  2476. CLSIDFromProgID (szProgId, &clsidT);
  2477. }
  2478. }
  2479. //+-------------------------------------------------------------------------
  2480. //
  2481. // Function: wCreateObject
  2482. //
  2483. // Synopsis: Calls CoCreateInstance to create an object, a defhandler
  2484. // is created if necessary and CLSID info is written to
  2485. // the storage.
  2486. //
  2487. // Effects:
  2488. //
  2489. // Arguments: [clsid] -- the class id of the object to create
  2490. // [iid] -- the requested interface ID
  2491. // [lpClientSite] -- pointer to the client site
  2492. // [lpStg] -- storage for the object
  2493. // [wfStorage] -- flags for the STORAGE, one of
  2494. // STG_NONE, STD_INITNEW, STG_LOAD,
  2495. // defined at the beginning of this file
  2496. // [ppv] -- where to put the pointer to the object
  2497. //
  2498. // Requires:
  2499. //
  2500. // Returns: HRESULT
  2501. //
  2502. // Signals:
  2503. //
  2504. // Modifies:
  2505. //
  2506. // Algorithm:
  2507. //
  2508. // History: dd-mmm-yy Author Comment
  2509. // 01-Feb-94 alexgo fixed memory leak
  2510. // 29-Oct-93 alexgo 32bit port
  2511. //
  2512. // Notes:
  2513. //
  2514. //--------------------------------------------------------------------------
  2515. #pragma SEG(wCreateObject)
  2516. INTERNAL wCreateObject
  2517. (
  2518. CLSID clsid,
  2519. BOOL fPermitCodeDownload, //parameter added in order to control whether code download occurs or not -RahulTh (11/20/97)
  2520. REFIID iid,
  2521. IOleClientSite FAR* lpClientSite,
  2522. IStorage FAR * lpStg,
  2523. WORD wfStorage,
  2524. void FAR* FAR* ppv
  2525. )
  2526. {
  2527. VDATEHEAP();
  2528. HRESULT error;
  2529. DWORD dwClsCtx;
  2530. IOleObject* pOleObject = NULL;
  2531. DWORD dwMiscStatus = 0;
  2532. DWORD dwAddClsCtx;
  2533. dwAddClsCtx = fPermitCodeDownload?0:CLSCTX_NO_CODE_DOWNLOAD;
  2534. *ppv = NULL;
  2535. CLSID clsidNew;
  2536. if (wfStorage == STG_INITNEW
  2537. && SUCCEEDED(OleGetAutoConvert (clsid, &clsidNew)))
  2538. // Insert an object of the new class
  2539. clsid = clsidNew;
  2540. if (wfStorage == STG_LOAD && CoIsHashedOle1Class (clsid))
  2541. EnsureCLSIDIsRegistered (clsid, lpStg);
  2542. if (IsWOWThread())
  2543. {
  2544. // CLSCTX needs to be turned on for possible 16 bit inproc server
  2545. // such as OLE controls
  2546. dwClsCtx = CLSCTX_INPROC | CLSCTX_INPROC_SERVER16 | dwAddClsCtx;
  2547. }
  2548. else
  2549. {
  2550. dwClsCtx = CLSCTX_INPROC | dwAddClsCtx;
  2551. }
  2552. if ((error = CoCreateInstance (clsid, NULL /*pUnkOuter*/,
  2553. dwClsCtx, iid, ppv)) != NOERROR) {
  2554. // if not OleLoad or error other than class not registered,
  2555. // exit
  2556. if (wfStorage != STG_LOAD || GetScode(error)
  2557. != REGDB_E_CLASSNOTREG)
  2558. goto errRtn;
  2559. // OleLoad and class not registered: use default handler
  2560. // directly
  2561. if ((error = OleCreateDefaultHandler(clsid, NULL, iid, ppv))
  2562. != NOERROR)
  2563. goto errRtn;
  2564. }
  2565. AssertSz(*ppv, "HRESULT is OK, but pointer is NULL");
  2566. // Check if we have client site
  2567. if(lpClientSite) {
  2568. // QI for IOleObject on the server
  2569. error = ((IUnknown *)*ppv)->QueryInterface(IID_IOleObject, (void **)&pOleObject);
  2570. if(error == NOERROR) {
  2571. // Get the MiscStatus bits
  2572. error = pOleObject->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
  2573. // Set the client site first if OLEMISC_SETCLIENTSITEFIRST bit is set
  2574. if(error == NOERROR && (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST)) {
  2575. error = pOleObject->SetClientSite(lpClientSite);
  2576. if(error != NOERROR) {
  2577. pOleObject->Release();
  2578. goto errRtn;
  2579. }
  2580. }
  2581. else if(error != NOERROR) {
  2582. error = NOERROR;
  2583. dwMiscStatus = 0;
  2584. }
  2585. }
  2586. else
  2587. goto errRtn;
  2588. }
  2589. if (wfStorage != STG_NONE)
  2590. {
  2591. IPersistStorage FAR* lpPS;
  2592. if ((error = ((LPUNKNOWN) *ppv)->QueryInterface(
  2593. IID_IPersistStorage, (LPLPVOID)&lpPS)) != NOERROR)
  2594. {
  2595. goto errRtn;
  2596. }
  2597. if (wfStorage == STG_INITNEW)
  2598. {
  2599. error = WriteClassStg(lpStg, clsid);
  2600. if (SUCCEEDED(error))
  2601. {
  2602. error = lpPS->InitNew (lpStg);
  2603. }
  2604. }
  2605. else
  2606. {
  2607. error = lpPS->Load (lpStg);
  2608. }
  2609. lpPS->Release();
  2610. if (FAILED(error))
  2611. {
  2612. goto errRtn;
  2613. }
  2614. }
  2615. if(lpClientSite) {
  2616. // Assert that pOleObject is set
  2617. Win4Assert(IsValidInterface(pOleObject));
  2618. // Set the client site if it has not been set already
  2619. if(!(dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST))
  2620. error = pOleObject->SetClientSite (lpClientSite);
  2621. // Release the object
  2622. pOleObject->Release();
  2623. if (FAILED(error))
  2624. goto errRtn;
  2625. }
  2626. AssertSz(error == NOERROR, "Invalid code path");
  2627. return NOERROR;
  2628. errRtn:
  2629. if (*ppv) {
  2630. ((LPUNKNOWN) *ppv)->Release();
  2631. *ppv = NULL;
  2632. }
  2633. return error;
  2634. }
  2635. //+-------------------------------------------------------------------------
  2636. //
  2637. // Function: wLoadAndInitObjectEx
  2638. //
  2639. // Synopsis: Loads and binds an object from the given storage.
  2640. // A cacle is initialized from the data object
  2641. //
  2642. // Effects:
  2643. //
  2644. // Arguments: [lpSrcDataObj] -- pointer to the data object to initialize
  2645. // the cache with
  2646. // [iid] -- requested interface ID
  2647. // [renderopt] -- render options, such as OLERENDER_DRAW
  2648. // [cFormats] -- the number of elements in rgFormatEtc
  2649. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  2650. // is specified in renderopt
  2651. // [rgFormatEtc] -- array of rendering formats, if
  2652. // OLERENDER_FORMAT is specified in renderopt
  2653. // [lpAdviseSink] -- the advise sink for the object
  2654. // [rgdwConnection]-- where to put the connection IDs for the
  2655. // advisory connections
  2656. // [lpClientSite] -- pointer to the client site.
  2657. // [lpStg] -- storage for the new object
  2658. // [lplpObj] -- where to put the pointer to the new object
  2659. //
  2660. // Requires:
  2661. //
  2662. // Returns: HRESULT
  2663. //
  2664. // Signals:
  2665. //
  2666. // Modifies:
  2667. //
  2668. // Algorithm:
  2669. //
  2670. // History: dd-mmm-yy Author Comment
  2671. // 29-Oct-93 alexgo 32bit port
  2672. //
  2673. // Notes:
  2674. //
  2675. //--------------------------------------------------------------------------
  2676. #pragma SEG(wLoadAndInitObjectEx)
  2677. INTERNAL wLoadAndInitObjectEx
  2678. (
  2679. IDataObject FAR* lpSrcDataObj,
  2680. REFIID iid,
  2681. DWORD renderopt,
  2682. ULONG cFormats,
  2683. DWORD FAR* rgAdvf,
  2684. LPFORMATETC rgFormatEtc,
  2685. IAdviseSink FAR* lpAdviseSink,
  2686. DWORD FAR* rgdwConnection,
  2687. IOleClientSite FAR* lpClientSite,
  2688. IStorage FAR* lpStg,
  2689. void FAR* FAR* lplpObj
  2690. )
  2691. {
  2692. VDATEHEAP();
  2693. HRESULT error;
  2694. CLSID clsid;
  2695. if ((error = OleLoadWithoutBinding(lpStg, FALSE, iid, lpClientSite,
  2696. lplpObj)) != NOERROR)
  2697. return error;
  2698. UtGetClassID((LPUNKNOWN) *lplpObj, &clsid);
  2699. error = wInitializeCacheEx(lpSrcDataObj, clsid, renderopt,
  2700. cFormats, rgAdvf, rgFormatEtc, lpAdviseSink, rgdwConnection,
  2701. *lplpObj);
  2702. if (error != NOERROR) {
  2703. // relevant cache data is not available from the lpSrcDataObj.
  2704. // So do Update and get the right cache data.
  2705. error = wDoUpdate ((LPUNKNOWN) *lplpObj);
  2706. }
  2707. if (GetScode(error) == CACHE_E_NOCACHE_UPDATED) {
  2708. error = ReportResult(0, DV_E_FORMATETC, 0, 0);
  2709. goto errRtn;
  2710. }
  2711. if (error == NOERROR)
  2712. wBindIfRunning((LPUNKNOWN) *lplpObj);
  2713. errRtn:
  2714. if (error != NOERROR && *lplpObj) {
  2715. ((IUnknown FAR*) *lplpObj)->Release();
  2716. *lplpObj = NULL;
  2717. }
  2718. return error;
  2719. }
  2720. //+-------------------------------------------------------------------------
  2721. //
  2722. // Function: wInitializeCacheEx
  2723. //
  2724. // Synopsis: Query's for IOleCache on the given object and calls IOC->Cache
  2725. // to initialize a cache node.
  2726. //
  2727. // Effects:
  2728. //
  2729. // Arguments: [lpSrcDataObj] -- pointer to data to initialize the cache
  2730. // with
  2731. // [rclsid] -- CLSID to use if an icon is needed
  2732. // [renderopt] -- render options, such as OLERENDER_DRAW
  2733. // [cFormats] -- the number of elements in rgFormatEtc
  2734. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  2735. // is specified in renderopt
  2736. // [rgFormatEtc] -- array of rendering formats, if
  2737. // OLERENDER_FORMAT is specified in renderopt
  2738. // [lpAdviseSink] -- the advise sink for the object
  2739. // [rgdwConnection]-- where to put the connection IDs for the
  2740. // advisory connections
  2741. // [lpNewObj] -- the object on which the cache should
  2742. // be initialized
  2743. // [pfCacheNodeCreated] -- where to return a flag indicating
  2744. // whether or not a cache node was
  2745. // created
  2746. //
  2747. // Requires:
  2748. //
  2749. // Returns: HRESULT
  2750. //
  2751. // Signals:
  2752. //
  2753. // Modifies:
  2754. //
  2755. // Algorithm:
  2756. //
  2757. // History: dd-mmm-yy Author Comment
  2758. // 31-Oct-93 alexgo 32bit port
  2759. //
  2760. // Notes:
  2761. //
  2762. //--------------------------------------------------------------------------
  2763. // This routine modifies lpFormatEtc's fields.
  2764. #pragma SEG(wInitializeCacheEx)
  2765. INTERNAL wInitializeCacheEx
  2766. (
  2767. IDataObject FAR* lpSrcDataObj,
  2768. REFCLSID rclsid,
  2769. DWORD renderopt,
  2770. ULONG cFormats,
  2771. DWORD FAR* rgAdvf,
  2772. LPFORMATETC rgFormatEtc,
  2773. IAdviseSink FAR* lpAdviseSink,
  2774. DWORD FAR* rgdwConnection,
  2775. void FAR* lpNewObj,
  2776. BOOL FAR* pfCacheNodeCreated
  2777. )
  2778. {
  2779. VDATEHEAP();
  2780. IDataObject FAR* lpNewDataObj = NULL;
  2781. IOleCache FAR* lpOleCache = NULL;
  2782. HRESULT error;
  2783. LPFORMATETC lpFormatEtc;
  2784. DWORD advf;
  2785. STGMEDIUM stgmed;
  2786. DWORD dwConnId = 0;
  2787. BOOL fIconCase;
  2788. if (pfCacheNodeCreated)
  2789. *pfCacheNodeCreated = FALSE;
  2790. if (renderopt == OLERENDER_NONE || renderopt == OLERENDER_ASIS)
  2791. return NOERROR;
  2792. if (lpAdviseSink) {
  2793. if ((error = ((IUnknown FAR*)lpNewObj)->QueryInterface(IID_IDataObject,
  2794. (LPLPVOID) &lpNewDataObj)) != NOERROR)
  2795. return error;
  2796. }
  2797. else {
  2798. if (((IUnknown FAR*)lpNewObj)->QueryInterface(IID_IOleCache,
  2799. (LPLPVOID) &lpOleCache) != NOERROR)
  2800. return wQueryFormatSupport(lpNewObj, renderopt, rgFormatEtc);
  2801. }
  2802. for (ULONG i=0; i<cFormats; i++)
  2803. {
  2804. advf = (rgAdvf ? rgAdvf[i] : ADVF_PRIMEFIRST);
  2805. lpFormatEtc = &rgFormatEtc[i];
  2806. fIconCase = FALSE;
  2807. if (lpFormatEtc->dwAspect == DVASPECT_ICON) {
  2808. if (lpFormatEtc->cfFormat == NULL) {
  2809. lpFormatEtc->cfFormat = CF_METAFILEPICT;
  2810. lpFormatEtc->tymed = TYMED_MFPICT;
  2811. }
  2812. fIconCase = (lpFormatEtc->cfFormat == CF_METAFILEPICT);
  2813. }
  2814. if (lpAdviseSink)
  2815. {
  2816. // if icon case, must use these advise flags or the icon
  2817. // data won't get passed back correctly
  2818. if (fIconCase)
  2819. advf |= (ADVF_PRIMEFIRST | ADVF_ONLYONCE);
  2820. // should we send the data immediately?
  2821. if ((advf & ADVF_PRIMEFIRST) && lpSrcDataObj)
  2822. {
  2823. stgmed.tymed = TYMED_NULL;
  2824. stgmed.pUnkForRelease = NULL;
  2825. if (advf & ADVF_NODATA)
  2826. {
  2827. // don't sent data, send only the notification
  2828. lpAdviseSink->OnDataChange(lpFormatEtc, &stgmed);
  2829. }
  2830. else
  2831. {
  2832. if (fIconCase)
  2833. error = UtGetIconData(lpSrcDataObj, rclsid, lpFormatEtc, &stgmed);
  2834. else
  2835. error = lpSrcDataObj->GetData(lpFormatEtc, &stgmed);
  2836. if (error != NOERROR)
  2837. goto errRtn;
  2838. // send data to sink and release stdmedium
  2839. lpAdviseSink->OnDataChange(lpFormatEtc, &stgmed);
  2840. ReleaseStgMedium(&stgmed);
  2841. }
  2842. if (advf & ADVF_ONLYONCE)
  2843. continue;
  2844. // remove the ADVF_PRIMEFIRST from flags.
  2845. advf &= (~ADVF_PRIMEFIRST);
  2846. }
  2847. // setup advisory connection
  2848. if ((error = lpNewDataObj->DAdvise(lpFormatEtc, advf,
  2849. lpAdviseSink, &dwConnId)) != NOERROR)
  2850. goto errRtn;
  2851. // optionally stuff the id in the array
  2852. if (rgdwConnection)
  2853. rgdwConnection[i] = dwConnId;
  2854. }
  2855. else
  2856. {
  2857. if (fIconCase)
  2858. advf = ADVF_NODATA;
  2859. // Create a cache of already specified view format.
  2860. // In case of olerender_draw, lpFormatEtc->cfFormat would have already
  2861. // been set to NULL.
  2862. error = lpOleCache->Cache(lpFormatEtc, advf, &dwConnId);
  2863. if (FAILED(GetScode(error))) {
  2864. if (! ((dwConnId != 0) && fIconCase) )
  2865. goto errRtn;
  2866. // In icon case we can ignore the cache's QueryGetData failure
  2867. }
  2868. error = NOERROR;
  2869. if (pfCacheNodeCreated)
  2870. *pfCacheNodeCreated = TRUE;
  2871. if (fIconCase) {
  2872. if ((error = UtGetIconData(lpSrcDataObj, rclsid, lpFormatEtc,
  2873. &stgmed)) == NOERROR) {
  2874. if ((error = lpOleCache->SetData(lpFormatEtc, &stgmed,
  2875. TRUE)) != NOERROR)
  2876. ReleaseStgMedium(&stgmed);
  2877. }
  2878. }
  2879. }
  2880. }
  2881. if (error == NOERROR && !lpAdviseSink && lpSrcDataObj)
  2882. error = lpOleCache->InitCache(lpSrcDataObj);
  2883. errRtn:
  2884. if (lpNewDataObj)
  2885. lpNewDataObj->Release();
  2886. if (lpOleCache)
  2887. lpOleCache->Release();
  2888. return error;
  2889. }
  2890. //+-------------------------------------------------------------------------
  2891. //
  2892. // Function: wReturnCreationError
  2893. //
  2894. // Synopsis: modifies the return code, used internally in creation api's
  2895. //
  2896. // Effects:
  2897. //
  2898. // Arguments: [hresult] -- the original error code
  2899. //
  2900. // Requires:
  2901. //
  2902. // Returns: HRESULT
  2903. //
  2904. // Signals:
  2905. //
  2906. // Modifies:
  2907. //
  2908. // Algorithm:
  2909. //
  2910. // History: dd-mmm-yy Author Comment
  2911. // 01-Nov-93 alexgo 32bit port
  2912. //
  2913. // Notes:
  2914. //
  2915. //--------------------------------------------------------------------------
  2916. INTERNAL wReturnCreationError(HRESULT hresult)
  2917. {
  2918. VDATEHEAP();
  2919. if (hresult != NOERROR) {
  2920. SCODE sc = GetScode(hresult);
  2921. if (sc == CACHE_S_FORMATETC_NOTSUPPORTED
  2922. || sc == CACHE_E_NOCACHE_UPDATED)
  2923. return ReportResult(0, DV_E_FORMATETC, 0, 0);
  2924. }
  2925. return hresult;
  2926. }
  2927. //+-------------------------------------------------------------------------
  2928. //
  2929. // Function: wGetMonikerAndClassFromFile
  2930. //
  2931. // Synopsis: gets a moniker and class id from the given file
  2932. //
  2933. // Effects:
  2934. //
  2935. // Arguments: [lpszFileName] -- the file
  2936. // [fLink] -- passed onto CreatePackagerMoniker
  2937. // [lplpmkFile] -- where to put the pointer to the file
  2938. // moniker
  2939. // [lpfPackagerMoniker] -- where to put a flag indicating
  2940. // whether or not a packager moniker
  2941. // was created.
  2942. // [lpClsid] -- where to put the class ID
  2943. //
  2944. // Requires:
  2945. //
  2946. // Returns: HRESULT
  2947. //
  2948. // Signals:
  2949. //
  2950. // Modifies:
  2951. //
  2952. // Algorithm:
  2953. //
  2954. // History: dd-mmm-yy Author Comment
  2955. // 01-Nov-93 alexgo 32bit port
  2956. // 10-May-94 KevinRo Reimplemented OLE 1.0 interop
  2957. // 03-Mar-95 ScottSk Added STG_E_FILENOTFOUND
  2958. //
  2959. //
  2960. //--------------------------------------------------------------------------
  2961. INTERNAL wGetMonikerAndClassFromFile
  2962. (
  2963. LPCOLESTR lpszFileName,
  2964. BOOL fLink,
  2965. LPMONIKER FAR* lplpmkFile,
  2966. BOOL FAR* lpfPackagerMoniker,
  2967. CLSID FAR* lpClsid,
  2968. LPDATAOBJECT * lplpDataObject
  2969. )
  2970. {
  2971. HRESULT hrFileMoniker;
  2972. HRESULT hresult;
  2973. BOOL fHaveBoundClsid = FALSE;
  2974. LPMONIKER lpFileMoniker;
  2975. VDATEHEAP();
  2976. *lplpDataObject = NULL;
  2977. *lplpmkFile = NULL;
  2978. // To ensure the same error codes are returned as before we don't return immediately if CreateFileMoniker fails.
  2979. hrFileMoniker = CreateFileMoniker((LPOLESTR)lpszFileName, &lpFileMoniker);
  2980. Assert( (NOERROR == hrFileMoniker) || (NULL == lpFileMoniker) );
  2981. if (NOERROR == hrFileMoniker)
  2982. {
  2983. LPBINDCTX pbc;
  2984. if (SUCCEEDED(CreateBindCtx( 0, &pbc )))
  2985. {
  2986. if (S_OK == lpFileMoniker->IsRunning(pbc,NULL,NULL))
  2987. {
  2988. // If the Object is Running Bind and get the CLSID
  2989. if (NOERROR == lpFileMoniker->BindToObject(pbc, NULL, IID_IDataObject,
  2990. (LPLPVOID) lplpDataObject))
  2991. {
  2992. fHaveBoundClsid = UtGetClassID((LPUNKNOWN)*lplpDataObject,lpClsid);
  2993. Assert( (TRUE == fHaveBoundClsid) || (IsEqualCLSID(*lpClsid, CLSID_NULL)) );
  2994. }
  2995. }
  2996. pbc->Release();
  2997. }
  2998. }
  2999. if (!fHaveBoundClsid)
  3000. {
  3001. // Call GetClassFileEx directly (rather than going through GetClassFile).
  3002. hresult = GetClassFileEx ((LPOLESTR)lpszFileName, lpClsid, CLSID_NULL);
  3003. Assert( (NOERROR == hresult) || (IsEqualCLSID(*lpClsid, CLSID_NULL)) );
  3004. if (NOERROR == hresult)
  3005. fHaveBoundClsid = TRUE;
  3006. }
  3007. // If have a CLSID at this point see if its insertable.
  3008. if (fHaveBoundClsid)
  3009. {
  3010. Assert(!IsEqualCLSID(*lpClsid, CLSID_NULL));
  3011. // Check whether we need package this file, even though it is an
  3012. // OLE class file.
  3013. if (!wNeedToPackage(*lpClsid))
  3014. {
  3015. if (lpfPackagerMoniker != NULL)
  3016. {
  3017. *lpfPackagerMoniker = FALSE;
  3018. }
  3019. *lplpmkFile = lpFileMoniker;
  3020. return hrFileMoniker;
  3021. }
  3022. }
  3023. //
  3024. // We didnt' find an OLE insertable object or couldn't get the CLSID. Therefore, create a
  3025. // packager moniker for it.
  3026. //
  3027. // If Bound to the DataObject, release it.
  3028. if (*lplpDataObject)
  3029. {
  3030. (*lplpDataObject)->Release();
  3031. *lplpDataObject = NULL;
  3032. }
  3033. // If GetClassFileEx() failed because the file was not found or could not be openned.
  3034. // don't try to bind with Packager.
  3035. if (hresult == MK_E_CANTOPENFILE)
  3036. {
  3037. if (NOERROR == hrFileMoniker)
  3038. {
  3039. lpFileMoniker->Release();
  3040. }
  3041. return STG_E_FILENOTFOUND;
  3042. }
  3043. // If we failed to create the file moniker its finally safe to bail without changing the error code.
  3044. if (NOERROR != hrFileMoniker)
  3045. {
  3046. return hrFileMoniker;
  3047. }
  3048. if (lpfPackagerMoniker != NULL)
  3049. {
  3050. *lpfPackagerMoniker = TRUE;
  3051. }
  3052. hresult = CreatePackagerMonikerEx(lpszFileName,lpFileMoniker,fLink,lplpmkFile);
  3053. lpFileMoniker->Release();
  3054. return hresult;
  3055. }
  3056. //+-------------------------------------------------------------------------
  3057. //
  3058. // Function: wCreatePackageEx
  3059. //
  3060. // Synopsis: Internal function, does a IDO->GetData for a filename, and
  3061. // then creates either a link or normal object from that file
  3062. //
  3063. // Effects:
  3064. //
  3065. // Arguments: [lpSrcDataObj] -- the source for the filename
  3066. // [iid] -- the requested interface ID
  3067. // [dwFlags] -- object creation flags
  3068. // [renderopt] -- render options, such as OLERENDER_DRAW
  3069. // [cFormats] -- the number of elements in rgFormatEtc
  3070. // [rgAdvf] -- array of advise flags, if OLRENDER_FORMAT
  3071. // is specified in renderopt
  3072. // [rgFormatEtc] -- array of rendering formats, if
  3073. // OLERENDER_FORMAT is specified in renderopt
  3074. // [lpAdviseSink] -- the advise sink for the object
  3075. // [rgdwConnection]-- where to put the connection IDs for the
  3076. // advisory connections
  3077. // [lpClientSite] -- client site for the object
  3078. // [lpStg] -- storage for the object
  3079. // [fLink] -- if TRUE, create a link
  3080. // [lplpObj] -- where to put the pointer to the object
  3081. //
  3082. // Requires:
  3083. //
  3084. // Returns: HRESULT
  3085. //
  3086. // Signals:
  3087. //
  3088. // Modifies:
  3089. //
  3090. // Algorithm: Gets a filename from the data object (converting to Unicode
  3091. // if necessary) and then creates either an embedding or link
  3092. // from that filename.
  3093. //
  3094. // History: dd-mmm-yy Author Comment
  3095. // 24-Apr-94 alexgo rewrote to handle FileNameW
  3096. // 01-Nov-93 alexgo 32bit port
  3097. //
  3098. // Notes:
  3099. //
  3100. //--------------------------------------------------------------------------
  3101. #pragma SEG(wCreatePackageEx)
  3102. INTERNAL wCreatePackageEx
  3103. (
  3104. LPDATAOBJECT lpSrcDataObj,
  3105. REFIID iid,
  3106. DWORD dwFlags,
  3107. DWORD renderopt,
  3108. ULONG cFormats,
  3109. DWORD FAR* rgAdvf,
  3110. LPFORMATETC rgFormatEtc,
  3111. IAdviseSink FAR* lpAdviseSink,
  3112. DWORD FAR* rgdwConnection,
  3113. LPOLECLIENTSITE lpClientSite,
  3114. LPSTORAGE lpStg,
  3115. BOOL fLink,
  3116. LPLPVOID lplpObj
  3117. )
  3118. {
  3119. VDATEHEAP();
  3120. FORMATETC formatetc;
  3121. STGMEDIUM medium;
  3122. HRESULT hresult;
  3123. CLSID clsid = CLSID_NULL;
  3124. LPOLESTR pszFileName = NULL;
  3125. OLECHAR szFileName[MAX_PATH +1]; // in case we
  3126. // have to
  3127. // translate
  3128. LEDebugOut((DEB_ITRACE, "%p _IN wCreatePackageEx ( %p , %p , %lx , %lx ,"
  3129. " %lx , %p , %p , %p , %p , %p , %p , %lu , %p )\n", NULL, lpSrcDataObj,
  3130. &iid, dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc, lpAdviseSink,
  3131. rgdwConnection, lpClientSite, lpStg, fLink, lplpObj));
  3132. INIT_FORETC(formatetc);
  3133. formatetc.cfFormat = g_cfFileNameW;
  3134. formatetc.tymed = TYMED_HGLOBAL;
  3135. // zero the medium
  3136. _xmemset(&medium, 0, sizeof(STGMEDIUM));
  3137. // we don't need to do a QueryGetData, because we will have only
  3138. // gotten here on the advice of a formatetc enumerator from the
  3139. // data object (and thus, one of the GetData calls should succeed).
  3140. hresult = lpSrcDataObj->GetData(&formatetc, &medium);
  3141. // if we couldn't get the Unicode filename for some reason, try
  3142. // for the ANSI version
  3143. if( hresult != NOERROR )
  3144. {
  3145. char * pszAnsiFileName;
  3146. DWORD cwchSize;
  3147. formatetc.cfFormat = g_cfFileName;
  3148. // re-NULL the medium, just in case it was messed up by
  3149. // the first call above
  3150. _xmemset( &medium, 0, sizeof(STGMEDIUM));
  3151. hresult = lpSrcDataObj->GetData(&formatetc, &medium);
  3152. if( hresult == NOERROR )
  3153. {
  3154. pszAnsiFileName = (char *)GlobalLock(medium.hGlobal);
  3155. cwchSize = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED,
  3156. pszAnsiFileName, -1, szFileName, MAX_PATH);
  3157. if( cwchSize == 0 )
  3158. {
  3159. GlobalUnlock(medium.hGlobal);
  3160. ReleaseStgMedium(&medium);
  3161. hresult = ResultFromScode(E_FAIL);
  3162. }
  3163. else
  3164. {
  3165. pszFileName = szFileName;
  3166. }
  3167. // we will Unlock at the end of the routine
  3168. }
  3169. }
  3170. else
  3171. {
  3172. pszFileName = (LPOLESTR)GlobalLock(medium.hGlobal);
  3173. }
  3174. if( hresult == NOERROR )
  3175. {
  3176. if (fLink)
  3177. {
  3178. hresult = OleCreateLinkToFileEx(pszFileName, iid,
  3179. dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc,
  3180. lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj);
  3181. }
  3182. else
  3183. {
  3184. hresult = OleCreateFromFileEx(clsid, pszFileName, iid,
  3185. dwFlags, renderopt, cFormats, rgAdvf, rgFormatEtc,
  3186. lpAdviseSink, rgdwConnection, lpClientSite, lpStg, lplpObj);
  3187. }
  3188. GlobalUnlock(medium.hGlobal);
  3189. ReleaseStgMedium(&medium);
  3190. }
  3191. LEDebugOut((DEB_ITRACE, "%p OUT wCreatePackageEx ( %lx ) [ %p ]\n",
  3192. NULL, hresult, *lplpObj));
  3193. return hresult;
  3194. }
  3195. //+-------------------------------------------------------------------------
  3196. //
  3197. // Function: wValidateCreateParams
  3198. //
  3199. // Synopsis: Validate the incoming create parameters
  3200. //
  3201. // Effects:
  3202. //
  3203. // Arguments: [cFormats] -- the number of elements in rgAdvf
  3204. // [rgAdvf] -- array of advise flags
  3205. //
  3206. // Requires:
  3207. //
  3208. // Returns: HRESULT
  3209. //
  3210. // Signals:
  3211. //
  3212. // Modifies:
  3213. //
  3214. // Algorithm:
  3215. //
  3216. // History: dd-mmm-yy Author Comment
  3217. // 26-Apr-96 davidwor added function
  3218. //
  3219. // Notes:
  3220. //
  3221. //--------------------------------------------------------------------------
  3222. #pragma SEG(wValidateCreateParams)
  3223. INTERNAL wValidateCreateParams
  3224. (
  3225. DWORD dwFlags,
  3226. DWORD renderopt,
  3227. ULONG cFormats,
  3228. DWORD FAR* rgAdvf,
  3229. LPFORMATETC rgFormatEtc,
  3230. IAdviseSink FAR* lpAdviseSink,
  3231. DWORD FAR* rgdwConnection,
  3232. IOleClientSite FAR* lpClientSite,
  3233. IStorage FAR* lpStg
  3234. )
  3235. {
  3236. HRESULT hresult = NOERROR;
  3237. VDATEHEAP();
  3238. if (dwFlags != (dwFlags & OLECREATE_LEAVERUNNING)) {
  3239. VdateAssert(dwFlags, "Invalid creation flags");
  3240. hresult = ResultFromScode(E_INVALIDARG);
  3241. goto errRtn;
  3242. }
  3243. if (renderopt == OLERENDER_DRAW && cFormats > 1) {
  3244. VdateAssert(cFormats, "Multiple formats not allowed with OLERENDER_DRAW");
  3245. hresult = ResultFromScode(E_INVALIDARG);
  3246. goto errRtn;
  3247. }
  3248. if (renderopt != OLERENDER_FORMAT)
  3249. VDATEPTRNULL_LABEL( lpAdviseSink, errRtn, hresult );
  3250. if (cFormats == 0) {
  3251. VDATEPTRNULL_LABEL( rgAdvf, errRtn, hresult );
  3252. VDATEPTRNULL_LABEL( rgFormatEtc, errRtn, hresult );
  3253. VDATEPTRNULL_LABEL( rgdwConnection, errRtn, hresult );
  3254. }
  3255. else {
  3256. VDATESIZEREADPTRIN_LABEL( rgAdvf, cFormats * sizeof(DWORD), errRtn, hresult );
  3257. VDATESIZEREADPTRIN_LABEL( rgFormatEtc, cFormats * sizeof(FORMATETC), errRtn, hresult );
  3258. if ( rgdwConnection ) {
  3259. VDATESIZEPTROUT_LABEL( rgdwConnection, cFormats * sizeof(DWORD), errRtn, hresult );
  3260. _xmemset(rgdwConnection, 0, cFormats * sizeof(DWORD));
  3261. }
  3262. }
  3263. if ((hresult = wValidateAdvfEx(cFormats, rgAdvf)) != NOERROR)
  3264. goto errRtn;
  3265. VDATEIFACE_LABEL( lpStg, errRtn, hresult );
  3266. if ( lpAdviseSink )
  3267. VDATEIFACE_LABEL( lpAdviseSink, errRtn, hresult );
  3268. if ( lpClientSite )
  3269. VDATEIFACE_LABEL( lpClientSite, errRtn, hresult );
  3270. errRtn:
  3271. return hresult;
  3272. }
  3273. //+-------------------------------------------------------------------------
  3274. //
  3275. // Function: wValidateAdvfEx
  3276. //
  3277. // Synopsis: Validate the incoming array of ADVF values
  3278. //
  3279. // Effects:
  3280. //
  3281. // Arguments: [cFormats] -- the number of elements in rgAdvf
  3282. // [rgAdvf] -- array of advise flags
  3283. //
  3284. // Requires:
  3285. //
  3286. // Returns: HRESULT
  3287. //
  3288. // Signals:
  3289. //
  3290. // Modifies:
  3291. //
  3292. // Algorithm:
  3293. //
  3294. // History: dd-mmm-yy Author Comment
  3295. // 19-Mar-96 davidwor added function
  3296. //
  3297. // Notes:
  3298. //
  3299. //--------------------------------------------------------------------------
  3300. #pragma SEG(wValidateAdvfEx)
  3301. INTERNAL wValidateAdvfEx
  3302. (
  3303. ULONG cFormats,
  3304. DWORD FAR* rgAdvf
  3305. )
  3306. {
  3307. VDATEHEAP();
  3308. if ((cFormats != 0) != (rgAdvf != NULL))
  3309. return ResultFromScode(E_INVALIDARG);
  3310. for (ULONG i=0; i<cFormats; i++)
  3311. {
  3312. if (rgAdvf[i] != (rgAdvf[i] & MASK_VALID_ADVF))
  3313. {
  3314. VdateAssert(rgAdvf, "Invalid ADVF value specified");
  3315. return ResultFromScode(E_INVALIDARG);
  3316. }
  3317. }
  3318. return NOERROR;
  3319. }
  3320. //+-------------------------------------------------------------------------
  3321. //
  3322. // Function: wValidateFormatEtc
  3323. //
  3324. // Synopsis: Validate the incoming formatetc and initialize the
  3325. // out formatetc with the correct info
  3326. //
  3327. // Effects:
  3328. //
  3329. // Arguments: [renderopt] -- rendering option
  3330. // [lpFormatEtc] -- the incoming formatetc
  3331. // [lpMyFormatEtc] -- the out formatetc
  3332. //
  3333. // Requires:
  3334. //
  3335. // Returns: HRESULT
  3336. //
  3337. // Signals:
  3338. //
  3339. // Modifies:
  3340. //
  3341. // Algorithm:
  3342. //
  3343. // History: dd-mmm-yy Author Comment
  3344. // 01-Nov-93 alexgo 32bit port
  3345. //
  3346. // Notes: The original comments,
  3347. //
  3348. // Validate the lpFormatEtc that's been passed to the creation APIs. And then
  3349. // initialize our formateEtc structure with the appropriate info.
  3350. //
  3351. // We allow NULL lpFormatEtc if the render option is olerender_draw
  3352. // We ignore lpFormatEtc if the render option is olerender_none
  3353. //
  3354. //--------------------------------------------------------------------------
  3355. #pragma SEG(wValidateFormatEtc)
  3356. INTERNAL wValidateFormatEtc
  3357. (
  3358. DWORD renderopt,
  3359. LPFORMATETC lpFormatEtc,
  3360. LPFORMATETC lpMyFormatEtc
  3361. )
  3362. {
  3363. VDATEHEAP();
  3364. SCODE sc = S_OK;
  3365. if (renderopt == OLERENDER_NONE || renderopt == OLERENDER_ASIS)
  3366. return NOERROR;
  3367. if (renderopt == OLERENDER_FORMAT) {
  3368. if (!lpFormatEtc || !lpFormatEtc->cfFormat) {
  3369. sc = E_INVALIDARG;
  3370. goto errRtn;
  3371. }
  3372. if (lpFormatEtc->tymed !=
  3373. UtFormatToTymed(lpFormatEtc->cfFormat)) {
  3374. sc = DV_E_TYMED;
  3375. goto errRtn;
  3376. }
  3377. } else if (renderopt == OLERENDER_DRAW) {
  3378. if (lpFormatEtc) {
  3379. if (lpFormatEtc->cfFormat != NULL) {
  3380. VdateAssert(lpFormatEtc->cfFormat,"NON-NULL clipformat specified with OLERENDER_DRAW");
  3381. sc = DV_E_CLIPFORMAT;
  3382. goto errRtn;
  3383. }
  3384. if (lpFormatEtc->tymed != TYMED_NULL) {
  3385. VdateAssert(lpFormatEtc->tymed,"TYMED_NULL is not specified with OLERENDER_DRAW");
  3386. sc = DV_E_TYMED;
  3387. goto errRtn;
  3388. }
  3389. }
  3390. } else {
  3391. VdateAssert(renderopt, "Unexpected value for OLERENDER_ option");
  3392. sc = E_INVALIDARG;
  3393. goto errRtn;
  3394. }
  3395. if (lpFormatEtc) {
  3396. if (!HasValidLINDEX(lpFormatEtc))
  3397. {
  3398. sc = DV_E_LINDEX;
  3399. goto errRtn;
  3400. }
  3401. VERIFY_ASPECT_SINGLE(lpFormatEtc->dwAspect)
  3402. *lpMyFormatEtc = *lpFormatEtc;
  3403. } else {
  3404. INIT_FORETC(*lpMyFormatEtc);
  3405. lpMyFormatEtc->tymed = TYMED_NULL;
  3406. lpMyFormatEtc->cfFormat = NULL;
  3407. }
  3408. errRtn:
  3409. return ReportResult(0, sc, 0, 0);
  3410. }
  3411. //+-------------------------------------------------------------------------
  3412. //
  3413. // Function: wValidateFormatEtcEx
  3414. //
  3415. // Synopsis: Validate the incoming formatetc and initialize the
  3416. // out formatetc with the correct info
  3417. //
  3418. // Effects:
  3419. //
  3420. // Arguments: [renderopt] -- rendering option
  3421. // [lpcFormats] -- the number of elements in rgFormatEtc
  3422. // [rgFormatEtc] -- array of rendering formats
  3423. // [lpFormatEtc] -- place to store valid formatetc if only one
  3424. // [lplpFormatEtc] -- the out array of formatetcs
  3425. // [lpfAlloced] -- place to store whether array was allocated
  3426. //
  3427. // Requires:
  3428. //
  3429. // Returns: HRESULT
  3430. //
  3431. // Signals:
  3432. //
  3433. // Modifies:
  3434. //
  3435. // Algorithm:
  3436. //
  3437. // History: dd-mmm-yy Author Comment
  3438. // 01-Nov-93 alexgo 32bit port
  3439. //
  3440. // Notes: The original comments,
  3441. //
  3442. // Validate the lpFormatEtc that's been passed to the creation APIs. And then
  3443. // initialize our formateEtc structure with the appropriate info.
  3444. //
  3445. // We allow NULL lpFormatEtc if the render option is olerender_draw
  3446. // We ignore lpFormatEtc if the render option is olerender_none
  3447. //
  3448. //--------------------------------------------------------------------------
  3449. #pragma SEG(wValidateFormatEtcEx)
  3450. INTERNAL wValidateFormatEtcEx
  3451. (
  3452. DWORD renderopt,
  3453. ULONG FAR* lpcFormats,
  3454. LPFORMATETC rgFormatEtc,
  3455. LPFORMATETC lpFormatEtc,
  3456. LPFORMATETC FAR* lplpFormatEtc,
  3457. LPBOOL lpfAlloced
  3458. )
  3459. {
  3460. LPFORMATETC lpfmtetc;
  3461. VDATEHEAP();
  3462. SCODE sc = S_OK;
  3463. *lplpFormatEtc = lpFormatEtc;
  3464. *lpfAlloced = FALSE;
  3465. if (renderopt == OLERENDER_NONE || renderopt == OLERENDER_ASIS)
  3466. return NOERROR;
  3467. if (renderopt != OLERENDER_FORMAT && renderopt != OLERENDER_DRAW) {
  3468. VdateAssert(renderopt, "Unexpected value for OLERENDER_ option");
  3469. return ResultFromScode(E_INVALIDARG);
  3470. }
  3471. if ((*lpcFormats != 0) != (rgFormatEtc != NULL))
  3472. return ResultFromScode(E_INVALIDARG);
  3473. if (*lpcFormats <= 1) {
  3474. if (*lpcFormats == 0)
  3475. *lpcFormats = 1;
  3476. return wValidateFormatEtc(renderopt, rgFormatEtc, lpFormatEtc);
  3477. }
  3478. *lplpFormatEtc = (LPFORMATETC)PubMemAlloc(*lpcFormats * sizeof(FORMATETC));
  3479. if (!*lplpFormatEtc)
  3480. return E_OUTOFMEMORY;
  3481. *lpfAlloced = TRUE;
  3482. for (ULONG i=0; i<*lpcFormats; i++)
  3483. {
  3484. lpfmtetc = &rgFormatEtc[i];
  3485. if (renderopt == OLERENDER_FORMAT)
  3486. {
  3487. if (!lpfmtetc->cfFormat) {
  3488. sc = E_INVALIDARG;
  3489. goto errRtn;
  3490. }
  3491. if (lpfmtetc->tymed !=
  3492. UtFormatToTymed(lpfmtetc->cfFormat)) {
  3493. sc = DV_E_TYMED;
  3494. goto errRtn;
  3495. }
  3496. }
  3497. else if (renderopt == OLERENDER_DRAW)
  3498. {
  3499. if (lpfmtetc->cfFormat != NULL) {
  3500. VdateAssert(lpfmtetc->cfFormat,"NON-NULL clipformat specified with OLERENDER_DRAW");
  3501. sc = DV_E_CLIPFORMAT;
  3502. goto errRtn;
  3503. }
  3504. if (lpfmtetc->tymed != TYMED_NULL) {
  3505. VdateAssert(lpfmtetc->tymed,"TYMED_NULL is not specified with OLERENDER_DRAW");
  3506. sc = DV_E_TYMED;
  3507. goto errRtn;
  3508. }
  3509. }
  3510. if (!HasValidLINDEX(lpfmtetc))
  3511. {
  3512. sc = DV_E_LINDEX;
  3513. goto errRtn;
  3514. }
  3515. VERIFY_ASPECT_SINGLE(lpfmtetc->dwAspect)
  3516. (*lplpFormatEtc)[i] = *lpfmtetc;
  3517. }
  3518. errRtn:
  3519. if (sc != S_OK) {
  3520. PubMemFree(*lplpFormatEtc);
  3521. *lpfAlloced = FALSE;
  3522. }
  3523. return ReportResult(0, sc, 0, 0);
  3524. }
  3525. //+-------------------------------------------------------------------------
  3526. //
  3527. // Function: wQueryFormatSupport
  3528. //
  3529. // Synopsis: check to see whether we will be able to Get and SetData of
  3530. // the given format
  3531. //
  3532. // Effects:
  3533. //
  3534. // Arguments: [lpObj] -- pointer to the object
  3535. // [renderopt] -- rendering options
  3536. // [lpFormatEtc] -- the formatetc in question
  3537. //
  3538. // Requires:
  3539. //
  3540. // Returns: HRESULT
  3541. //
  3542. // Signals:
  3543. //
  3544. // Modifies:
  3545. //
  3546. // Algorithm: Internal function, calls UtIsFormatSupported (which calls
  3547. // EnumFormatEtc and checks all of the formats) if renderopt
  3548. // is OLERENDER_FORMAT
  3549. //
  3550. // History: dd-mmm-yy Author Comment
  3551. // 01-Nov-93 alexgo 32bit port
  3552. //
  3553. // Notes:
  3554. //
  3555. //--------------------------------------------------------------------------
  3556. #pragma SEG(wQueryFormatSupport)
  3557. INTERNAL wQueryFormatSupport
  3558. (LPVOID lpObj, DWORD renderopt, LPFORMATETC lpFormatEtc)
  3559. {
  3560. VDATEHEAP();
  3561. IDataObject FAR* lpDataObj;
  3562. HRESULT error = NOERROR;
  3563. if (renderopt == OLERENDER_FORMAT)
  3564. {
  3565. if ((error = ((IUnknown FAR*) lpObj)->QueryInterface(
  3566. IID_IDataObject, (LPLPVOID)&lpDataObj)) == NOERROR)
  3567. {
  3568. if (!UtIsFormatSupported(lpDataObj,
  3569. DATADIR_GET | DATADIR_SET,
  3570. lpFormatEtc->cfFormat))
  3571. error = ResultFromScode(DV_E_CLIPFORMAT);
  3572. lpDataObj->Release();
  3573. }
  3574. }
  3575. return error;
  3576. }
  3577. //+-------------------------------------------------------------------------
  3578. //
  3579. // Function: wGetMonikerAndClassFromObject
  3580. //
  3581. // Synopsis: Gets the moniker and class ID from the given object
  3582. //
  3583. // Effects:
  3584. //
  3585. // Arguments: [lpSrcDataObj] -- the data object
  3586. // [lplpmkSrc] -- where to put a pointer to the moniker
  3587. // [lpclsidLast] -- where to put the clsid
  3588. //
  3589. // Requires:
  3590. //
  3591. // Returns: HRESULT
  3592. //
  3593. // Signals:
  3594. //
  3595. // Modifies:
  3596. //
  3597. // Algorithm:
  3598. //
  3599. // History: dd-mmm-yy Author Comment
  3600. // 15-Mar-95 alexgo added a hack for CorelDraw5
  3601. // 01-Nov-93 alexgo 32bit port
  3602. //
  3603. // Notes: see also wGetMonikerAndClassFromFile
  3604. //
  3605. //--------------------------------------------------------------------------
  3606. #pragma SEG(wGetMonikerAndClassFromObject)
  3607. INTERNAL wGetMonikerAndClassFromObject(
  3608. LPDATAOBJECT lpSrcDataObj,
  3609. LPMONIKER FAR* lplpmkSrc,
  3610. CLSID FAR* lpclsidLast
  3611. )
  3612. {
  3613. VDATEHEAP();
  3614. HRESULT error;
  3615. FORMATETC foretcTmp;
  3616. STGMEDIUM medium;
  3617. LPMONIKER lpmkSrc = NULL;
  3618. LARGE_INTEGER large_integer;
  3619. INIT_FORETC(foretcTmp);
  3620. foretcTmp.cfFormat = g_cfLinkSource;
  3621. foretcTmp.tymed = TYMED_ISTREAM;
  3622. // 16bit OLE had a bug where the medium was uninitialized at this
  3623. // point. Corel5, when doing a paste-link to itself, actually
  3624. // checked the tymed and compared it with TYMED_NULL. So here
  3625. // we set the value to something recognizeable.
  3626. //
  3627. // NB! In the thunk layer, if we are *NOT* in Corel Draw, this
  3628. // value will be reset to TYMED_NULL.
  3629. if( IsWOWThread() )
  3630. {
  3631. medium.tymed = 0x66666666;
  3632. }
  3633. else
  3634. {
  3635. medium.tymed = TYMED_NULL;
  3636. }
  3637. medium.pstm = NULL;
  3638. medium.pUnkForRelease = NULL;
  3639. if ((error = lpSrcDataObj->GetData(&foretcTmp, &medium)) != NOERROR)
  3640. return ReportResult(0, OLE_E_CANT_GETMONIKER, 0, 0);
  3641. LISet32( large_integer, 0 );
  3642. if ((error = (medium.pstm)->Seek (large_integer, STREAM_SEEK_SET,
  3643. NULL)) != NOERROR)
  3644. goto FreeStgMed;
  3645. // get moniker from the stream
  3646. if ((error = OleLoadFromStream (medium.pstm, IID_IMoniker,
  3647. (LPLPVOID) lplpmkSrc)) != NOERROR)
  3648. goto FreeStgMed;
  3649. // read class stm; if error, use CLSID_NULL (for compatibility with
  3650. // prior times when the clsid was missing).
  3651. ReadClassStm(medium.pstm, lpclsidLast);
  3652. FreeStgMed:
  3653. ReleaseStgMedium (&medium);
  3654. if (error != NOERROR)
  3655. return ReportResult(0, OLE_E_CANT_GETMONIKER, 0, 0);
  3656. return NOERROR;
  3657. }
  3658. //+-------------------------------------------------------------------------
  3659. //
  3660. // Function: wDoLockUnlock
  3661. //
  3662. // Synopsis: tickles an object by locking and unlocking, used to resolve
  3663. // ambiguities with stub manager locks
  3664. //
  3665. // Effects: the object may go away as a result of this call, if the
  3666. // object is invisible and the lock count goes to zero as
  3667. // a result of locking/unlocking.
  3668. //
  3669. // Arguments: [lpUnk] -- pointer to the object to lock/unlock
  3670. //
  3671. // Requires:
  3672. //
  3673. // Returns: void
  3674. //
  3675. // Signals:
  3676. //
  3677. // Modifies:
  3678. //
  3679. // Algorithm:
  3680. //
  3681. // History: dd-mmm-yy Author Comment
  3682. // 01-Nov-93 alexgo 32bit port
  3683. //
  3684. // Notes:
  3685. //
  3686. //--------------------------------------------------------------------------
  3687. #pragma SEG(wDoLockUnlock)
  3688. void wDoLockUnlock(IUnknown FAR* lpUnk)
  3689. {
  3690. VDATEHEAP();
  3691. IRunnableObject FAR* pRO;
  3692. if (lpUnk->QueryInterface(IID_IRunnableObject, (LPLPVOID)&pRO)
  3693. == NOERROR)
  3694. { // increase lock count
  3695. if (pRO->LockRunning(TRUE, FALSE) == NOERROR)
  3696. // decrease lock count
  3697. pRO->LockRunning(FALSE, TRUE);
  3698. pRO->Release();
  3699. }
  3700. }
  3701. //+-------------------------------------------------------------------------
  3702. //
  3703. // Function: wSaveObjectWithoutCommit
  3704. //
  3705. // Synopsis: Saves an object without committing (to preserve the
  3706. // container's undo state)
  3707. //
  3708. // Effects:
  3709. //
  3710. // Arguments: [lpUnk] -- pointer to the object
  3711. // [pstgSave] -- storage in which to save
  3712. // [fSameAsLoad] -- indicates SaveAs operation
  3713. //
  3714. // Requires:
  3715. //
  3716. // Returns: HRESULT
  3717. //
  3718. // Signals:
  3719. //
  3720. // Modifies:
  3721. //
  3722. // Algorithm:
  3723. //
  3724. // History: dd-mmm-yy Author Comment
  3725. // 02-Nov-93 alexgo 32bit port
  3726. //
  3727. // Notes:
  3728. //
  3729. //--------------------------------------------------------------------------
  3730. INTERNAL wSaveObjectWithoutCommit
  3731. (LPUNKNOWN lpUnk, LPSTORAGE pstgSave, BOOL fSameAsLoad)
  3732. {
  3733. VDATEHEAP();
  3734. LPPERSISTSTORAGE pPS;
  3735. HRESULT error;
  3736. CLSID clsid;
  3737. if (error = lpUnk->QueryInterface(IID_IPersistStorage, (LPLPVOID)&pPS))
  3738. return error;
  3739. if (error = pPS->GetClassID(&clsid))
  3740. goto errRtn;
  3741. if (error = WriteClassStg(pstgSave, clsid))
  3742. goto errRtn;
  3743. if (error = pPS->Save(pstgSave, fSameAsLoad))
  3744. goto errRtn;
  3745. pPS->SaveCompleted(NULL);
  3746. errRtn:
  3747. pPS->Release();
  3748. return error;
  3749. }
  3750. //+-------------------------------------------------------------------------
  3751. //
  3752. // Function: wStuffIconOfFileEx
  3753. //
  3754. // Synopsis: Retrieves the icon if file [lpszFile] and stuffs it into
  3755. // [lpUnk]'s cache
  3756. //
  3757. // Effects:
  3758. //
  3759. // Arguments: [lpszFile] -- the file where the icon is stored
  3760. // [fAddLabel] -- if TRUE, adds a label to the icon
  3761. // presentation
  3762. // [renderopt] -- must be OLERENDER_DRAW or
  3763. // OLERENDER_FORMAT for anything to happen
  3764. // [cFormats] -- the number of elements in rgFormatEtc
  3765. // [rgFormatEtc] -- array of rendering formats, aspect must be
  3766. // DVASPECT_ICON and the clipboard format
  3767. // must be NULL or CF_METAFILE for anything
  3768. // to happen
  3769. // [lpUnk] -- pointer to the object in which the icon
  3770. // should be stuffed
  3771. //
  3772. // Requires:
  3773. //
  3774. // Returns: HRESULT
  3775. //
  3776. // Signals:
  3777. //
  3778. // Modifies:
  3779. //
  3780. // Algorithm:
  3781. //
  3782. // History: dd-mmm-yy Author Comment
  3783. // 02-Nov-93 alexgo 32bit port
  3784. //
  3785. // Notes:
  3786. // REVIEW32: maybe we should support enhanced metafiles for NT
  3787. //
  3788. //--------------------------------------------------------------------------
  3789. #pragma SEG(wStuffIconOfFileEx)
  3790. INTERNAL wStuffIconOfFileEx
  3791. (
  3792. LPCOLESTR lpszFile,
  3793. BOOL fAddLabel,
  3794. DWORD renderopt,
  3795. ULONG cFormats,
  3796. LPFORMATETC rgFormatEtc,
  3797. LPUNKNOWN lpUnk
  3798. )
  3799. {
  3800. VDATEHEAP();
  3801. IOleCache FAR* lpOleCache;
  3802. HRESULT error;
  3803. BOOL fFound = FALSE;
  3804. FORMATETC foretc;
  3805. STGMEDIUM stgmed;
  3806. if (renderopt == OLERENDER_NONE || renderopt == OLERENDER_ASIS)
  3807. return NOERROR;
  3808. if (rgFormatEtc == NULL)
  3809. return NOERROR; // in this case we default to DVASPECT_CONTENT
  3810. for (ULONG i=0; i<cFormats; i++)
  3811. {
  3812. if ((rgFormatEtc[i].dwAspect == DVASPECT_ICON) &&
  3813. (rgFormatEtc[i].cfFormat == NULL ||
  3814. rgFormatEtc[i].cfFormat == CF_METAFILEPICT))
  3815. {
  3816. foretc = rgFormatEtc[i];
  3817. fFound = TRUE;
  3818. }
  3819. }
  3820. if (!fFound)
  3821. return NOERROR;
  3822. foretc.cfFormat = CF_METAFILEPICT;
  3823. foretc.tymed = TYMED_MFPICT;
  3824. if ((error = lpUnk->QueryInterface(IID_IOleCache,
  3825. (LPLPVOID) &lpOleCache)) != NOERROR)
  3826. return error;
  3827. stgmed.tymed = TYMED_MFPICT;
  3828. stgmed.pUnkForRelease = NULL;
  3829. // get icon data of file, from registration database
  3830. if (!(stgmed.hGlobal = OleGetIconOfFile((LPOLESTR) lpszFile,
  3831. fAddLabel))) {
  3832. error = ResultFromScode(E_OUTOFMEMORY);
  3833. goto errRtn;
  3834. }
  3835. // take ownership of the data
  3836. if ((error = lpOleCache->SetData(&foretc, &stgmed, TRUE)) != NOERROR)
  3837. ReleaseStgMedium(&stgmed);
  3838. errRtn:
  3839. lpOleCache->Release();
  3840. return error;
  3841. }
  3842. //+-------------------------------------------------------------------------
  3843. //
  3844. // Function: wNeedToPackage
  3845. //
  3846. // Synopsis: Determines whether or not a given CLSID should be
  3847. // packaged.
  3848. //
  3849. // Effects:
  3850. //
  3851. // Arguments: [rclsid] -- the class ID
  3852. //
  3853. // Requires:
  3854. //
  3855. // Returns: BOOL
  3856. //
  3857. // Signals:
  3858. //
  3859. // Modifies:
  3860. //
  3861. // Algorithm: Looks for the reg key PackageOnFileDrop, or if it's a
  3862. // Word document, or if it is insertable, or if it's an OLE1
  3863. // class
  3864. //
  3865. // History: dd-mmm-yy Author Comment
  3866. // 02-Nov-93 alexgo 32bit port
  3867. // 03-Jun-94 AlexT Just check for Insertable key (instead
  3868. // of requiring a value)
  3869. //
  3870. // Notes:
  3871. //--------------------------------------------------------------------------
  3872. INTERNAL_(BOOL) wNeedToPackage(REFCLSID rclsid)
  3873. {
  3874. VDATEHEAP();
  3875. HKEY hkeyClsid;
  3876. HKEY hkeyTmp;
  3877. HKEY hkeyTmp2;
  3878. BOOL fPackage = FALSE;
  3879. LPOLESTR lpszProgID;
  3880. DWORD dw;
  3881. LONG cbValue = sizeof(dw);
  3882. LONG lRet;
  3883. CLSID clsidNew;
  3884. if (NOERROR != OleGetAutoConvert (rclsid, &clsidNew))
  3885. {
  3886. if (NOERROR != CoGetTreatAsClass (rclsid, &clsidNew))
  3887. {
  3888. clsidNew = rclsid;
  3889. }
  3890. }
  3891. if (CoOpenClassKey(clsidNew, FALSE, &hkeyClsid) != NOERROR)
  3892. return TRUE; // NON-OLE file, package it
  3893. if (ProgIDFromCLSID(clsidNew, &lpszProgID) == NOERROR) {
  3894. // see whether we can open this key
  3895. dw = (DWORD) RegOpenKey(HKEY_CLASSES_ROOT, lpszProgID,
  3896. &hkeyTmp);
  3897. PubMemFree(lpszProgID);
  3898. if (dw == ERROR_SUCCESS) {
  3899. // This is definitely a OLE insertable file.
  3900. lRet = RegOpenKey(hkeyTmp,
  3901. OLESTR("PackageOnFileDrop"),
  3902. &hkeyTmp2);
  3903. // Check whether we need to package this file
  3904. if (ERROR_SUCCESS == lRet)
  3905. {
  3906. RegCloseKey(hkeyTmp2);
  3907. fPackage = TRUE;
  3908. }
  3909. else if (IsEqualCLSID(clsidNew, CLSID_WordDocument))
  3910. {
  3911. // Hack to make sure Word documents are always
  3912. // Packaged on file drop. We write the key here
  3913. // so that we can say that a file is Packaged if
  3914. // and only if its ProgID has the "PackageOnFileDrop"
  3915. // key.
  3916. RegSetValue (hkeyTmp,
  3917. OLESTR("PackageOnFileDrop"),
  3918. REG_SZ, (LPOLESTR)NULL, 0);
  3919. fPackage = TRUE;
  3920. }
  3921. RegCloseKey(hkeyTmp);
  3922. if (fPackage) {
  3923. RegCloseKey(hkeyClsid);
  3924. return TRUE;
  3925. }
  3926. }
  3927. }
  3928. // There is no "PackageOnFileDrop" key defined.
  3929. // See whether this is an "Insertable" class by checking for the
  3930. // existence of the Insertable key - we don't require a value
  3931. lRet = RegOpenKey(hkeyClsid, OLESTR("Insertable"), &hkeyTmp);
  3932. if (ERROR_SUCCESS == lRet)
  3933. {
  3934. // Insertable key exists - close it and return
  3935. RegCloseKey(hkeyTmp);
  3936. goto errRtn;
  3937. }
  3938. //
  3939. // See whether this is a "Ole1Class" class by opening the
  3940. // registry key Ole1Class. We don't require a value
  3941. //
  3942. cbValue = sizeof(dw);
  3943. lRet = RegOpenKey(hkeyClsid,OLESTR("Ole1Class"),&hkeyTmp);
  3944. if (ERROR_SUCCESS == lRet)
  3945. {
  3946. RegCloseKey(hkeyTmp);
  3947. goto errRtn;
  3948. }
  3949. else
  3950. {
  3951. fPackage = TRUE;
  3952. }
  3953. errRtn:
  3954. RegCloseKey(hkeyClsid);
  3955. return fPackage;
  3956. }
  3957. //+-------------------------------------------------------------------------
  3958. //
  3959. // Function: wDoUpdate
  3960. //
  3961. // Synopsis: calls IOleObject->Update() on the given object, internal
  3962. // function
  3963. //
  3964. // Effects:
  3965. //
  3966. // Arguments: [lpUnkown] -- the object to update
  3967. //
  3968. // Requires:
  3969. //
  3970. // Returns: HRESULT
  3971. //
  3972. // Signals:
  3973. //
  3974. // Modifies:
  3975. //
  3976. // Algorithm:
  3977. //
  3978. // History: dd-mmm-yy Author Comment
  3979. // 02-Nov-93 alexgo 32bit port
  3980. //
  3981. // Notes:
  3982. //
  3983. //--------------------------------------------------------------------------
  3984. #pragma SEG(wDoUpdate)
  3985. INTERNAL wDoUpdate(IUnknown FAR* lpUnknown)
  3986. {
  3987. VDATEHEAP();
  3988. HRESULT error = NOERROR;
  3989. IOleObject FAR* lpOle;
  3990. if (lpUnknown->QueryInterface (IID_IOleObject, (LPLPVOID)&lpOle)
  3991. == NOERROR) {
  3992. error = lpOle->Update();
  3993. lpOle->Release();
  3994. }
  3995. return error;
  3996. }
  3997. //+-------------------------------------------------------------------------
  3998. //
  3999. // Function: wBindIfRunning
  4000. //
  4001. // Synopsis: calls IOleLink->BindIfRunning() on the given object
  4002. //
  4003. // Effects:
  4004. //
  4005. // Arguments: [lpUnk] -- the object
  4006. //
  4007. // Requires:
  4008. //
  4009. // Returns: HRESULT
  4010. //
  4011. // Signals:
  4012. //
  4013. // Modifies:
  4014. //
  4015. // Algorithm:
  4016. //
  4017. // History: dd-mmm-yy Author Comment
  4018. // 02-Nov-93 alexgo 32bit port
  4019. //
  4020. // Notes:
  4021. //
  4022. //--------------------------------------------------------------------------
  4023. INTERNAL_(void) wBindIfRunning(LPUNKNOWN lpUnk)
  4024. {
  4025. VDATEHEAP();
  4026. IOleLink FAR* lpLink;
  4027. if (lpUnk->QueryInterface (IID_IOleLink, (LPLPVOID)&lpLink)
  4028. == NOERROR)
  4029. {
  4030. lpLink->BindIfRunning();
  4031. lpLink->Release();
  4032. }
  4033. }
  4034. //+-------------------------------------------------------------------------
  4035. //
  4036. // Function: wQueryUseCustomLink
  4037. //
  4038. // Synopsis: look at the registry and see if the class ID has a custom
  4039. // link regisetered
  4040. //
  4041. // Effects:
  4042. //
  4043. // Arguments: [rclsid] -- the class ID in question
  4044. //
  4045. // Requires:
  4046. //
  4047. // Returns: BOOL
  4048. //
  4049. // Signals:
  4050. //
  4051. // Modifies:
  4052. //
  4053. // Algorithm:
  4054. //
  4055. // History: dd-mmm-yy Author Comment
  4056. // 02-Nov-93 alexgo 32bit port
  4057. //
  4058. // Notes:
  4059. //
  4060. //--------------------------------------------------------------------------
  4061. INTERNAL_(BOOL) wQueryUseCustomLink(REFCLSID rclsid)
  4062. {
  4063. VDATEHEAP();
  4064. // see whether it has Custom Link implementation
  4065. HKEY hkeyClsid;
  4066. HKEY hkeyTmp;
  4067. BOOL bUseCustomLink = FALSE;
  4068. if (SUCCEEDED(CoOpenClassKey(rclsid, FALSE, &hkeyClsid)))
  4069. {
  4070. DWORD dw;
  4071. dw = RegOpenKey(hkeyClsid,OLESTR("UseCustomLink"),&hkeyTmp);
  4072. if (ERROR_SUCCESS == dw)
  4073. {
  4074. RegCloseKey(hkeyTmp);
  4075. bUseCustomLink = TRUE;
  4076. }
  4077. RegCloseKey(hkeyClsid);
  4078. }
  4079. return bUseCustomLink;
  4080. }