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.

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