1 | /*
|
---|
2 | * Ole 2 Create functions implementation
|
---|
3 | *
|
---|
4 | * Copyright (C) 1999-2000 Abey George
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include <string.h>
|
---|
8 | #include "winbase.h"
|
---|
9 | #include "wingdi.h"
|
---|
10 | #include "winuser.h"
|
---|
11 | #include "debugtools.h"
|
---|
12 | #include "ole2.h"
|
---|
13 | #include "olestd.h"
|
---|
14 | #include "winreg.h"
|
---|
15 |
|
---|
16 | DEFAULT_DEBUG_CHANNEL(ole);
|
---|
17 |
|
---|
18 | #define MAX_CLIPFORMAT_NAME 80
|
---|
19 |
|
---|
20 | /******************************************************************************
|
---|
21 | * OleQueryCreateFromData [OLE32.117]
|
---|
22 | *
|
---|
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.
|
---|
29 | */
|
---|
30 |
|
---|
31 | HRESULT WINAPI OleQueryCreateFromData(LPDATAOBJECT pSrcDataObject)
|
---|
32 | {
|
---|
33 | IEnumFORMATETC *pfmt;
|
---|
34 | FORMATETC fmt;
|
---|
35 | CHAR szFmtName[MAX_CLIPFORMAT_NAME];
|
---|
36 | BOOL bFoundStatic = FALSE;
|
---|
37 |
|
---|
38 | HRESULT hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
|
---|
39 |
|
---|
40 | if (hr == S_OK)
|
---|
41 | hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
|
---|
42 |
|
---|
43 | while (hr == S_OK)
|
---|
44 | {
|
---|
45 | GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
|
---|
46 |
|
---|
47 | /* first, Check for Embedded Object, Embed Source or Filename */
|
---|
48 |
|
---|
49 | if (!strcmp(szFmtName, CF_EMBEDDEDOBJECT) || !strcmp(szFmtName, CF_EMBEDSOURCE) || !strcmp(szFmtName, CF_FILENAME))
|
---|
50 | return S_OK;
|
---|
51 |
|
---|
52 | /* Check for Metafile, Bitmap or DIB */
|
---|
53 |
|
---|
54 | if (fmt.cfFormat == CF_METAFILEPICT || fmt.cfFormat == CF_BITMAP || fmt.cfFormat == CF_DIB)
|
---|
55 | bFoundStatic = TRUE;
|
---|
56 |
|
---|
57 | hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
|
---|
58 | }
|
---|
59 |
|
---|
60 | /* Found a static format, but no embed format */
|
---|
61 |
|
---|
62 | if (bFoundStatic)
|
---|
63 | return OLE_S_STATIC;
|
---|
64 |
|
---|
65 | return S_FALSE;
|
---|
66 | }
|
---|
67 |
|
---|
68 | /******************************************************************************
|
---|
69 | * OleCreateFromData [OLE32.92]
|
---|
70 | *
|
---|
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.
|
---|
78 | */
|
---|
79 |
|
---|
80 | HRESULT WINAPI OleCreateFromData(LPDATAOBJECT pSrcDataObject, REFIID riid,
|
---|
81 | DWORD renderopt, LPFORMATETC pFormatEtc,
|
---|
82 | LPOLECLIENTSITE pClientSite, LPSTORAGE pStg,
|
---|
83 | LPVOID* ppvObj)
|
---|
84 | {
|
---|
85 | IEnumFORMATETC *pfmt;
|
---|
86 | FORMATETC fmt;
|
---|
87 | CHAR szFmtName[MAX_CLIPFORMAT_NAME];
|
---|
88 | STGMEDIUM std;
|
---|
89 | HRESULT hr;
|
---|
90 | HRESULT hr1;
|
---|
91 |
|
---|
92 | hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
|
---|
93 |
|
---|
94 | if (hr == S_OK)
|
---|
95 | {
|
---|
96 | memset(&std, 0, sizeof(STGMEDIUM));
|
---|
97 |
|
---|
98 | hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
|
---|
99 | while (hr == S_OK)
|
---|
100 | {
|
---|
101 | GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
|
---|
102 |
|
---|
103 | /* first, Check for Embedded Object, Embed Source or Filename */
|
---|
104 | /* TODO: Currently checks only for Embed Source. */
|
---|
105 |
|
---|
106 | if (!strcmp(szFmtName, CF_EMBEDSOURCE))
|
---|
107 | {
|
---|
108 | std.tymed = TYMED_HGLOBAL;
|
---|
109 |
|
---|
110 | if ((hr1 = IDataObject_GetData(pSrcDataObject, &fmt, &std)) == S_OK)
|
---|
111 | {
|
---|
112 | ILockBytes *ptrILockBytes = 0;
|
---|
113 | IStorage *pStorage = 0;
|
---|
114 | IOleObject *pOleObject = 0;
|
---|
115 | IPersistStorage *pPersistStorage = 0;
|
---|
116 | CLSID clsID;
|
---|
117 |
|
---|
118 | /* Create ILock bytes */
|
---|
119 |
|
---|
120 | hr1 = CreateILockBytesOnHGlobal(std.u.hGlobal, FALSE, &ptrILockBytes);
|
---|
121 |
|
---|
122 | /* Open storage on the ILock bytes */
|
---|
123 |
|
---|
124 | if (hr1 == S_OK)
|
---|
125 | hr1 = StgOpenStorageOnILockBytes(ptrILockBytes, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
|
---|
126 |
|
---|
127 | /* Get Class ID from the opened storage */
|
---|
128 |
|
---|
129 | if (hr1 == S_OK)
|
---|
130 | hr1 = ReadClassStg(pStorage, &clsID);
|
---|
131 |
|
---|
132 | /* Create default handler for Persist storage */
|
---|
133 |
|
---|
134 | if (hr1 == S_OK)
|
---|
135 | hr1 = OleCreateDefaultHandler(&clsID, NULL, &IID_IPersistStorage, (LPVOID*)&pPersistStorage);
|
---|
136 |
|
---|
137 | /* Load the storage to Persist storage */
|
---|
138 |
|
---|
139 | if (hr1 == S_OK)
|
---|
140 | hr1 = IPersistStorage_Load(pPersistStorage, pStorage);
|
---|
141 |
|
---|
142 | /* Query for IOleObject */
|
---|
143 |
|
---|
144 | if (hr1 == S_OK)
|
---|
145 | hr1 = IPersistStorage_QueryInterface(pPersistStorage, &IID_IOleObject, (LPVOID*)&pOleObject);
|
---|
146 |
|
---|
147 | /* Set client site with the IOleObject */
|
---|
148 |
|
---|
149 | if (hr1 == S_OK)
|
---|
150 | hr1 = IOleObject_SetClientSite(pOleObject, pClientSite);
|
---|
151 |
|
---|
152 | IPersistStorage_Release(pPersistStorage);
|
---|
153 | /* Query for the requested interface */
|
---|
154 |
|
---|
155 | if (hr1 == S_OK)
|
---|
156 | hr1 = IPersistStorage_QueryInterface(pPersistStorage, riid, ppvObj);
|
---|
157 |
|
---|
158 | IPersistStorage_Release(pPersistStorage);
|
---|
159 |
|
---|
160 | IStorage_Release(pStorage);
|
---|
161 |
|
---|
162 | if (hr1 == S_OK)
|
---|
163 | return S_OK;
|
---|
164 | }
|
---|
165 |
|
---|
166 | /* Return error */
|
---|
167 |
|
---|
168 | return DV_E_FORMATETC;
|
---|
169 | }
|
---|
170 |
|
---|
171 | hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
|
---|
172 | }
|
---|
173 | }
|
---|
174 |
|
---|
175 | return DV_E_FORMATETC;
|
---|
176 | }
|
---|
177 |
|
---|