Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1818 lines
48 KiB

  1. /******************************* Module Header *******************************
  2. * Module Name: OLE.C
  3. *
  4. * Purpose: Handles all API routines for the dde L&E sub-dll of the ole dll.
  5. *
  6. * PURPOSE: API routines for handling generic objects (which may be static,
  7. * linked, or embedded). These routines will be made into a DLL.
  8. *
  9. * Created: 1990
  10. *
  11. * Copyright (c) 1990, 1991 Microsoft Corporation
  12. *
  13. * History:
  14. * Raor, Srinik (../../90, 91) Designed/coded.
  15. * curts created portable version for WIN16/32
  16. *
  17. *****************************************************************************/
  18. #include <windows.h>
  19. #include "dll.h"
  20. #include "strsafe.h"
  21. extern DLL_ENTRY lpDllTable[];
  22. extern char packageClass[];
  23. extern OLECLIPFORMAT cfFileName;
  24. extern DWORD dwOleVer;
  25. DWORD dwVerFromFile;
  26. HANDLE hInfo = NULL;
  27. CLIENTDOC lockDoc = {{'C', 'D'}, 0L, 0L, 0, 0, 0, 0L, 0L};
  28. LHCLIENTDOC lhLockDoc = (LHCLIENTDOC) ((LPCLIENTDOC) &lockDoc);
  29. BOOL gbCreateInvisible = FALSE;
  30. BOOL gbLaunchServer;
  31. OLESTATUS INTERNAL LockServer (LPOBJECT_LE);
  32. #ifdef USE_FILE_VERSION_APIS
  33. //////////////////////////////////////////////////////////////////////////////
  34. //
  35. // LPVOID FAR PASCAL OleSetFileVer ()
  36. //
  37. //////////////////////////////////////////////////////////////////////////////
  38. OLESTATUS FAR PASCAL OleSetFileVer (
  39. LHCLIENTDOC lhclientdoc,
  40. WORD wFileVer
  41. ){
  42. LPCLIENTDOC lpclientdoc = (LPCLIENTDOC)lhclientdoc;
  43. char lpstr[256];
  44. switch (wFileVer)
  45. {
  46. case OS_WIN16:
  47. case OS_WIN32:
  48. lpclientdoc->dwFileVer = (DWORD)MAKELONG(wReleaseVer,wFileVer);
  49. return OLE_OK;
  50. default:
  51. return OLE_ERROR_FILE_VER;
  52. }
  53. }
  54. //////////////////////////////////////////////////////////////////////////////
  55. //
  56. // LPVOID FAR PASCAL OleQueryFileVer ()
  57. //
  58. //////////////////////////////////////////////////////////////////////////////
  59. DWORD FAR PASCAL OleQueryFileVer (
  60. LPCLIENTDOC lpclientdoc
  61. ){
  62. return (lpclientdoc->dwFileVer);
  63. }
  64. #endif
  65. //////////////////////////////////////////////////////////////////////////////
  66. //
  67. // LPVOID FAR PASCAL OleQueryProtocol (lpobj, lpprotocol)
  68. //
  69. // Tells whether the object supports the specified protocol.
  70. //
  71. // Arguments:
  72. //
  73. // lpobj - object pointer
  74. // lpprotocol - protocol string
  75. //
  76. // Returns:
  77. //
  78. // long ptr to object if the protocol is supported
  79. // NULL if not.
  80. //
  81. // Effects:
  82. //
  83. //////////////////////////////////////////////////////////////////////////////
  84. LPVOID FAR PASCAL OleQueryProtocol (
  85. LPOLEOBJECT lpobj,
  86. LPCSTR lpprotocol
  87. ){
  88. if (!CheckObject(lpobj))
  89. return NULL;
  90. return (*lpobj->lpvtbl->QueryProtocol) (lpobj, lpprotocol);
  91. }
  92. //////////////////////////////////////////////////////////////////////////////
  93. //
  94. // OLESTATUS FAR PASCAL OleDelete (lpobj)
  95. //
  96. // Deletes the given object and all memory associated with its sub-parts.
  97. // The calling function should cease to use 'lpobj', as it is now invalid.
  98. // If handler dll is used reference count is reduced by one, and if it
  99. // reaches zero the hanlder dll will be freed up.
  100. //
  101. // Arguments:
  102. //
  103. // lpobj - object pointer
  104. //
  105. // Returns:
  106. //
  107. // OLE_OK
  108. // OLE_ERROR_OBJECT
  109. // OLE_WAIT_FOR_RELEASE
  110. //
  111. // Effects:
  112. //
  113. //////////////////////////////////////////////////////////////////////////////
  114. OLESTATUS FAR PASCAL OleDelete (
  115. LPOLEOBJECT lpobj
  116. ){
  117. Puts("OleDelete");
  118. if (!CheckObject(lpobj))
  119. return OLE_ERROR_OBJECT;
  120. return (*lpobj->lpvtbl->Delete) (lpobj);
  121. }
  122. /***************************** Public Function ****************************\
  123. * OLESTATUS FAR PASCAL OleRelease (lpobj)
  124. *
  125. * OleRelease:
  126. *
  127. * Effects:
  128. *
  129. * History:
  130. * Wrote it.
  131. \***************************************************************************/
  132. OLESTATUS FAR PASCAL OleRelease (
  133. LPOLEOBJECT lpobj
  134. ){
  135. Puts("OleRelease");
  136. if (!CheckObject(lpobj))
  137. return OLE_ERROR_OBJECT;
  138. return (*lpobj->lpvtbl->Release) (lpobj);
  139. }
  140. /***************************** Public Function ****************************\
  141. *
  142. * OLESTATUS FAR PASCAL OleSaveToStream (lpobj, lpstream)
  143. *
  144. * oleSaveToStream: This will read <hobj> to the stream based on the <hfile>
  145. * structure. It will return TRUE on success. This is the only object
  146. * function for which it is not an error to pass a NULL <hobj>. In the case
  147. * of NULL, this function will simply put a placemarker for an object.
  148. * See oleLoadFromStream.
  149. *
  150. * Effects:
  151. *
  152. * History:
  153. * Wrote it.
  154. \***************************************************************************/
  155. OLESTATUS FAR PASCAL OleSaveToStream (
  156. LPOLEOBJECT lpobj,
  157. LPOLESTREAM lpstream
  158. ){
  159. Puts("OleSaveToStream");
  160. if (!CheckObject(lpobj))
  161. return OLE_ERROR_OBJECT;
  162. PROBE_READ(lpstream);
  163. return ((*lpobj->lpvtbl->SaveToStream) (lpobj, lpstream));
  164. }
  165. /***************************** Public Function ****************************\
  166. *
  167. * OLESTATUS FAR PASCAL OleLoadFromStream (lpstream, lpprotcol, lpclient, lhclientdoc, lpobjname, lplpobj)
  168. *
  169. * oleLoadFromStream: This will read an object out of the stream based on the
  170. * <hfile> structure. It will return a HANDLE to the object it creates.
  171. * On error, the return value is NULL, but since NULL is also a valid object
  172. * in the file, the <error> parameter should be checked as well.
  173. *
  174. * Effects:
  175. *
  176. * History:
  177. * Wrote it.
  178. \***************************************************************************/
  179. OLESTATUS FAR PASCAL OleLoadFromStream (
  180. LPOLESTREAM lpstream,
  181. LPCSTR lpprotocol,
  182. LPOLECLIENT lpclient,
  183. LHCLIENTDOC lhclientdoc,
  184. LPCSTR lpobjname,
  185. LPOLEOBJECT FAR * lplpobj
  186. ){
  187. LONG len;
  188. OLESTATUS retVal = OLE_ERROR_STREAM;
  189. char class[100];
  190. ATOM aClass;
  191. BOOL bEdit = FALSE, bStatic = FALSE;
  192. LONG ctype;
  193. int objCount;
  194. int iTable = INVALID_INDEX;
  195. Puts("OleLoadFromStream");
  196. *lplpobj = NULL;
  197. PROBE_MODE(bProtMode);
  198. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  199. return OLE_ERROR_HANDLE;
  200. PROBE_READ(lpstream);
  201. PROBE_WRITE(lplpobj);
  202. PROBE_READ(lpprotocol);
  203. PROBE_READ(lpclient);
  204. PROBE_READ(lpobjname);
  205. if (!lpobjname[0])
  206. return OLE_ERROR_NAME;
  207. if (!(bEdit = !lstrcmpi (lpprotocol, PROTOCOL_EDIT)))
  208. if (!(bStatic = !lstrcmpi (lpprotocol, PROTOCOL_STATIC)))
  209. return OLE_ERROR_PROTOCOL;
  210. if (GetBytes (lpstream, (LPSTR) &dwVerFromFile, sizeof(LONG)))
  211. return OLE_ERROR_STREAM;
  212. if (GetBytes (lpstream, (LPSTR)&ctype, sizeof(LONG)))
  213. return OLE_ERROR_STREAM;
  214. if (ctype == CT_NULL)
  215. return (bStatic ? OLE_OK: OLE_ERROR_PROTOCOL);
  216. if (((ctype != CT_PICTURE) && (ctype != CT_STATIC) && bStatic) ||
  217. ((ctype != CT_LINK) && (ctype != CT_OLDLINK)
  218. && (ctype != CT_EMBEDDED) && bEdit))
  219. return OLE_ERROR_PROTOCOL;
  220. //** Get Class
  221. if (GetBytes(lpstream, (LPSTR)&len, sizeof(len)))
  222. return OLE_ERROR_STREAM;
  223. if (len == 0)
  224. return OLE_ERROR_STREAM;
  225. if (GetBytes(lpstream, (LPSTR)&class, len))
  226. return OLE_ERROR_STREAM;
  227. aClass = GlobalAddAtom (class);
  228. if ((ctype == CT_PICTURE) || (ctype == CT_STATIC))
  229. retVal = DefLoadFromStream (lpstream, (LPSTR)lpprotocol, lpclient,
  230. lhclientdoc, (LPSTR)lpobjname, lplpobj, ctype, aClass, 0);
  231. //!!! It's the DLL's responsibility to delete the atom. But in case of
  232. // failure we delete the atom if our DefLoadFromStream().
  233. else if ((iTable = LoadDll (class)) == INVALID_INDEX) {
  234. retVal = DefLoadFromStream (lpstream, (LPSTR)lpprotocol, lpclient,
  235. lhclientdoc, (LPSTR)lpobjname, lplpobj, ctype, aClass, 0);
  236. }
  237. else {
  238. objCount = lpDllTable[iTable].cObj;
  239. retVal = (*lpDllTable[iTable].Load) (lpstream, (LPSTR)lpprotocol, lpclient,
  240. lhclientdoc, (LPSTR)lpobjname, lplpobj, ctype, aClass, 0);
  241. if (retVal > OLE_WAIT_FOR_RELEASE)
  242. lpDllTable[iTable].cObj = objCount - 1;
  243. else
  244. (*lplpobj)->iTable = iTable;
  245. }
  246. return retVal;
  247. }
  248. OLESTATUS FAR PASCAL OleClone (
  249. LPOLEOBJECT lpobjsrc,
  250. LPOLECLIENT lpclient,
  251. LHCLIENTDOC lhclientdoc,
  252. LPCSTR lpobjname,
  253. LPOLEOBJECT FAR * lplpobj
  254. ){
  255. OLESTATUS retVal;
  256. Puts("OleClone");
  257. if (!CheckObject(lpobjsrc))
  258. return OLE_ERROR_OBJECT;
  259. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  260. return OLE_ERROR_HANDLE;
  261. PROBE_READ(lpclient);
  262. PROBE_READ(lpobjname);
  263. if (!lpobjname[0])
  264. return OLE_ERROR_NAME;
  265. PROBE_WRITE(lplpobj);
  266. *lplpobj = NULL;
  267. retVal = (*lpobjsrc->lpvtbl->Clone) (lpobjsrc, lpclient,
  268. lhclientdoc, lpobjname, lplpobj);
  269. if ((lpobjsrc->iTable != INVALID_INDEX) && (retVal <= OLE_WAIT_FOR_RELEASE))
  270. lpDllTable[lpobjsrc->iTable].cObj++;
  271. return retVal;
  272. }
  273. OLESTATUS FAR PASCAL OleCopyFromLink (
  274. LPOLEOBJECT lpobjsrc,
  275. LPCSTR lpprotocol,
  276. LPOLECLIENT lpclient,
  277. LHCLIENTDOC lhclientdoc,
  278. LPCSTR lpobjname,
  279. LPOLEOBJECT FAR * lplpobj
  280. ){
  281. OLESTATUS retVal;
  282. Puts("OleCopyFromLnk");
  283. if (!CheckObject(lpobjsrc))
  284. return(OLE_ERROR_OBJECT);
  285. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  286. return OLE_ERROR_HANDLE;
  287. PROBE_READ(lpprotocol);
  288. PROBE_WRITE(lplpobj);
  289. PROBE_READ(lpclient);
  290. PROBE_READ(lpobjname);
  291. if (!lpobjname[0])
  292. return OLE_ERROR_NAME;
  293. *lplpobj = NULL;
  294. if (lstrcmpi (lpprotocol, PROTOCOL_EDIT))
  295. return OLE_ERROR_PROTOCOL;
  296. retVal = (*lpobjsrc->lpvtbl->CopyFromLink) (lpobjsrc, lpclient,
  297. lhclientdoc, lpobjname, lplpobj);
  298. if ((lpobjsrc->iTable != INVALID_INDEX) && (retVal <= OLE_WAIT_FOR_RELEASE))
  299. lpDllTable[lpobjsrc->iTable].cObj++;
  300. return retVal;
  301. }
  302. OLESTATUS FAR PASCAL OleEqual (
  303. LPOLEOBJECT lpobj1,
  304. LPOLEOBJECT lpobj2
  305. ){
  306. if (!CheckObject(lpobj1))
  307. return OLE_ERROR_OBJECT;
  308. if (!CheckObject(lpobj2))
  309. return OLE_ERROR_OBJECT;
  310. if (lpobj1->ctype != lpobj2->ctype)
  311. return OLE_ERROR_NOT_EQUAL;
  312. return ((*lpobj1->lpvtbl->Equal) (lpobj1, lpobj2));
  313. }
  314. /***************************** Public Function ****************************\
  315. *
  316. * OLESTATUS FAR PASCAL OleQueryLinkFromClip (lpprotcol, optRender, cfFormat)
  317. *
  318. * oleQueryFromClip: Returns OLE_OK if a linked object can be created.
  319. *
  320. *
  321. * Effects:
  322. *
  323. * History:
  324. * Wrote it.
  325. \***************************************************************************/
  326. OLESTATUS FAR PASCAL OleQueryLinkFromClip (
  327. LPCSTR lpprotocol,
  328. OLEOPT_RENDER optRender,
  329. OLECLIPFORMAT cfFormat
  330. ){
  331. Puts("OleQueryLinkFromClip");
  332. return LeQueryCreateFromClip ((LPSTR)lpprotocol, optRender,
  333. cfFormat, CT_LINK);
  334. }
  335. /***************************** Public Function ****************************\
  336. *
  337. * OLESTATUS FAR PASCAL OleQueryCreateFromClip (lpprotcol, optRender, cfFormat)
  338. *
  339. * oleQueryCreateFromClip: Returns true if a non-linked object can be
  340. * created.
  341. *
  342. *
  343. * Effects:
  344. *
  345. * History:
  346. * Wrote it.
  347. \***************************************************************************/
  348. OLESTATUS FAR PASCAL OleQueryCreateFromClip (
  349. LPCSTR lpprotocol,
  350. OLEOPT_RENDER optRender,
  351. OLECLIPFORMAT cfFormat
  352. ){
  353. Puts("OleQueryCreateFromClip");
  354. return (LeQueryCreateFromClip ((LPSTR)lpprotocol, optRender,
  355. cfFormat, CT_EMBEDDED));
  356. }
  357. /***************************** Public Function ****************************\
  358. *
  359. * OLESTATUS FAR PASCAL OleCreateLinkFromClip (lpprotcol, lpclient, lhclientdoc, lpobjname, lplpoleobject, optRender, cfFormat)
  360. *
  361. *
  362. * oleCreateLinkFromClip: This function creates the LP to an object from the
  363. * clipboard. It will try to create a linked object. Return value is OLE_OK
  364. * is the object is successfully created it
  365. *
  366. * Effects:
  367. *
  368. * History:
  369. * Wrote it.
  370. \***************************************************************************/
  371. OLESTATUS FAR PASCAL OleCreateLinkFromClip (
  372. LPCSTR lpprotocol,
  373. LPOLECLIENT lpclient,
  374. LHCLIENTDOC lhclientdoc,
  375. LPCSTR lpobjname,
  376. LPOLEOBJECT FAR * lplpobj,
  377. OLEOPT_RENDER optRender,
  378. OLECLIPFORMAT cfFormat
  379. ){
  380. int objCount;
  381. int iTable = INVALID_INDEX;
  382. OLESTATUS retVal;
  383. LPSTR lpInfo;
  384. Puts("OleCreateLinkFromClip");
  385. PROBE_MODE(bProtMode);
  386. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  387. return OLE_ERROR_HANDLE;
  388. PROBE_READ(lpprotocol);
  389. PROBE_READ(lpclient);
  390. PROBE_WRITE(lplpobj);
  391. PROBE_READ(lpobjname);
  392. if (!lpobjname[0])
  393. return OLE_ERROR_NAME;
  394. *lplpobj = NULL;
  395. if (lstrcmpi (lpprotocol, PROTOCOL_EDIT))
  396. return OLE_ERROR_PROTOCOL;
  397. if (IsClipboardFormatAvailable (cfFileName))
  398. return CreatePackageFromClip (lpclient, lhclientdoc, (LPSTR)lpobjname,
  399. lplpobj, optRender, cfFormat, CT_LINK);
  400. if (!(hInfo = GetClipboardData (cfObjectLink)))
  401. return OLE_ERROR_CLIPBOARD;
  402. if (!(lpInfo = GlobalLock(hInfo)))
  403. return OLE_ERROR_CLIPBOARD;
  404. iTable = LoadDll (lpInfo);
  405. GlobalUnlock (hInfo);
  406. if (iTable == INVALID_INDEX)
  407. retVal = DefCreateLinkFromClip ((LPSTR)lpprotocol, lpclient, lhclientdoc,
  408. (LPSTR)lpobjname, lplpobj, optRender, cfFormat);
  409. else {
  410. objCount = lpDllTable[iTable].cObj;
  411. retVal = (*lpDllTable[iTable].Link) ((LPSTR)lpprotocol, lpclient,
  412. lhclientdoc, (LPSTR)lpobjname, lplpobj, optRender, cfFormat);
  413. if (retVal > OLE_WAIT_FOR_RELEASE)
  414. lpDllTable[iTable].cObj = objCount - 1;
  415. else
  416. (*lplpobj)->iTable = iTable;
  417. }
  418. hInfo = NULL;
  419. return retVal;
  420. }
  421. /***************************** Public Function ****************************\
  422. *
  423. * OLESTATUS FAR PASCAL OleCreateFromClip (lpprotcol, lpclient, lplpoleobject, optRender, cfFormat)
  424. *
  425. *
  426. * oleCreateFromClip: This function creates the LP to an object
  427. * from the clipboard. It will try to create an embedded object if
  428. * OwnerLink and Native are available, otherwise it will create a static
  429. * picture. Return value is OLE_OK if the object is successfully
  430. * created it.
  431. *
  432. * Effects:
  433. *
  434. * History:
  435. * Wrote it.
  436. \***************************************************************************/
  437. OLESTATUS FAR PASCAL OleCreateFromClip (
  438. LPCSTR lpprotocol,
  439. LPOLECLIENT lpclient,
  440. LHCLIENTDOC lhclientdoc,
  441. LPCSTR lpobjname,
  442. LPOLEOBJECT FAR * lplpobj,
  443. OLEOPT_RENDER optRender,
  444. OLECLIPFORMAT cfFormat
  445. ){
  446. OLESTATUS retVal;
  447. LONG ctype;
  448. int iTable = INVALID_INDEX;
  449. LPSTR lpInfo;
  450. LPSTR lpClass = NULL;
  451. int objCount;
  452. OLECLIPFORMAT cfEnum = 0;
  453. Puts("OleCreateFromClip");
  454. PROBE_MODE(bProtMode);
  455. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  456. return OLE_ERROR_HANDLE;
  457. PROBE_READ(lpprotocol);
  458. PROBE_READ(lpclient);
  459. PROBE_WRITE(lplpobj);
  460. PROBE_READ(lpobjname);
  461. if (!lpobjname[0])
  462. return OLE_ERROR_NAME;
  463. *lplpobj = NULL;
  464. if (!lstrcmpi (lpprotocol, PROTOCOL_STATIC)) {
  465. if (optRender == olerender_none)
  466. return OLE_ERROR_OPTION;
  467. if ( (optRender == olerender_format) &&
  468. (cfFormat != CF_METAFILEPICT) &&
  469. (cfFormat != CF_DIB) &&
  470. (cfFormat != CF_BITMAP) &&
  471. (cfFormat != CF_ENHMETAFILE))
  472. return OLE_ERROR_FORMAT;
  473. if (!IsClipboardFormatAvailable (CF_METAFILEPICT)
  474. && !IsClipboardFormatAvailable (CF_DIB)
  475. && !IsClipboardFormatAvailable (CF_BITMAP)
  476. && !IsClipboardFormatAvailable (CF_ENHMETAFILE) )
  477. return OLE_ERROR_FORMAT;
  478. return CreatePictFromClip (lpclient, lhclientdoc,
  479. (LPSTR)lpobjname, lplpobj, optRender,
  480. cfFormat, NULL, CT_STATIC);
  481. }
  482. else if (!lstrcmpi (lpprotocol, PROTOCOL_EDIT)) {
  483. if (IsClipboardFormatAvailable (cfFileName))
  484. return CreatePackageFromClip (lpclient, lhclientdoc, (LPSTR)lpobjname,
  485. lplpobj, optRender, cfFormat, CT_EMBEDDED);
  486. if (!(hInfo = GetClipboardData (cfOwnerLink)))
  487. return OLE_ERROR_CLIPBOARD;
  488. while (TRUE) {
  489. cfEnum = (OLECLIPFORMAT)EnumClipboardFormats ((WORD)cfEnum);
  490. if (cfEnum == (OLECLIPFORMAT)cfNative) {
  491. ctype = CT_EMBEDDED;
  492. break;
  493. }
  494. else if (cfEnum == cfOwnerLink) {
  495. ctype = CT_LINK;
  496. break;
  497. }
  498. }
  499. if (!(lpInfo = GlobalLock(hInfo)))
  500. return OLE_ERROR_CLIPBOARD;
  501. iTable = LoadDll (lpInfo);
  502. GlobalUnlock (hInfo);
  503. }
  504. else {
  505. return OLE_ERROR_PROTOCOL;
  506. }
  507. if (iTable == INVALID_INDEX)
  508. retVal = DefCreateFromClip ((LPSTR)lpprotocol, lpclient, lhclientdoc,
  509. (LPSTR)lpobjname, lplpobj, optRender, cfFormat, ctype);
  510. else {
  511. objCount = lpDllTable[iTable].cObj;
  512. retVal = (*lpDllTable[iTable].Clip) ((LPSTR)lpprotocol, lpclient,
  513. lhclientdoc, (LPSTR)lpobjname, lplpobj,
  514. optRender, cfFormat, ctype);
  515. if (retVal > OLE_WAIT_FOR_RELEASE)
  516. lpDllTable[iTable].cObj = objCount - 1;
  517. else
  518. (*lplpobj)->iTable = iTable;
  519. }
  520. hInfo = NULL;
  521. return retVal;
  522. }
  523. /***************************** Public Function ****************************\
  524. *
  525. * OLESTATUS FAR PASCAL OleCopyToClipboard (lpobj)
  526. *
  527. *
  528. * oleCopyToClipboard: This routine executes the standard "Copy" menu item
  529. * on the typical "Edit" menu. Returns TRUE if successful.
  530. *
  531. * Effects:
  532. *
  533. * History:
  534. * Wrote it.
  535. \***************************************************************************/
  536. OLESTATUS FAR PASCAL OleCopyToClipboard (
  537. LPOLEOBJECT lpobj
  538. ){
  539. Puts("OleCopyToClipboard");
  540. if (!CheckObject(lpobj))
  541. return(OLE_ERROR_OBJECT);
  542. return ((*lpobj->lpvtbl->CopyToClipboard) (lpobj));
  543. }
  544. OLESTATUS FAR PASCAL OleSetHostNames (
  545. LPOLEOBJECT lpobj,
  546. LPCSTR lpclientName,
  547. LPCSTR lpdocName
  548. ){
  549. Puts ("OleSetHostNames");
  550. if (!CheckObject(lpobj))
  551. return(OLE_ERROR_OBJECT);
  552. PROBE_READ(lpclientName);
  553. PROBE_READ(lpdocName);
  554. return ((*lpobj->lpvtbl->SetHostNames) (lpobj, lpclientName, lpdocName));
  555. }
  556. OLESTATUS FAR PASCAL OleSetTargetDevice (
  557. LPOLEOBJECT lpobj,
  558. HANDLE hDevInfo
  559. ){
  560. Puts("OleSetTargetDevice");
  561. if (!CheckObject(lpobj))
  562. return(OLE_ERROR_OBJECT);
  563. return ((*lpobj->lpvtbl->SetTargetDevice) (lpobj, hDevInfo));
  564. }
  565. OLESTATUS FAR PASCAL OleSetColorScheme (
  566. LPOLEOBJECT lpobj,
  567. const LOGPALETTE FAR *lplogpal
  568. ){
  569. Puts("OleSetColorScheme");
  570. if (!CheckObject(lpobj))
  571. return(OLE_ERROR_OBJECT);
  572. return ((*lpobj->lpvtbl->SetColorScheme) (lpobj, (LOGPALETTE FAR *)lplogpal));
  573. }
  574. OLESTATUS FAR PASCAL OleSetBounds(
  575. LPOLEOBJECT lpobj,
  576. const RECT FAR *lprc
  577. ){
  578. Puts("OleSetBounds");
  579. if (!CheckObject(lpobj))
  580. return OLE_ERROR_OBJECT;
  581. PROBE_READ((RECT FAR *)lprc);
  582. return ((*lpobj->lpvtbl->SetBounds) (lpobj, (RECT FAR *)lprc));
  583. }
  584. /***************************** Public Function ****************************\
  585. * OLESTATUS FAR PASCAL OleQueryBounds (lpobj, lpRc)
  586. *
  587. * Returns the bounds of the object in question in MM_HIMETRIC mode.
  588. * width = lprc->right - lprc->left; in HIMETRIC units
  589. * height = lprc->top - lprc->bottom; in HIMETRIC units
  590. *
  591. * Returns OLE_OK or OLE_ERROR_MEMORY.
  592. *
  593. *
  594. * Effects:
  595. *
  596. * History:
  597. * Wrote it.
  598. \***************************************************************************/
  599. OLESTATUS FAR PASCAL OleQueryBounds (
  600. LPOLEOBJECT lpobj,
  601. LPRECT lprc
  602. ){
  603. Puts("OleQueryBounds");
  604. if (!CheckObject(lpobj))
  605. return(OLE_ERROR_OBJECT);
  606. PROBE_WRITE(lprc);
  607. return (*lpobj->lpvtbl->QueryBounds) (lpobj, lprc);
  608. }
  609. /***************************** Public Function ****************************\
  610. * OLESTATUS FAR PASCAL OleQuerySize (lpobj, lpsize)
  611. *
  612. * Effects:
  613. *
  614. * History:
  615. * Wrote it.
  616. \***************************************************************************/
  617. OLESTATUS FAR PASCAL OleQuerySize (
  618. LPOLEOBJECT lpobj,
  619. DWORD FAR * lpdwSize
  620. ){
  621. Puts("OleQuerySize");
  622. if (!CheckObject(lpobj))
  623. return OLE_ERROR_OBJECT;
  624. PROBE_WRITE(lpdwSize);
  625. *lpdwSize = 0;
  626. return (*lpobj->lpvtbl->QuerySize) (lpobj, lpdwSize);
  627. }
  628. /***************************** Public Function ****************************\
  629. * OLESTATUS FAR PASCAL OleDraw (lpobj, hdc, lprc, lpWrc, lphdcTarget)
  630. *
  631. * oleObjectDraw: This displays the given object on the device context <hcd>.
  632. * The <htargetdc> parameter is not currently used. Returns same as Draw().
  633. *
  634. * Expects rectangle coordinates in MM_HIMETRIC units.
  635. *
  636. *
  637. * Effects:
  638. *
  639. * History:
  640. * Wrote it.
  641. \***************************************************************************/
  642. OLESTATUS FAR PASCAL OleDraw (
  643. LPOLEOBJECT lpobj,
  644. HDC hdc,
  645. const RECT FAR *lprc,
  646. const RECT FAR *lpWrc,
  647. HDC hdcTarget
  648. ){
  649. Puts("OleObjectDraw");
  650. if (!FarCheckObject(lpobj))
  651. return(OLE_ERROR_OBJECT);
  652. PROBE_READ((RECT FAR *)lprc);
  653. if (lpWrc)
  654. PROBE_READ((RECT FAR *)lpWrc);
  655. return ((*lpobj->lpvtbl->Draw) (lpobj, hdc, (RECT FAR *)lprc, (RECT FAR *)lpWrc, hdcTarget));
  656. }
  657. /***************************** Public Function ****************************\
  658. *
  659. * OLESTATUS FAR PASCAL OleQueryOpen (lpobj)
  660. *
  661. * returns TRUE is an object has been activated.
  662. *
  663. *
  664. * Effects:
  665. *
  666. * History:
  667. * Wrote it.
  668. \***************************************************************************/
  669. OLESTATUS FAR PASCAL OleQueryOpen (
  670. LPOLEOBJECT lpobj
  671. ){
  672. Puts("OleQueryOpen");
  673. if (!CheckObject(lpobj))
  674. return(OLE_ERROR_OBJECT);
  675. return (*lpobj->lpvtbl->QueryOpen) (lpobj);
  676. }
  677. /***************************** Public Function ****************************\
  678. *
  679. * OLESTATUS FAR PASCAL OleActivate (lpobj)
  680. *
  681. * Activates an object. For embeded objects always a new instance is
  682. * loaded and the instance is destroyed once the data is transferred
  683. * at close time. For linked objects, an instance of the render is created
  684. * only if one does not exist.
  685. * Effects:
  686. *
  687. * History:
  688. * Wrote it.
  689. \***************************************************************************/
  690. OLESTATUS FAR PASCAL OleActivate (
  691. LPOLEOBJECT lpobj,
  692. UINT verb,
  693. BOOL fShow,
  694. BOOL fActivate,
  695. HWND hWnd,
  696. const RECT FAR *lprc
  697. ){
  698. Puts("OleActivate");
  699. if (!CheckObject(lpobj))
  700. return(OLE_ERROR_OBJECT);
  701. /* PROBE_READ(lprc); */
  702. return (*lpobj->lpvtbl->Activate) (lpobj, verb, fShow, fActivate, hWnd, (RECT FAR *)lprc);
  703. }
  704. OLESTATUS FAR PASCAL OleClose (
  705. LPOLEOBJECT lpobj
  706. ){
  707. Puts("OleClose");
  708. if (!CheckObject(lpobj))
  709. return(OLE_ERROR_OBJECT);
  710. return (*lpobj->lpvtbl->Close) (lpobj);
  711. }
  712. /***************************** Public Function ****************************\
  713. *
  714. * OLESTATUS FAR PASCAL OleUpdate (lpobj)
  715. *
  716. * If there exists a link, sends advise for getting the latest rendering
  717. * infromation. If there is no link, loads an instance, advises for the
  718. * render information and closes the instance once the data is available.
  719. * (If possible should not show the window).
  720. *
  721. * History:
  722. * Wrote it.
  723. \***************************************************************************/
  724. OLESTATUS FAR PASCAL OleUpdate (
  725. LPOLEOBJECT lpobj
  726. ){
  727. Puts("OleUpdate");
  728. if (!CheckObject(lpobj))
  729. return(OLE_ERROR_OBJECT);
  730. return (*lpobj->lpvtbl->Update) (lpobj);
  731. }
  732. /***************************** Public Function ****************************\
  733. *
  734. * OLESTATUS FAR PASCAL OleReconnect (lpobj)
  735. *
  736. * Reconnects to the renderer if one does not exist already.
  737. *
  738. * History:
  739. * Wrote it.
  740. \***************************************************************************/
  741. OLESTATUS FAR PASCAL OleReconnect (
  742. LPOLEOBJECT lpobj
  743. ){
  744. Puts("OleReconnect");
  745. if (!CheckObject(lpobj))
  746. return(OLE_ERROR_OBJECT);
  747. return (*lpobj->lpvtbl->Reconnect) (lpobj);
  748. }
  749. OLESTATUS FAR PASCAL OleGetLinkUpdateOptions (
  750. LPOLEOBJECT lpobj,
  751. OLEOPT_UPDATE FAR * lpOptions
  752. ){
  753. Puts("OleGetLinkUpdateOptions");
  754. if (!CheckObject(lpobj))
  755. return(OLE_ERROR_OBJECT);
  756. PROBE_WRITE(lpOptions);
  757. return (*lpobj->lpvtbl->GetLinkUpdateOptions) (lpobj, lpOptions);
  758. }
  759. OLESTATUS FAR PASCAL OleSetLinkUpdateOptions (
  760. LPOLEOBJECT lpobj,
  761. OLEOPT_UPDATE options
  762. ){
  763. Puts("OleSetLinkUpdateOptions");
  764. if (!CheckObject(lpobj))
  765. return(OLE_ERROR_OBJECT);
  766. return (*lpobj->lpvtbl->SetLinkUpdateOptions) (lpobj, options);
  767. }
  768. /***************************** Public Function ****************************\
  769. * OLESTATUS FAR PASCAL OleEnumFormats (lpobj, cfFormat)
  770. *
  771. * Returns OLE_YES if the object is of type LINK or EMBEDDED.
  772. *
  773. * Effects:
  774. *
  775. * History:
  776. * Wrote it.
  777. \***************************************************************************/
  778. OLECLIPFORMAT FAR PASCAL OleEnumFormats (
  779. LPOLEOBJECT lpobj,
  780. OLECLIPFORMAT cfFormat
  781. ){
  782. Puts("OleEnumFormats");
  783. if (!CheckObject(lpobj))
  784. return 0;
  785. return (*lpobj->lpvtbl->EnumFormats) (lpobj, cfFormat);
  786. }
  787. OLESTATUS FAR PASCAL OleRequestData (
  788. LPOLEOBJECT lpobj,
  789. OLECLIPFORMAT cfFormat
  790. ){
  791. Puts("OleGetData");
  792. if (!CheckObject(lpobj))
  793. return(OLE_ERROR_OBJECT);
  794. if (!cfFormat)
  795. return OLE_ERROR_FORMAT;
  796. return (*lpobj->lpvtbl->RequestData) (lpobj, cfFormat);
  797. }
  798. OLESTATUS FAR PASCAL OleGetData (
  799. LPOLEOBJECT lpobj,
  800. OLECLIPFORMAT cfFormat,
  801. LPHANDLE lphandle
  802. ){
  803. Puts("OleGetData");
  804. if (!CheckObject(lpobj))
  805. return(OLE_ERROR_OBJECT);
  806. PROBE_WRITE((LPVOID)lphandle);
  807. return (*lpobj->lpvtbl->GetData) (lpobj, cfFormat, lphandle);
  808. }
  809. OLESTATUS FAR PASCAL OleSetData (
  810. LPOLEOBJECT lpobj,
  811. OLECLIPFORMAT cfFormat,
  812. HANDLE hData
  813. ){
  814. Puts("OleSetData");
  815. if (!CheckObject(lpobj))
  816. return(OLE_ERROR_OBJECT);
  817. return (*lpobj->lpvtbl->SetData) (lpobj, cfFormat, hData);
  818. }
  819. OLESTATUS FAR PASCAL OleQueryOutOfDate (
  820. LPOLEOBJECT lpobj
  821. ){
  822. if (!CheckObject(lpobj))
  823. return(OLE_ERROR_OBJECT);
  824. return (*lpobj->lpvtbl->QueryOutOfDate) (lpobj);
  825. }
  826. OLESTATUS FAR PASCAL OleLockServer (
  827. LPOLEOBJECT lpobjsrc,
  828. LHSERVER FAR * lplhsrvr
  829. ){
  830. LPOBJECT_LE lpobj;
  831. OLESTATUS retVal = OLE_OK;
  832. ATOM aCliClass, aSvrClass;
  833. Puts ("OleLockServer");
  834. if (!FarCheckObject(lpobjsrc))
  835. return OLE_ERROR_OBJECT;
  836. if (lpobjsrc->ctype == CT_STATIC)
  837. return OLE_ERROR_STATIC;
  838. // Assumes all the creates are in order
  839. PROBE_CREATE_ASYNC(((LPOBJECT_LE)lpobjsrc));
  840. FARPROBE_WRITE(lplhsrvr);
  841. aCliClass = ((LPCLIENTDOC)(lpobjsrc->lhclientdoc))->aClass;
  842. aSvrClass = ((LPOBJECT_LE)lpobjsrc)->app;
  843. // See whether the server is already locked
  844. lpobj = (LPOBJECT_LE) (lockDoc.lpHeadObj);
  845. while (lpobj) {
  846. if ((lpobj->app == aSvrClass) && (lpobj->topic == aCliClass)) {
  847. if (!lpobj->head.cx) {
  848. // The unlocking process of server handle has started. This
  849. // is an asynchronous process. We want to let it complete.
  850. // Let's try the next handle
  851. ;
  852. }
  853. else {
  854. if (!IsServerValid (lpobj)) {
  855. DeleteSrvrEdit (lpobj);
  856. retVal = LockServer (lpobj);
  857. }
  858. else {
  859. // Lock count
  860. lpobj->head.cx++;
  861. }
  862. if (retVal == OLE_OK)
  863. *lplhsrvr = (LHSERVER) lpobj;
  864. return retVal;
  865. }
  866. }
  867. lpobj = (LPOBJECT_LE) (lpobj->head.lpNextObj);
  868. }
  869. if (!(lpobj = LeCreateBlank(lhLockDoc, NULL, OT_EMBEDDED)))
  870. return OLE_ERROR_MEMORY;
  871. lpobj->head.lpclient = NULL;
  872. lpobj->head.lpvtbl = lpobjsrc->lpvtbl;
  873. lpobj->app = DuplicateAtom (aSvrClass);
  874. lpobj->topic = DuplicateAtom (aCliClass);
  875. lpobj->aServer = DuplicateAtom(((LPOBJECT_LE)lpobjsrc)->aServer);
  876. lpobj->bOleServer = ((LPOBJECT_LE)lpobjsrc)->bOleServer;
  877. if ((retVal = LockServer (lpobj)) == OLE_OK) {
  878. // Change signature
  879. lpobj->head.objId[0] = 'S';
  880. lpobj->head.objId[1] = 'L';
  881. *lplhsrvr = (LHSERVER) lpobj;
  882. }
  883. else {
  884. LeRelease ((LPOLEOBJECT)lpobj);
  885. }
  886. return retVal;
  887. }
  888. OLESTATUS INTERNAL LockServer (
  889. LPOBJECT_LE lpobj
  890. ){
  891. HANDLE hInst;
  892. if (!InitSrvrConv (lpobj, NULL)) {
  893. if (!lpobj->bOleServer)
  894. lpobj->fCmd = ACT_MINIMIZE;
  895. else
  896. lpobj->fCmd = 0;
  897. if (!(hInst = LeLaunchApp (lpobj)))
  898. return OLE_ERROR_LAUNCH;
  899. if (!InitSrvrConv (lpobj, hInst))
  900. return OLE_ERROR_COMM;
  901. }
  902. // lock count
  903. lpobj->head.cx++;
  904. return OLE_OK;
  905. }
  906. OLESTATUS FAR PASCAL OleUnlockServer (
  907. LHSERVER lhsrvr
  908. ){
  909. LPOBJECT_LE lpobj;
  910. OLESTATUS retval;
  911. Puts ("OleUnlockServer");
  912. if (!FarCheckPointer ((lpobj = (LPOBJECT_LE)lhsrvr), WRITE_ACCESS))
  913. return OLE_ERROR_HANDLE;
  914. if (lpobj->head.objId[0] != 'S' || lpobj->head.objId[1] != 'L')
  915. return OLE_ERROR_HANDLE;
  916. if (!lpobj->head.cx)
  917. return OLE_OK;
  918. if (--lpobj->head.cx)
  919. return OLE_OK;
  920. //change signature
  921. lpobj->head.objId[0] = 'L';
  922. lpobj->head.objId[1] = 'E';
  923. if ((retval = LeRelease((LPOLEOBJECT)lpobj)) == OLE_WAIT_FOR_RELEASE)
  924. DocDeleteObject ((LPOLEOBJECT)lpobj);
  925. return retval;
  926. }
  927. OLESTATUS FAR PASCAL OleObjectConvert (
  928. LPOLEOBJECT lpobj,
  929. LPCSTR lpprotocol,
  930. LPOLECLIENT lpclient,
  931. LHCLIENTDOC lhclientdoc,
  932. LPCSTR lpobjname,
  933. LPOLEOBJECT FAR * lplpobj
  934. ){
  935. if (!CheckObject(lpobj))
  936. return(OLE_ERROR_OBJECT);
  937. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  938. return OLE_ERROR_HANDLE;
  939. PROBE_READ(lpprotocol);
  940. PROBE_WRITE(lplpobj);
  941. PROBE_READ(lpobjname);
  942. if (!lpobjname[0])
  943. return OLE_ERROR_NAME;
  944. return (*lpobj->lpvtbl->ObjectConvert) (lpobj, lpprotocol, lpclient,
  945. lhclientdoc, lpobjname, lplpobj);
  946. }
  947. //OleCreateFromTemplate: Creates an embedded object from Template
  948. OLESTATUS FAR PASCAL OleCreateFromTemplate (
  949. LPCSTR lpprotocol,
  950. LPOLECLIENT lpclient,
  951. LPCSTR lptemplate,
  952. LHCLIENTDOC lhclientdoc,
  953. LPCSTR lpobjname,
  954. LPOLEOBJECT FAR * lplpoleobject,
  955. OLEOPT_RENDER optRender,
  956. OLECLIPFORMAT cfFormat
  957. ){
  958. OLESTATUS retval = OLE_ERROR_MEMORY;
  959. char buf[MAX_STR];
  960. int objCount;
  961. int iTable = INVALID_INDEX;
  962. Puts("OleCreateFromTemplate");
  963. PROBE_MODE(bProtMode);
  964. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  965. return OLE_ERROR_HANDLE;
  966. PROBE_READ(lpprotocol);
  967. PROBE_READ(lpclient);
  968. PROBE_READ(lptemplate);
  969. PROBE_WRITE(lplpoleobject);
  970. PROBE_READ(lpobjname);
  971. if (!lpobjname[0])
  972. return OLE_ERROR_NAME;
  973. if (lstrcmpi (lpprotocol, PROTOCOL_EDIT))
  974. return OLE_ERROR_PROTOCOL;
  975. if (!MapExtToClass ((LPSTR)lptemplate, (LPSTR)buf, MAX_STR))
  976. return OLE_ERROR_CLASS;
  977. // !!! we found the class name. At this point, we need to load
  978. // the right library and call the right entry point;
  979. iTable = LoadDll (buf);
  980. if (iTable == INVALID_INDEX)
  981. retval = DefCreateFromTemplate ((LPSTR)lpprotocol, lpclient,
  982. (LPSTR)lptemplate,
  983. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  984. optRender, cfFormat);
  985. else {
  986. objCount = lpDllTable[iTable].cObj;
  987. retval = (*lpDllTable[iTable].CreateFromTemplate) ((LPSTR)lpprotocol,
  988. lpclient, (LPSTR)lptemplate,
  989. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  990. optRender, cfFormat);
  991. if (retval > OLE_WAIT_FOR_RELEASE)
  992. lpDllTable[iTable].cObj = objCount - 1;
  993. else
  994. (*lplpoleobject)->iTable = iTable;
  995. }
  996. return retval;
  997. }
  998. //OleCreate: Creates an embedded object from the class.
  999. OLESTATUS FAR PASCAL OleCreate (
  1000. LPCSTR lpprotocol,
  1001. LPOLECLIENT lpclient,
  1002. LPCSTR lpclass,
  1003. LHCLIENTDOC lhclientdoc,
  1004. LPCSTR lpobjname,
  1005. LPOLEOBJECT FAR * lplpoleobject,
  1006. OLEOPT_RENDER optRender,
  1007. OLECLIPFORMAT cfFormat
  1008. ){
  1009. OLESTATUS retval = OLE_ERROR_MEMORY;
  1010. int objCount;
  1011. int iTable = INVALID_INDEX;
  1012. Puts("OleCreate");
  1013. PROBE_MODE(bProtMode);
  1014. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  1015. return OLE_ERROR_HANDLE;
  1016. PROBE_READ(lpprotocol);
  1017. PROBE_READ(lpclient);
  1018. PROBE_READ(lpclass);
  1019. PROBE_WRITE(lplpoleobject);
  1020. PROBE_READ(lpobjname);
  1021. if (!lpobjname[0])
  1022. return OLE_ERROR_NAME;
  1023. if (lstrcmpi (lpprotocol, PROTOCOL_EDIT))
  1024. return OLE_ERROR_PROTOCOL;
  1025. iTable = LoadDll (lpclass);
  1026. if (iTable == INVALID_INDEX)
  1027. retval = DefCreate ((LPSTR)lpprotocol, lpclient, (LPSTR)lpclass,
  1028. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1029. optRender, cfFormat);
  1030. else {
  1031. objCount = lpDllTable[iTable].cObj;
  1032. retval = (*lpDllTable[iTable].Create) ((LPSTR)lpprotocol,
  1033. lpclient, (LPSTR)lpclass,
  1034. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1035. optRender, cfFormat);
  1036. if (retval > OLE_WAIT_FOR_RELEASE)
  1037. lpDllTable[iTable].cObj = objCount - 1;
  1038. else
  1039. (*lplpoleobject)->iTable = iTable;
  1040. }
  1041. return retval;
  1042. }
  1043. //////////////////////////////////////////////////////////////////////////////
  1044. //
  1045. // OLESTATUS FAR PASCAL OleCreateInvisible (lpprotocol, lpclient, lpclass, lhclientdoc, lpobjname, lplpoleobject, optRender, cfFormat, bLaunchServer)
  1046. //
  1047. // Creates an embedded object from the class.
  1048. //
  1049. // Arguments:
  1050. //
  1051. // lpprotocol -
  1052. // lpclient -
  1053. // lpclass -
  1054. // lhclientdoc -
  1055. // lpobjname -
  1056. // lplpoleobject -
  1057. // optRender -
  1058. // cfFormat -
  1059. // bLaunchServer -
  1060. //
  1061. // Returns:
  1062. //
  1063. // OLE_ERROR_HANDLE -
  1064. // OLE_ERROR_NAME -
  1065. // OLE_ERROR_PROTOCOL -
  1066. //
  1067. // Effects:
  1068. //
  1069. //////////////////////////////////////////////////////////////////////////////
  1070. OLESTATUS FAR PASCAL OleCreateInvisible (
  1071. LPCSTR lpprotocol,
  1072. LPOLECLIENT lpclient,
  1073. LPCSTR lpclass,
  1074. LHCLIENTDOC lhclientdoc,
  1075. LPCSTR lpobjname,
  1076. LPOLEOBJECT FAR * lplpoleobject,
  1077. OLEOPT_RENDER optRender,
  1078. OLECLIPFORMAT cfFormat,
  1079. BOOL bLaunchServer
  1080. ){
  1081. OLESTATUS retval = OLE_ERROR_MEMORY;
  1082. int objCount;
  1083. int iTable = INVALID_INDEX;
  1084. Puts("OleCreateInvisible");
  1085. PROBE_MODE(bProtMode);
  1086. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  1087. return OLE_ERROR_HANDLE;
  1088. PROBE_READ(lpprotocol);
  1089. PROBE_READ(lpclient);
  1090. PROBE_READ(lpclass);
  1091. PROBE_WRITE(lplpoleobject);
  1092. PROBE_READ(lpobjname);
  1093. if (!lpobjname[0])
  1094. return OLE_ERROR_NAME;
  1095. if (lstrcmpi (lpprotocol, PROTOCOL_EDIT))
  1096. return OLE_ERROR_PROTOCOL;
  1097. iTable = LoadDll (lpclass);
  1098. if (iTable == INVALID_INDEX) {
  1099. retval = DefCreateInvisible ((LPSTR)lpprotocol, lpclient, (LPSTR)lpclass,
  1100. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1101. optRender, cfFormat, bLaunchServer);
  1102. }
  1103. else {
  1104. objCount = lpDllTable[iTable].cObj;
  1105. if (!(lpDllTable[iTable].CreateInvisible)) {
  1106. // dll didn't export this function. Lets call DllCreate, so that
  1107. // handler will get a chance to replace the methods. The flag is
  1108. // used to tell the internal functions that this call infact wants
  1109. // to achieve the effect of CreateInvisble.
  1110. gbCreateInvisible = TRUE;
  1111. gbLaunchServer = bLaunchServer;
  1112. retval = (*lpDllTable[iTable].Create) ((LPSTR)lpprotocol,
  1113. lpclient, (LPSTR)lpclass,
  1114. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1115. optRender, cfFormat);
  1116. gbCreateInvisible = FALSE;
  1117. }
  1118. else {
  1119. retval = (*lpDllTable[iTable].CreateInvisible) ((LPSTR)lpprotocol,
  1120. lpclient, (LPSTR)lpclass,
  1121. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1122. optRender, cfFormat, bLaunchServer);
  1123. }
  1124. if (retval > OLE_WAIT_FOR_RELEASE)
  1125. lpDllTable[iTable].cObj = objCount - 1;
  1126. else
  1127. (*lplpoleobject)->iTable = iTable;
  1128. }
  1129. return retval;
  1130. }
  1131. //OleCreateFromFile: Creates an embedded object from file
  1132. OLESTATUS FAR PASCAL OleCreateFromFile (
  1133. LPCSTR lpprotocol,
  1134. LPOLECLIENT lpclient,
  1135. LPCSTR lpclass,
  1136. LPCSTR lpfile,
  1137. LHCLIENTDOC lhclientdoc,
  1138. LPCSTR lpobjname,
  1139. LPOLEOBJECT FAR * lplpoleobject,
  1140. OLEOPT_RENDER optRender,
  1141. OLECLIPFORMAT cfFormat
  1142. ){
  1143. OLESTATUS retval = OLE_ERROR_MEMORY;
  1144. char buf[MAX_STR];
  1145. int objCount;
  1146. int iTable = INVALID_INDEX;
  1147. Puts("OleCreateFromFile");
  1148. PROBE_MODE(bProtMode);
  1149. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  1150. return OLE_ERROR_HANDLE;
  1151. PROBE_READ(lpprotocol);
  1152. PROBE_READ(lpclient);
  1153. PROBE_READ(lpfile);
  1154. PROBE_WRITE(lplpoleobject);
  1155. PROBE_READ(lpobjname);
  1156. if (!lpobjname[0])
  1157. return OLE_ERROR_NAME;
  1158. if (lpclass)
  1159. PROBE_READ(lpclass);
  1160. if (lstrcmpi (lpprotocol, PROTOCOL_EDIT))
  1161. return OLE_ERROR_PROTOCOL;
  1162. if (lpclass) {
  1163. if (!QueryApp (lpclass, lpprotocol, buf))
  1164. return OLE_ERROR_CLASS;
  1165. if (!lstrcmp (lpclass, packageClass))
  1166. iTable = INVALID_INDEX;
  1167. else
  1168. iTable = LoadDll (lpclass);
  1169. }
  1170. else if (MapExtToClass ((LPSTR)lpfile, buf, MAX_STR))
  1171. iTable = LoadDll (buf);
  1172. else
  1173. return OLE_ERROR_CLASS;
  1174. if (iTable == INVALID_INDEX)
  1175. retval = DefCreateFromFile ((LPSTR)lpprotocol,
  1176. lpclient, (LPSTR)lpclass, (LPSTR)lpfile,
  1177. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1178. optRender, cfFormat);
  1179. else {
  1180. objCount = lpDllTable[iTable].cObj;
  1181. retval = (*lpDllTable[iTable].CreateFromFile) ((LPSTR)lpprotocol,
  1182. lpclient, (LPSTR)lpclass, (LPSTR)lpfile,
  1183. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1184. optRender, cfFormat);
  1185. if (retval > OLE_WAIT_FOR_RELEASE)
  1186. lpDllTable[iTable].cObj = objCount - 1;
  1187. else
  1188. (*lplpoleobject)->iTable = iTable;
  1189. }
  1190. return retval;
  1191. }
  1192. //OleCreateLinkFromFile: Creates a linked object from file
  1193. OLESTATUS FAR PASCAL OleCreateLinkFromFile (
  1194. LPCSTR lpprotocol,
  1195. LPOLECLIENT lpclient,
  1196. LPCSTR lpclass,
  1197. LPCSTR lpfile,
  1198. LPCSTR lpitem,
  1199. LHCLIENTDOC lhclientdoc,
  1200. LPCSTR lpobjname,
  1201. LPOLEOBJECT FAR * lplpoleobject,
  1202. OLEOPT_RENDER optRender,
  1203. OLECLIPFORMAT cfFormat
  1204. ){
  1205. OLESTATUS retval = OLE_ERROR_MEMORY;
  1206. char buf[MAX_STR+6];
  1207. int objCount;
  1208. int iTable = INVALID_INDEX;
  1209. Puts("OleCreateLinkFromFile");
  1210. PROBE_MODE(bProtMode);
  1211. if (!CheckClientDoc ((LPCLIENTDOC) lhclientdoc))
  1212. return OLE_ERROR_HANDLE;
  1213. PROBE_READ(lpprotocol);
  1214. PROBE_READ(lpclient);
  1215. PROBE_READ(lpfile);
  1216. PROBE_WRITE(lplpoleobject);
  1217. PROBE_READ(lpobjname);
  1218. if (!lpobjname[0])
  1219. return OLE_ERROR_NAME;
  1220. if (lpclass)
  1221. PROBE_READ(lpclass);
  1222. if (lpitem)
  1223. PROBE_READ(lpitem);
  1224. if (lstrcmpi (lpprotocol, PROTOCOL_EDIT))
  1225. return OLE_ERROR_PROTOCOL;
  1226. if (lpclass) {
  1227. if (!QueryApp (lpclass, lpprotocol, buf))
  1228. return OLE_ERROR_CLASS;
  1229. if (!lstrcmp (lpclass, packageClass)) {
  1230. if (FAILED(StringCchCopy(buf, sizeof(buf)/sizeof(buf[0]), lpfile)))
  1231. return OLE_ERROR_NAME;
  1232. if (FAILED(StringCchCat(buf, sizeof(buf)/sizeof(buf[0]), "/Link")))
  1233. return OLE_ERROR_NAME;
  1234. return CreateEmbLnkFromFile (lpclient, packageClass, buf,
  1235. NULL, lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1236. optRender, cfFormat, OT_EMBEDDED);
  1237. }
  1238. else
  1239. iTable = LoadDll (lpclass);
  1240. }
  1241. else if (MapExtToClass ((LPSTR)lpfile, buf, MAX_STR))
  1242. iTable = LoadDll (buf);
  1243. else
  1244. return OLE_ERROR_CLASS;
  1245. if (iTable == INVALID_INDEX)
  1246. retval = DefCreateLinkFromFile ((LPSTR)lpprotocol,
  1247. lpclient, (LPSTR)lpclass, (LPSTR)lpfile, (LPSTR)lpitem,
  1248. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1249. optRender, cfFormat);
  1250. else {
  1251. objCount = lpDllTable[iTable].cObj;
  1252. retval = (*lpDllTable[iTable].CreateLinkFromFile) ((LPSTR)lpprotocol,
  1253. lpclient, (LPSTR)lpclass, (LPSTR)lpfile, (LPSTR)lpitem,
  1254. lhclientdoc, (LPSTR)lpobjname, lplpoleobject,
  1255. optRender, cfFormat);
  1256. if (retval > OLE_WAIT_FOR_RELEASE)
  1257. lpDllTable[iTable].cObj = objCount - 1;
  1258. else
  1259. (*lplpoleobject)->iTable = iTable;
  1260. }
  1261. return retval;
  1262. }
  1263. // Routines related to asynchronous operations.
  1264. OLESTATUS FAR PASCAL OleQueryReleaseStatus (
  1265. LPOLEOBJECT lpobj
  1266. ){
  1267. if (!CheckPointer (lpobj, WRITE_ACCESS))
  1268. return OLE_ERROR_OBJECT;
  1269. // make sure that it is a long pointer to L&E object or a lock handle
  1270. if (!(lpobj->objId[0] == 'L' && lpobj->objId[1] == 'E')
  1271. && !(lpobj->objId[0] == 'S' && lpobj->objId[1] == 'L'))
  1272. return OLE_ERROR_OBJECT;
  1273. return (*lpobj->lpvtbl->QueryReleaseStatus) (lpobj);
  1274. }
  1275. OLESTATUS FAR PASCAL OleQueryReleaseError (
  1276. LPOLEOBJECT lpobj
  1277. ){
  1278. if (!CheckObject(lpobj))
  1279. return(OLE_ERROR_OBJECT);
  1280. return (*lpobj->lpvtbl->QueryReleaseError) (lpobj);
  1281. }
  1282. OLE_RELEASE_METHOD FAR PASCAL OleQueryReleaseMethod (
  1283. LPOLEOBJECT lpobj
  1284. ){
  1285. if (!CheckObject(lpobj))
  1286. return(OLE_ERROR_OBJECT);
  1287. return (*lpobj->lpvtbl->QueryReleaseMethod) (lpobj);
  1288. }
  1289. OLESTATUS FAR PASCAL OleRename (
  1290. LPOLEOBJECT lpobj,
  1291. LPCSTR lpNewName
  1292. ){
  1293. if (!CheckObject(lpobj))
  1294. return OLE_ERROR_OBJECT;
  1295. return (*lpobj->lpvtbl->Rename) (lpobj, lpNewName);
  1296. }
  1297. OLESTATUS FAR PASCAL OleExecute (
  1298. LPOLEOBJECT lpobj,
  1299. HANDLE hCmds,
  1300. UINT wReserved
  1301. ){
  1302. if (!CheckObject(lpobj))
  1303. return OLE_ERROR_OBJECT;
  1304. return (*lpobj->lpvtbl->Execute) (lpobj, hCmds, wReserved);
  1305. }
  1306. OLESTATUS FAR PASCAL OleQueryName (
  1307. LPOLEOBJECT lpobj,
  1308. LPSTR lpBuf,
  1309. UINT FAR * lpcbBuf
  1310. ){
  1311. if (!CheckObject(lpobj))
  1312. return OLE_ERROR_OBJECT;
  1313. return (*lpobj->lpvtbl->QueryName) (lpobj, lpBuf, lpcbBuf);
  1314. }
  1315. OLESTATUS FAR PASCAL OleQueryType (
  1316. LPOLEOBJECT lpobj,
  1317. LPLONG lptype
  1318. ){
  1319. Puts("OleQueryType");
  1320. if (!CheckObject(lpobj))
  1321. return(OLE_ERROR_OBJECT);
  1322. PROBE_WRITE(lptype);
  1323. return (*lpobj->lpvtbl->QueryType) (lpobj, lptype);
  1324. }
  1325. DWORD FAR PASCAL OleQueryClientVersion ()
  1326. {
  1327. return dwOleVer;
  1328. }
  1329. OLESTATUS INTERNAL LeQueryCreateFromClip (
  1330. LPSTR lpprotocol,
  1331. OLEOPT_RENDER optRender,
  1332. OLECLIPFORMAT cfFormat,
  1333. LONG cType
  1334. ){
  1335. OLESTATUS retVal = TRUE;
  1336. BOOL bEdit = FALSE, bStatic = FALSE;
  1337. PROBE_MODE(bProtMode);
  1338. PROBE_READ(lpprotocol);
  1339. if (bEdit = !lstrcmpi (lpprotocol, PROTOCOL_EDIT)) {
  1340. if (IsClipboardFormatAvailable (cfFileName))
  1341. return OLE_OK;
  1342. if (cType == CT_LINK)
  1343. retVal = IsClipboardFormatAvailable (cfObjectLink);
  1344. #ifdef OLD
  1345. || IsClipboardFormatAvailable (cfLink) ;
  1346. #endif
  1347. else if (cType == CT_EMBEDDED)
  1348. retVal = IsClipboardFormatAvailable (cfOwnerLink);
  1349. if (!retVal)
  1350. return OLE_ERROR_FORMAT;
  1351. if (optRender == olerender_none)
  1352. return OLE_OK;
  1353. }
  1354. else if (bStatic = !lstrcmpi (lpprotocol, PROTOCOL_STATIC)) {
  1355. if (cType == CT_LINK)
  1356. return OLE_ERROR_PROTOCOL;
  1357. if (optRender == olerender_none)
  1358. return OLE_ERROR_FORMAT;
  1359. }
  1360. else {
  1361. return OLE_ERROR_PROTOCOL;
  1362. }
  1363. if (optRender == olerender_draw) {
  1364. if (!IsClipboardFormatAvailable (CF_METAFILEPICT) &&
  1365. !IsClipboardFormatAvailable (CF_DIB) &&
  1366. !IsClipboardFormatAvailable (CF_BITMAP) &&
  1367. !IsClipboardFormatAvailable (CF_ENHMETAFILE) &&
  1368. !(bEdit && QueryHandler((cType == CT_LINK) ? cfObjectLink : cfOwnerLink)))
  1369. return OLE_ERROR_FORMAT;
  1370. }
  1371. else if (optRender == olerender_format) {
  1372. if (!IsClipboardFormatAvailable (cfFormat))
  1373. return OLE_ERROR_FORMAT;
  1374. if (bStatic &&
  1375. (cfFormat != CF_METAFILEPICT) &&
  1376. (cfFormat != CF_ENHMETAFILE) &&
  1377. (cfFormat != CF_DIB) &&
  1378. (cfFormat != CF_BITMAP))
  1379. return OLE_ERROR_FORMAT;
  1380. }
  1381. else {
  1382. return OLE_ERROR_FORMAT;
  1383. }
  1384. return OLE_OK;
  1385. }
  1386. BOOL INTERNAL CheckObject(
  1387. LPOLEOBJECT lpobj
  1388. ){
  1389. if (!CheckPointer(lpobj, WRITE_ACCESS))
  1390. return FALSE;
  1391. if (lpobj->objId[0] == 'L' && lpobj->objId[1] == 'E')
  1392. return TRUE;
  1393. return FALSE;
  1394. }
  1395. BOOL FARINTERNAL FarCheckObject(
  1396. LPOLEOBJECT lpobj
  1397. ){
  1398. return (CheckObject (lpobj));
  1399. }