2 * Ole 2 Create functions implementation
4 * Copyright (C) 1999-2000 Abey George
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
28 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(ole);
35 #define MAX_CLIPFORMAT_NAME 80
37 /******************************************************************************
38 * OleQueryCreateFromData [OLE32.117]
40 * Author : Abey George
41 * Checks whether an object can become an embedded object.
42 * the clipboard or OLE drag and drop.
43 * Returns : S_OK - Format that supports Embedded object creation are present.
44 * OLE_E_STATIC - Format that supports static object creation are present.
45 * S_FALSE - No acceptable format is available.
48 HRESULT WINAPI OleQueryCreateFromData(LPDATAOBJECT pSrcDataObject)
52 CHAR szFmtName[MAX_CLIPFORMAT_NAME];
53 BOOL bFoundStatic = FALSE;
55 HRESULT hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
58 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
62 GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
64 /* first, Check for Embedded Object, Embed Source or Filename */
66 if (!strcmp(szFmtName, CF_EMBEDDEDOBJECT) || !strcmp(szFmtName, CF_EMBEDSOURCE) || !strcmp(szFmtName, CF_FILENAME))
69 /* Check for Metafile, Bitmap or DIB */
71 if (fmt.cfFormat == CF_METAFILEPICT || fmt.cfFormat == CF_BITMAP || fmt.cfFormat == CF_DIB)
74 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
77 /* Found a static format, but no embed format */
85 /******************************************************************************
86 * OleCreateFromData [OLE32.92]
88 * Author : Abey George
89 * Creates an embedded object from data transfer object retrieved from
90 * the clipboard or OLE drag and drop.
91 * Returns : S_OK - Embedded object was created successfully.
92 * OLE_E_STATIC - OLE can create only a static object
93 * DV_E_FORMATETC - No acceptable format is available (only error return code)
94 * TODO : CF_FILENAME, CF_EMBEDEDOBJECT formats. Parameter renderopt is currently ignored.
97 HRESULT WINAPI OleCreateFromData(LPDATAOBJECT pSrcDataObject, REFIID riid,
98 DWORD renderopt, LPFORMATETC pFormatEtc,
99 LPOLECLIENTSITE pClientSite, LPSTORAGE pStg,
102 IEnumFORMATETC *pfmt;
104 CHAR szFmtName[MAX_CLIPFORMAT_NAME];
109 hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
113 memset(&std, 0, sizeof(STGMEDIUM));
115 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
118 GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
120 /* first, Check for Embedded Object, Embed Source or Filename */
121 /* TODO: Currently checks only for Embed Source. */
123 if (!strcmp(szFmtName, CF_EMBEDSOURCE))
125 std.tymed = TYMED_HGLOBAL;
127 if ((hr1 = IDataObject_GetData(pSrcDataObject, &fmt, &std)) == S_OK)
129 ILockBytes *ptrILockBytes = 0;
130 IStorage *pStorage = 0;
131 IOleObject *pOleObject = 0;
132 IPersistStorage *pPersistStorage = 0;
135 /* Create ILock bytes */
137 hr1 = CreateILockBytesOnHGlobal(std.u.hGlobal, FALSE, &ptrILockBytes);
139 /* Open storage on the ILock bytes */
142 hr1 = StgOpenStorageOnILockBytes(ptrILockBytes, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
144 /* Get Class ID from the opened storage */
147 hr1 = ReadClassStg(pStorage, &clsID);
149 /* Create default handler for Persist storage */
152 hr1 = OleCreateDefaultHandler(&clsID, NULL, &IID_IPersistStorage, (LPVOID*)&pPersistStorage);
154 /* Load the storage to Persist storage */
157 hr1 = IPersistStorage_Load(pPersistStorage, pStorage);
159 /* Query for IOleObject */
162 hr1 = IPersistStorage_QueryInterface(pPersistStorage, &IID_IOleObject, (LPVOID*)&pOleObject);
164 /* Set client site with the IOleObject */
167 hr1 = IOleObject_SetClientSite(pOleObject, pClientSite);
169 IPersistStorage_Release(pPersistStorage);
170 /* Query for the requested interface */
173 hr1 = IPersistStorage_QueryInterface(pPersistStorage, riid, ppvObj);
175 IPersistStorage_Release(pPersistStorage);
177 IStorage_Release(pStorage);
185 return DV_E_FORMATETC;
188 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
192 return DV_E_FORMATETC;