source: trunk/src/ole32/old/ole2impl.cpp@ 6496

Last change on this file since 6496 was 5601, checked in by sandervl, 24 years ago

created

File size: 4.9 KB
Line 
1/* $Id: ole2impl.cpp,v 1.1 2001-04-26 19:26:12 sandervl Exp $ */
2/*
3 * Ole 2 Create functions implementation
4 *
5 * Copyright (C) 1999-2000 Abey George
6 */
7/*
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12/*
13 * Ported from Wine 20/03/00
14 *
15 * Copyright 1999 David J. Raison
16 *
17 */
18
19#include "ole32.h"
20#include <winerror.h>
21#include <olestd.h>
22#include "oString.h"
23#include <assert.h>
24
25#define MAX_CLIPFORMAT_NAME 80
26
27/**
28 * [OLE32.117]
29 * Checks whether an object can become an embedded object.
30 * the clipboard or OLE drag and drop.
31 * @author Abey George
32 * @returns S_OK - Format that supports Embedded object creation are present.
33 * OLE_E_STATIC - Format that supports static object creation are present.
34 * S_FALSE - No acceptable format is available.
35 */
36
37HRESULT WINAPI OleQueryCreateFromData(LPDATAOBJECT pSrcDataObject)
38{
39 IEnumFORMATETC *pfmt;
40 FORMATETC fmt;
41 CHAR szFmtName[MAX_CLIPFORMAT_NAME];
42 BOOL bFoundStatic = FALSE;
43
44 HRESULT hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
45
46 if (hr == S_OK)
47 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
48
49 while (hr == S_OK)
50 {
51 GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
52
53 /* first, Check for Embedded Object, Embed Source or Filename */
54
55 if (!strcmp(szFmtName, CF_EMBEDDEDOBJECT) || !strcmp(szFmtName, CF_EMBEDSOURCE) || !strcmp(szFmtName, CF_FILENAME))
56 return S_OK;
57
58 /* Check for Metafile, Bitmap or DIB */
59
60 if (fmt.cfFormat == CF_METAFILEPICT || fmt.cfFormat == CF_BITMAP || fmt.cfFormat == CF_DIB)
61 bFoundStatic = TRUE;
62
63 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
64 }
65
66 /* Found a static format, but no embed format */
67
68 if (bFoundStatic)
69 return OLE_S_STATIC;
70
71 return S_FALSE;
72}
73
74/**
75 * Creates an embedded object from data transfer object retrieved from
76 * the clipboard or OLE drag and drop.
77 * [OLE32.92]
78 * @author Abey George
79 * @returns S_OK - Embedded object was created successfully.
80 * OLE_E_STATIC - OLE can create only a static object
81 * DV_E_FORMATETC - No acceptable format is available (only error return code)
82 * @remark TODO : CF_FILENAME, CF_EMBEDEDOBJECT formats. Parameter renderopt is currently ignored.
83 */
84
85HRESULT WINAPI OleCreateFromData(LPDATAOBJECT pSrcDataObject, REFIID riid,
86 DWORD renderopt, LPFORMATETC pFormatEtc,
87 LPOLECLIENTSITE pClientSite, LPSTORAGE pStg,
88 LPVOID* ppvObj)
89{
90 IEnumFORMATETC *pfmt;
91 FORMATETC fmt;
92 CHAR szFmtName[MAX_CLIPFORMAT_NAME];
93 STGMEDIUM std;
94 HRESULT hr;
95 HRESULT hr1;
96
97 hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
98
99 if (hr == S_OK)
100 {
101 memset(&std, 0, sizeof(STGMEDIUM));
102
103 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
104 while (hr == S_OK)
105 {
106 GetClipboardFormatNameA(fmt.cfFormat, szFmtName, MAX_CLIPFORMAT_NAME-1);
107
108 /* first, Check for Embedded Object, Embed Source or Filename */
109 /* TODO: Currently checks only for Embed Source. */
110
111 if (!strcmp(szFmtName, CF_EMBEDSOURCE))
112 {
113 std.tymed = TYMED_HGLOBAL;
114
115 if ((hr1 = IDataObject_GetData(pSrcDataObject, &fmt, &std)) == S_OK)
116 {
117 ILockBytes *ptrILockBytes = 0;
118 IStorage *pStorage = 0;
119 IOleObject *pOleObject = 0;
120 IPersistStorage *pPersistStorage = 0;
121 CLSID clsID;
122
123 /* Create ILock bytes */
124
125 hr1 = CreateILockBytesOnHGlobal(std.u.hGlobal, FALSE, &ptrILockBytes);
126
127 /* Open storage on the ILock bytes */
128
129 if (hr1 == S_OK)
130 hr1 = StgOpenStorageOnILockBytes(ptrILockBytes, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
131
132 /* Get Class ID from the opened storage */
133
134 if (hr1 == S_OK)
135 hr1 = ReadClassStg(pStorage, &clsID);
136
137 /* Create default handler for Persist storage */
138
139 if (hr1 == S_OK)
140 hr1 = OleCreateDefaultHandler(&clsID, NULL, &IID_IPersistStorage, (LPVOID *)&pPersistStorage);
141
142 /* Load the storage to Persist storage */
143
144 if (hr1 == S_OK)
145 hr1 = IPersistStorage_Load(pPersistStorage, pStorage);
146
147 /* Query for IOleObject */
148
149 if (hr1 == S_OK)
150 hr1 = IPersistStorage_QueryInterface(pPersistStorage, &IID_IOleObject, (LPVOID *)&pOleObject);
151
152 /* Set client site with the IOleObject */
153
154 if (hr1 == S_OK)
155 hr1 = IOleObject_SetClientSite(pOleObject, pClientSite);
156
157 IPersistStorage_Release(pPersistStorage);
158 /* Query for the requested interface */
159
160 if (hr1 == S_OK)
161 hr1 = IPersistStorage_QueryInterface(pPersistStorage, riid, ppvObj);
162
163 IPersistStorage_Release(pPersistStorage);
164
165 IStorage_Release(pStorage);
166
167 if (hr1 == S_OK)
168 return S_OK;
169 }
170
171 /* Return error */
172
173 return DV_E_FORMATETC;
174 }
175
176 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
177 }
178 }
179
180 return DV_E_FORMATETC;
181}
182
Note: See TracBrowser for help on using the repository browser.