Fixed callback parameters (bogus hWave); added acm conversion for
[wine.git] / dlls / ole32 / ole2impl.c
blob1cd283ad0fb656be279fe576226a312a0bed60e2
1 /*
2 * Ole 2 Create functions implementation
4 * Copyright (C) 1999-2000 Abey George
5 */
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"
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)
32 IEnumFORMATETC *pfmt;
33 FORMATETC fmt;
34 CHAR szFmtName[MAX_CLIPFORMAT_NAME];
35 BOOL bFoundStatic = FALSE;
37 HRESULT hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
39 if (hr == S_OK)
40 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
42 while (hr == S_OK)
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))
49 return S_OK;
51 /* Check for Metafile, Bitmap or DIB */
53 if (fmt.cfFormat == CF_METAFILEPICT || fmt.cfFormat == CF_BITMAP || fmt.cfFormat == CF_DIB)
54 bFoundStatic = TRUE;
56 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
59 /* Found a static format, but no embed format */
61 if (bFoundStatic)
62 return OLE_S_STATIC;
64 return S_FALSE;
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,
81 LPVOID* ppvObj)
83 IEnumFORMATETC *pfmt;
84 FORMATETC fmt;
85 CHAR szFmtName[MAX_CLIPFORMAT_NAME];
86 STGMEDIUM std;
87 HRESULT hr;
88 HRESULT hr1;
90 hr = IDataObject_EnumFormatEtc(pSrcDataObject, DATADIR_GET, &pfmt);
92 if (hr == S_OK)
94 memset(&std, 0, sizeof(STGMEDIUM));
96 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
97 while (hr == S_OK)
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;
114 CLSID clsID;
116 /* Create ILock bytes */
118 hr1 = CreateILockBytesOnHGlobal(std.u.hGlobal, FALSE, &ptrILockBytes);
120 /* Open storage on the ILock bytes */
122 if (hr1 == S_OK)
123 hr1 = StgOpenStorageOnILockBytes(ptrILockBytes, NULL, STGM_SHARE_EXCLUSIVE, NULL, 0, &pStorage);
125 /* Get Class ID from the opened storage */
127 if (hr1 == S_OK)
128 hr1 = ReadClassStg(pStorage, &clsID);
130 /* Create default handler for Persist storage */
132 if (hr1 == S_OK)
133 hr1 = OleCreateDefaultHandler(&clsID, NULL, &IID_IPersistStorage, (LPVOID*)&pPersistStorage);
135 /* Load the storage to Persist storage */
137 if (hr1 == S_OK)
138 hr1 = IPersistStorage_Load(pPersistStorage, pStorage);
140 /* Query for IOleObject */
142 if (hr1 == S_OK)
143 hr1 = IPersistStorage_QueryInterface(pPersistStorage, &IID_IOleObject, (LPVOID*)&pOleObject);
145 /* Set client site with the IOleObject */
147 if (hr1 == S_OK)
148 hr1 = IOleObject_SetClientSite(pOleObject, pClientSite);
150 IPersistStorage_Release(pPersistStorage);
151 /* Query for the requested interface */
153 if (hr1 == S_OK)
154 hr1 = IPersistStorage_QueryInterface(pPersistStorage, riid, ppvObj);
156 IPersistStorage_Release(pPersistStorage);
158 IStorage_Release(pStorage);
160 if (hr1 == S_OK)
161 return S_OK;
164 /* Return error */
166 return DV_E_FORMATETC;
169 hr = IEnumFORMATETC_Next(pfmt, 1, &fmt, NULL);
173 return DV_E_FORMATETC;