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 * Function : OleQueryCreateFromData [OLE32.117]
22 * Author : Abey George
23 * Checks whether an object can become an embedded object.
24 * the clipboard or OLE drag and drop.
25 * Returns : S_OK - Format that supports Embedded object creation are present.
26 * OLE_E_STATIC - Format that supports static object creation are present.
27 * S_FALSE - No acceptable format is available.
30 HRESULT WINAPI
OleQueryCreateFromData(LPDATAOBJECT pSrcDataObject
)
34 CHAR szFmtName
[MAX_CLIPFORMAT_NAME
];
35 BOOL bFoundStatic
= FALSE
;
37 HRESULT hr
= IDataObject_EnumFormatEtc(pSrcDataObject
, DATADIR_GET
, &pfmt
);
40 hr
= IEnumFORMATETC_Next(pfmt
, 1, &fmt
, NULL
);
44 GetClipboardFormatNameA(fmt
.cfFormat
, szFmtName
, MAX_CLIPFORMAT_NAME
-1);
46 /* first, Check for Embedded Object, Embed Source or Filename */
48 if (!strcmp(szFmtName
, CF_EMBEDDEDOBJECT
) || !strcmp(szFmtName
, CF_EMBEDSOURCE
) || !strcmp(szFmtName
, CF_FILENAME
))
51 /* Check for Metafile, Bitmap or DIB */
53 if (fmt
.cfFormat
== CF_METAFILEPICT
|| fmt
.cfFormat
== CF_BITMAP
|| fmt
.cfFormat
== CF_DIB
)
56 hr
= IEnumFORMATETC_Next(pfmt
, 1, &fmt
, NULL
);
59 /* Found a static format, but no embed format */
67 /******************************************************************************
68 * Function : OleCreateFromData [OLE32.92]
69 * Author : Abey George
70 * Creates an embedded object from data transfer object retrieved from
71 * the clipboard or OLE drag and drop.
72 * Returns : S_OK - Embedded object was created successfully.
73 * OLE_E_STATIC - OLE can create only a static object
74 * DV_E_FORMATETC - No acceptable format is available (only error return code)
75 * TODO : CF_FILENAME, CF_EMBEDEDOBJECT formats. Parameter renderopt is currently ignored.
78 HRESULT WINAPI
OleCreateFromData(LPDATAOBJECT pSrcDataObject
, REFIID riid
,
79 DWORD renderopt
, LPFORMATETC pFormatEtc
,
80 LPOLECLIENTSITE pClientSite
, LPSTORAGE pStg
,
85 CHAR szFmtName
[MAX_CLIPFORMAT_NAME
];
90 hr
= IDataObject_EnumFormatEtc(pSrcDataObject
, DATADIR_GET
, &pfmt
);
94 memset(&std
, 0, sizeof(STGMEDIUM
));
96 hr
= IEnumFORMATETC_Next(pfmt
, 1, &fmt
, NULL
);
99 GetClipboardFormatNameA(fmt
.cfFormat
, szFmtName
, MAX_CLIPFORMAT_NAME
-1);
101 /* first, Check for Embedded Object, Embed Source or Filename */
102 /* TODO: Currently checks only for Embed Source. */
104 if (!strcmp(szFmtName
, CF_EMBEDSOURCE
))
106 std
.tymed
= TYMED_HGLOBAL
;
108 if ((hr1
= IDataObject_GetData(pSrcDataObject
, &fmt
, &std
)) == S_OK
)
110 ILockBytes
*ptrILockBytes
= 0;
111 IStorage
*pStorage
= 0;
112 IOleObject
*pOleObject
= 0;
113 IPersistStorage
*pPersistStorage
= 0;
116 /* Create ILock bytes */
118 hr1
= CreateILockBytesOnHGlobal(std
.u
.hGlobal
, FALSE
, &ptrILockBytes
);
120 /* Open storage on the ILock bytes */
123 hr1
= StgOpenStorageOnILockBytes(ptrILockBytes
, NULL
, STGM_SHARE_EXCLUSIVE
, NULL
, 0, &pStorage
);
125 /* Get Class ID from the opened storage */
128 hr1
= ReadClassStg(pStorage
, &clsID
);
130 /* Create default handler for Persist storage */
133 hr1
= OleCreateDefaultHandler(&clsID
, NULL
, &IID_IPersistStorage
, (LPVOID
*)&pPersistStorage
);
135 /* Load the storage to Persist storage */
138 hr1
= IPersistStorage_Load(pPersistStorage
, pStorage
);
140 /* Query for IOleObject */
143 hr1
= IPersistStorage_QueryInterface(pPersistStorage
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
145 /* Set client site with the IOleObject */
148 hr1
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
150 IPersistStorage_Release(pPersistStorage
);
151 /* Query for the requested interface */
154 hr1
= IPersistStorage_QueryInterface(pPersistStorage
, riid
, ppvObj
);
156 IPersistStorage_Release(pPersistStorage
);
158 IStorage_Release(pStorage
);
166 return DV_E_FORMATETC
;
169 hr
= IEnumFORMATETC_Next(pfmt
, 1, &fmt
, NULL
);
173 return DV_E_FORMATETC
;