include: Print contents of VT_LPSTR and VT_LPWSTR variants in wine_dbgstr_variant.
[wine.git] / dlls / ole2.dll16 / ole2.c
blobbd9cf45d6dc64bc312bf13d4f0a377dfb3915c87
2 /*
3 * OLE2 library - 16 bit only interfaces
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Noel Borthwick
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "config.h"
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "wownt32.h"
37 #include "ole2.h"
38 #include "winerror.h"
40 #include "wine/winbase16.h"
41 #include "wine/wingdi16.h"
42 #include "wine/winuser16.h"
43 #include "ifs.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ole);
49 #define E_INVALIDARG16 MAKE_SCODE(SEVERITY_ERROR, FACILITY_NULL, 3)
51 static HICON convert_icon_to_32( HICON16 icon16 )
53 CURSORICONINFO *info = GlobalLock16( icon16 );
54 void *and_bits = info + 1;
55 void *xor_bits = (BYTE *)and_bits + info->nHeight * 2 * ((info->nWidth + 15) / 16);
56 HICON ret = CreateIcon( 0, info->nWidth, info->nHeight, info->bPlanes, info->bBitsPerPixel,
57 and_bits, xor_bits );
58 GlobalUnlock16( icon16 );
59 return ret;
62 /******************************************************************************
63 * OleBuildVersion (OLE2.1)
65 DWORD WINAPI OleBuildVersion16(void)
67 return OleBuildVersion();
70 /***********************************************************************
71 * OleInitialize (OLE2.2)
73 HRESULT WINAPI OleInitialize16(LPVOID reserved)
75 return OleInitialize( reserved );
78 /******************************************************************************
79 * OleUninitialize (OLE2.3)
81 void WINAPI OleUninitialize16(void)
83 OleUninitialize();
86 /***********************************************************************
87 * DllGetClassObject (OLE2.4)
89 HRESULT WINAPI DllGetClassObject16(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
91 FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
92 return E_NOTIMPL;
95 /******************************************************************************
96 * GetRunningObjectTable (OLE2.30)
98 HRESULT WINAPI GetRunningObjectTable16(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot)
100 FIXME("(%d,%p),stub!\n",reserved,pprot);
101 return E_NOTIMPL;
104 /***********************************************************************
105 * RegisterDragDrop (OLE2.35)
107 HRESULT WINAPI RegisterDragDrop16(
108 HWND16 hwnd,
109 LPDROPTARGET pDropTarget
111 FIXME("(0x%04x,%p),stub!\n",hwnd,pDropTarget);
112 return S_OK;
115 /***********************************************************************
116 * RevokeDragDrop (OLE2.36)
118 HRESULT WINAPI RevokeDragDrop16(
119 HWND16 hwnd
121 FIXME("(0x%04x),stub!\n",hwnd);
122 return S_OK;
125 /******************************************************************************
126 * OleMetaFilePictFromIconAndLabel (OLE2.56)
128 * Returns a global memory handle to a metafile which contains the icon and
129 * label given.
130 * I guess the result of that should look somehow like desktop icons.
131 * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
132 * This code might be wrong at some places.
134 HGLOBAL16 WINAPI OleMetafilePictFromIconAndLabel16(
135 HICON16 icon16,
136 LPCOLESTR16 lpszLabel,
137 LPCOLESTR16 lpszSourceFile,
138 UINT16 iIconIndex
140 METAFILEPICT *pict;
141 HGLOBAL hmf;
142 HGLOBAL16 hmf16;
143 LPWSTR label = NULL, source = NULL;
144 DWORD len;
145 HICON icon = convert_icon_to_32( icon16 );
147 if (lpszLabel)
149 len = MultiByteToWideChar( CP_ACP, 0, lpszLabel, -1, NULL, 0 );
150 label = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
151 MultiByteToWideChar( CP_ACP, 0, lpszLabel, -1, label, len );
153 if (lpszSourceFile)
155 len = MultiByteToWideChar( CP_ACP, 0, lpszSourceFile, -1, NULL, 0 );
156 source = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
157 MultiByteToWideChar( CP_ACP, 0, lpszSourceFile, -1, source, len );
159 hmf = OleMetafilePictFromIconAndLabel( icon, label, source, iIconIndex );
160 HeapFree( GetProcessHeap(), 0, label );
161 HeapFree( GetProcessHeap(), 0, source );
162 DestroyIcon( icon );
164 if (!hmf) return 0;
165 pict = GlobalLock( hmf );
167 hmf16 = GlobalAlloc16(0, sizeof(METAFILEPICT16));
168 if (hmf16)
170 METAFILEPICT16 *pict16 = GlobalLock16( hmf16 );
171 pict16->mm = pict->mm;
172 pict16->xExt = pict->xExt;
173 pict16->yExt = pict->yExt;
174 len = GetMetaFileBitsEx( pict->hMF, 0, 0 );
175 pict16->hMF = GlobalAlloc16( GMEM_MOVEABLE, len );
176 GetMetaFileBitsEx( pict->hMF, len, GlobalLock16( pict16->hMF) );
177 GlobalUnlock16( pict16->hMF );
178 GlobalUnlock16( hmf16 );
180 DeleteMetaFile( pict->hMF );
181 GlobalUnlock( hmf );
182 GlobalFree( hmf );
183 return hmf16;
187 /******************************************************************************
188 * CreateItemMoniker (OLE2.27)
190 HRESULT WINAPI CreateItemMoniker16(LPCOLESTR16 lpszDelim,LPCOLESTR16 lpszItem,LPMONIKER* ppmk)
192 FIXME("(%s,%p),stub!\n",lpszDelim,ppmk);
193 *ppmk = NULL;
194 return E_NOTIMPL;
198 /******************************************************************************
199 * CreateFileMoniker (OLE2.28)
201 HRESULT WINAPI CreateFileMoniker16(LPCOLESTR16 lpszPathName,LPMONIKER* ppmk)
203 FIXME("(%s,%p),stub!\n",lpszPathName,ppmk);
204 return E_NOTIMPL;
207 /******************************************************************************
208 * OleSetMenuDescriptor (OLE2.41)
210 * PARAMS
211 * hOleMenu FIXME: Should probably be an HOLEMENU16.
213 HRESULT WINAPI OleSetMenuDescriptor16(
214 HOLEMENU hOleMenu,
215 HWND16 hwndFrame,
216 HWND16 hwndActiveObject,
217 LPOLEINPLACEFRAME lpFrame,
218 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
220 FIXME("(%p, %x, %x, %p, %p), stub!\n", hOleMenu, hwndFrame, hwndActiveObject, lpFrame, lpActiveObject);
221 return E_NOTIMPL;
224 /******************************************************************************
225 * OleLoad [OLE2.12]
227 * PARAMS
228 * pStg Segmented LPSTORAGE pointer.
229 * pClientSite Segmented LPOLECLIENTSITE pointer.
231 HRESULT WINAPI OleLoad16(
232 SEGPTR pStg,
233 REFIID riid,
234 SEGPTR pClientSite,
235 LPVOID* ppvObj)
237 FIXME("(%x,%s,%x,%p), stub!\n", pStg, debugstr_guid(riid), pClientSite, ppvObj);
238 return E_NOTIMPL;
241 /******************************************************************************
242 * OleDoAutoConvert [OLE2.79]
244 HRESULT WINAPI OleDoAutoConvert16(LPSTORAGE pStg, LPCLSID pClsidNew)
246 FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
247 return E_NOTIMPL;
250 /***********************************************************************
251 * OleSetClipboard [OLE2.49]
253 HRESULT WINAPI OleSetClipboard16(IDataObject* pDataObj)
255 FIXME("(%p): stub\n", pDataObj);
256 return S_OK;
259 /***********************************************************************
260 * OleGetClipboard [OLE2.50]
262 HRESULT WINAPI OleGetClipboard16(IDataObject** ppDataObj)
264 FIXME("(%p): stub\n", ppDataObj);
265 return E_NOTIMPL;
268 /***********************************************************************
269 * OleFlushClipboard [OLE2.76]
272 HRESULT WINAPI OleFlushClipboard16(void)
274 return OleFlushClipboard();
277 #define GET_SEGPTR_METHOD_ADDR(ifacename,segptr,methodname) \
278 ((SEGPTR)((const ifacename##Vtbl*)MapSL((SEGPTR)((ifacename*)MapSL(segptr))->lpVtbl))->methodname)
280 /***********************************************************************
281 * ReadClassStg (OLE2.18)
283 * This method reads the CLSID previously written to a storage object with
284 * the WriteClassStg.
286 * PARAMS
287 * pstg [I] Segmented LPSTORAGE pointer.
288 * pclsid [O] Pointer to where the CLSID is written
290 * RETURNS
291 * Success: S_OK.
292 * Failure: HRESULT code.
294 HRESULT WINAPI ReadClassStg16(SEGPTR pstg, CLSID *pclsid)
296 STATSTG16 statstg;
297 HANDLE16 hstatstg;
298 HRESULT hres;
299 DWORD args[3];
301 TRACE("(%x, %p)\n", pstg, pclsid);
303 if (!pclsid)
304 return E_INVALIDARG16;
306 memset(pclsid, 0, sizeof(*pclsid));
308 if (!pstg)
309 return E_INVALIDARG16;
312 * read a STATSTG structure (contains the clsid) from the storage
314 args[0] = pstg; /* iface */
315 args[1] = WOWGlobalAllocLock16( 0, sizeof(STATSTG16), &hstatstg );
316 args[2] = STATFLAG_DEFAULT;
318 if (!WOWCallback16Ex(
319 GET_SEGPTR_METHOD_ADDR(IStorage16, pstg, Stat),
320 WCB16_PASCAL,
321 3*sizeof(DWORD),
322 args,
323 (LPDWORD)&hres
324 )) {
325 WOWGlobalUnlockFree16(args[1]);
326 ERR("CallTo16 IStorage16::Stat() failed, hres %x\n",hres);
327 return hres;
329 memcpy(&statstg, MapSL(args[1]), sizeof(STATSTG16));
330 WOWGlobalUnlockFree16(args[1]);
332 if(SUCCEEDED(hres)) {
333 *pclsid=statstg.clsid;
334 TRACE("clsid is %s\n", debugstr_guid(&statstg.clsid));
336 return hres;
339 /***********************************************************************
340 * ReadClassStm (OLE2.20)
342 HRESULT WINAPI ReadClassStm16(SEGPTR stream, CLSID *clsid)
344 HANDLE16 hclsid, hread;
345 HRESULT hres;
346 DWORD args[4];
348 TRACE("(0x%x, %p)\n", stream, clsid);
350 if (!clsid)
351 return E_INVALIDARG16;
353 memset(clsid, 0, sizeof(*clsid));
355 if (!stream)
356 return E_INVALIDARG16;
358 args[0] = stream; /* iface */
359 args[1] = WOWGlobalAllocLock16( 0, sizeof(CLSID), &hclsid );
360 args[2] = sizeof(CLSID);
361 args[3] = WOWGlobalAllocLock16( 0, sizeof(ULONG), &hread );
363 if (WOWCallback16Ex(
364 GET_SEGPTR_METHOD_ADDR(IStream16, stream, Read),
365 WCB16_PASCAL,
366 4*sizeof(DWORD),
367 args,
368 (DWORD*)&hres))
370 ULONG readlen;
372 memcpy(&readlen, MapSL(args[3]), sizeof(readlen));
373 if (readlen == sizeof(CLSID))
374 memcpy(clsid, MapSL(args[1]), sizeof(CLSID));
375 else
376 hres = STG_E_READFAULT;
378 TRACE("clsid is %s\n", debugstr_guid(clsid));
380 else
382 ERR("CallTo16 IStream16::Read() failed, hres %x\n", hres);
383 hres = E_FAIL;
385 WOWGlobalUnlockFree16(args[1]);
386 WOWGlobalUnlockFree16(args[3]);
388 return hres;
391 /***********************************************************************
392 * GetConvertStg (OLE2.82)
394 HRESULT WINAPI GetConvertStg16(LPSTORAGE stg)
396 FIXME("unimplemented stub!\n");
397 return E_FAIL;
400 /***********************************************************************
401 * ReleaseStgMedium (OLE2.32)
403 VOID WINAPI ReleaseStgMedium16(LPSTGMEDIUM medium)
405 FIXME("%p: unimplemented stub!\n", medium);
408 /***********************************************************************
409 * WriteClassStg16 (OLE2.19)
411 HRESULT WINAPI WriteClassStg16(IStorage *stg, REFCLSID clsid)
413 FIXME("stub:%p %s\n", stg, debugstr_guid(clsid));
414 return STG_E_MEDIUMFULL;