2 * Ole 2 Create functions implementation
4 * Copyright (C) 1999-2000 Abey George
11 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(ole);
18 #define MAX_CLIPFORMAT_NAME 80
20 /******************************************************************************
21 * OleQueryCreateFromData [OLE32.117]
23 * Author : Abey George
24 * Checks whether an object can become an embedded object.
25 * the clipboard or OLE drag and drop.
26 * Returns : S_OK - Format that supports Embedded object creation are present.
27 * OLE_E_STATIC - Format that supports static object creation are present.
28 * S_FALSE - No acceptable format is available.
31 HRESULT WINAPI OleQueryCreateFromData(LPDATAOBJECT pSrcDataObject)
35 CHAR szFmtName[MAX_CLIPFORMAT_NAME];
36 BOOL bFoundStatic = FALSE;
38 HRESULT hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
41 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
45 GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
47 /* first, Check for Embedded Object, Embed Source or Filename */
49 if (!strcmp(szFmtName, CF_EMBEDDEDOBJECT) || !strcmp(szFmtName, CF_EMBEDSOURCE) || !strcmp(szFmtName, CF_FILENAME))
52 /* Check for Metafile, Bitmap or DIB */
54 if (fmt.cfFormat == CF_METAFILEPICT || fmt.cfFormat == CF_BITMAP || fmt.cfFormat == CF_DIB)
57 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
60 /* Found a static format, but no embed format */
68 /******************************************************************************
69 * OleCreateFromData [OLE32.92]
71 * Author : Abey George
72 * Creates an embedded object from data transfer object retrieved from
73 * the clipboard or OLE drag and drop.
74 * Returns : S_OK - Embedded object was created successfully.
75 * OLE_E_STATIC - OLE can create only a static object
76 * DV_E_FORMATETC - No acceptable format is available (only error return code)
77 * TODO : CF_FILENAME, CF_EMBEDEDOBJECT formats. Parameter renderopt is currently ignored.
80 HRESULT WINAPI OleCreateFromData(LPDATAOBJECT pSrcDataObject, REFIID riid,
81 DWORD renderopt, LPFORMATETC pFormatEtc,
82 LPOLECLIENTSITE pClientSite, LPSTORAGE pStg,
87 CHAR szFmtName[MAX_CLIPFORMAT_NAME];
92 hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
96 memset(&std, 0, sizeof(STGMEDIUM));
98 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
101 GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
103 /* first, Check for Embedded Object, Embed Source or Filename */
104 /* TODO: Currently checks only for Embed Source. */
106 if (!strcmp(szFmtName, CF_EMBEDSOURCE))
108 std.tymed = TYMED_HGLOBAL;
110 if ((hr1 = IDataObject_GetData(pSrcDataObject, &fmt, &std)) == S_OK)
112 ILockBytes *ptrILockBytes = 0;
113 IStorage *pStorage = 0;
114 IOleObject *pOleObject = 0;
115 IPersistStorage *pPersistStorage = 0;
118 /* Create ILock bytes */
120 hr1 = CreateILockBytesOnHGlobal(std.u.hGlobal, FALSE, &ptrILockBytes);
122 /* Open storage on the ILock bytes */
125 hr1 = StgOpenStorageOnILockBytes(ptrILockBytes, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
127 /* Get Class ID from the opened storage */
130 hr1 = ReadClassStg(pStorage, &clsID);
132 /* Create default handler for Persist storage */
135 hr1 = OleCreateDefaultHandler(&clsID, NULL, &IID_IPersistStorage, (LPVOID*)&pPersistStorage);
137 /* Load the storage to Persist storage */
140 hr1 = IPersistStorage_Load(pPersistStorage, pStorage);
142 /* Query for IOleObject */
145 hr1 = IPersistStorage_QueryInterface(pPersistStorage, &IID_IOleObject, (LPVOID*)&pOleObject);
147 /* Set client site with the IOleObject */
150 hr1 = IOleObject_SetClientSite(pOleObject, pClientSite);
152 IPersistStorage_Release(pPersistStorage);
153 /* Query for the requested interface */
156 hr1 = IPersistStorage_QueryInterface(pPersistStorage, riid, ppvObj);
158 IPersistStorage_Release(pPersistStorage);
160 IStorage_Release(pStorage);
168 return DV_E_FORMATETC;
171 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
175 return DV_E_FORMATETC;