1 | /* $Id: ole2impl.c,v 1.2 2001-09-05 13:17:11 bird Exp $ */
|
---|
2 | /*
|
---|
3 | * Ole 2 Create functions implementation
|
---|
4 | *
|
---|
5 | * Copyright (C) 1999-2000 Abey George
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include <string.h>
|
---|
9 | #include "winbase.h"
|
---|
10 | #include "wingdi.h"
|
---|
11 | #include "winuser.h"
|
---|
12 | #include "debugtools.h"
|
---|
13 | #include "ole2.h"
|
---|
14 | #include "olestd.h"
|
---|
15 | #include "winreg.h"
|
---|
16 |
|
---|
17 | DEFAULT_DEBUG_CHANNEL(ole);
|
---|
18 |
|
---|
19 | #define MAX_CLIPFORMAT_NAME 80
|
---|
20 |
|
---|
21 | /******************************************************************************
|
---|
22 | * Function : 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.
|
---|
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 | * Function : OleCreateFromData [OLE32.92]
|
---|
70 | * Author : Abey George
|
---|
71 | * Creates an embedded object from data transfer object retrieved from
|
---|
72 | * the clipboard or OLE drag and drop.
|
---|
73 | * Returns : S_OK - Embedded object was created successfully.
|
---|
74 | * OLE_E_STATIC - OLE can create only a static object
|
---|
75 | * DV_E_FORMATETC - No acceptable format is available (only error return code)
|
---|
76 | * TODO : CF_FILENAME, CF_EMBEDEDOBJECT formats. Parameter renderopt is currently ignored.
|
---|
77 | */
|
---|
78 |
|
---|
79 | HRESULT WINAPI OleCreateFromData(LPDATAOBJECT pSrcDataObject, REFIID riid,
|
---|
80 | DWORD renderopt, LPFORMATETC pFormatEtc,
|
---|
81 | LPOLECLIENTSITE pClientSite, LPSTORAGE pStg,
|
---|
82 | LPVOID* ppvObj)
|
---|
83 | {
|
---|
84 | IEnumFORMATETC *pfmt;
|
---|
85 | FORMATETC fmt;
|
---|
86 | CHAR szFmtName[MAX_CLIPFORMAT_NAME];
|
---|
87 | STGMEDIUM std;
|
---|
88 | HRESULT hr;
|
---|
89 | HRESULT hr1;
|
---|
90 |
|
---|
91 | hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
|
---|
92 |
|
---|
93 | if (hr == S_OK)
|
---|
94 | {
|
---|
95 | memset(&std, 0, sizeof(STGMEDIUM));
|
---|
96 |
|
---|
97 | hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
|
---|
98 | while (hr == S_OK)
|
---|
99 | {
|
---|
100 | GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
|
---|
101 |
|
---|
102 | /* first, Check for Embedded Object, Embed Source or Filename */
|
---|
103 | /* TODO: Currently checks only for Embed Source. */
|
---|
104 |
|
---|
105 | if (!strcmp(szFmtName, CF_EMBEDSOURCE))
|
---|
106 | {
|
---|
107 | std.tymed = TYMED_HGLOBAL;
|
---|
108 |
|
---|
109 | if ((hr1 = IDataObject_GetData(pSrcDataObject, &fmt, &std)) == S_OK)
|
---|
110 | {
|
---|
111 | ILockBytes *ptrILockBytes = 0;
|
---|
112 | IStorage *pStorage = 0;
|
---|
113 | IOleObject *pOleObject = 0;
|
---|
114 | IPersistStorage *pPersistStorage = 0;
|
---|
115 | CLSID clsID;
|
---|
116 |
|
---|
117 | /* Create ILock bytes */
|
---|
118 |
|
---|
119 | hr1 = CreateILockBytesOnHGlobal(std.u.hGlobal, FALSE, &ptrILockBytes);
|
---|
120 |
|
---|
121 | /* Open storage on the ILock bytes */
|
---|
122 |
|
---|
123 | if (hr1 == S_OK)
|
---|
124 | hr1 = StgOpenStorageOnILockBytes(ptrILockBytes, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
|
---|
125 |
|
---|
126 | /* Get Class ID from the opened storage */
|
---|
127 |
|
---|
128 | if (hr1 == S_OK)
|
---|
129 | hr1 = ReadClassStg(pStorage, &clsID);
|
---|
130 |
|
---|
131 | /* Create default handler for Persist storage */
|
---|
132 |
|
---|
133 | if (hr1 == S_OK)
|
---|
134 | hr1 = OleCreateDefaultHandler(&clsID, NULL, &IID_IPersistStorage, (LPVOID*)&pPersistStorage);
|
---|
135 |
|
---|
136 | /* Load the storage to Persist storage */
|
---|
137 |
|
---|
138 | if (hr1 == S_OK)
|
---|
139 | hr1 = IPersistStorage_Load(pPersistStorage, pStorage);
|
---|
140 |
|
---|
141 | /* Query for IOleObject */
|
---|
142 |
|
---|
143 | if (hr1 == S_OK)
|
---|
144 | hr1 = IPersistStorage_QueryInterface(pPersistStorage, &IID_IOleObject, (LPVOID*)&pOleObject);
|
---|
145 |
|
---|
146 | /* Set client site with the IOleObject */
|
---|
147 |
|
---|
148 | if (hr1 == S_OK)
|
---|
149 | hr1 = IOleObject_SetClientSite(pOleObject, pClientSite);
|
---|
150 |
|
---|
151 | IPersistStorage_Release(pPersistStorage);
|
---|
152 | /* Query for the requested interface */
|
---|
153 |
|
---|
154 | if (hr1 == S_OK)
|
---|
155 | hr1 = IPersistStorage_QueryInterface(pPersistStorage, riid, ppvObj);
|
---|
156 |
|
---|
157 | IPersistStorage_Release(pPersistStorage);
|
---|
158 |
|
---|
159 | IStorage_Release(pStorage);
|
---|
160 |
|
---|
161 | if (hr1 == S_OK)
|
---|
162 | return S_OK;
|
---|
163 | }
|
---|
164 |
|
---|
165 | /* Return error */
|
---|
166 |
|
---|
167 | return DV_E_FORMATETC;
|
---|
168 | }
|
---|
169 |
|
---|
170 | hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | return DV_E_FORMATETC;
|
---|
175 | }
|
---|
176 |
|
---|