makefiles: Add a standard header for all makefiles to replace the common variable...
[wine] / dlls / ole2.dll16 / ole2.c
1
2 /*
3  *      OLE2 library - 16 bit only interfaces
4  *
5  *      Copyright 1995  Martin von Loewis
6  *      Copyright 1999  Francis Beaudet
7  *      Copyright 1999  Noel Borthwick
8  *
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.
13  *
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.
18  *
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
22  */
23
24 #include "config.h"
25
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
31
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
34 #include "windef.h"
35 #include "winbase.h"
36 #include "wingdi.h"
37 #include "winuser.h"
38 #include "wownt32.h"
39 #include "ole2.h"
40 #include "winerror.h"
41
42 #include "wine/winbase16.h"
43 #include "wine/wingdi16.h"
44 #include "wine/winuser16.h"
45 #include "ifs.h"
46
47 #include "wine/debug.h"
48
49 WINE_DEFAULT_DEBUG_CHANNEL(ole);
50
51
52 static HICON convert_icon_to_32( HICON16 icon16 )
53 {
54     CURSORICONINFO *info = GlobalLock16( icon16 );
55     void *and_bits = info + 1;
56     void *xor_bits = (BYTE *)and_bits + info->nHeight * 2 * ((info->nWidth + 15) / 16);
57     HICON ret = CreateIcon( 0, info->nWidth, info->nHeight, info->bPlanes, info->bBitsPerPixel,
58                             and_bits, xor_bits );
59     GlobalUnlock16( icon16 );
60     return ret;
61 }
62
63 /******************************************************************************
64  *              OleBuildVersion (OLE2.1)
65  */
66 DWORD WINAPI OleBuildVersion16(void)
67 {
68     return OleBuildVersion();
69 }
70
71 /***********************************************************************
72  *           OleInitialize       (OLE2.2)
73  */
74 HRESULT WINAPI OleInitialize16(LPVOID reserved)
75 {
76     return OleInitialize( reserved );
77 }
78
79 /******************************************************************************
80  *              OleUninitialize (OLE2.3)
81  */
82 void WINAPI OleUninitialize16(void)
83 {
84     return OleUninitialize();
85 }
86
87 /***********************************************************************
88  *           DllGetClassObject (OLE2.4)
89  */
90 HRESULT WINAPI DllGetClassObject16(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
91 {
92   FIXME("(%s, %s, %p): stub\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
93   return E_NOTIMPL;
94 }
95
96 /******************************************************************************
97  *              GetRunningObjectTable (OLE2.30)
98  */
99 HRESULT WINAPI GetRunningObjectTable16(DWORD reserved, LPRUNNINGOBJECTTABLE *pprot)
100 {
101     FIXME("(%d,%p),stub!\n",reserved,pprot);
102     return E_NOTIMPL;
103 }
104
105 /***********************************************************************
106  *           RegisterDragDrop (OLE2.35)
107  */
108 HRESULT WINAPI RegisterDragDrop16(
109         HWND16 hwnd,
110         LPDROPTARGET pDropTarget
111 ) {
112         FIXME("(0x%04x,%p),stub!\n",hwnd,pDropTarget);
113         return S_OK;
114 }
115
116 /***********************************************************************
117  *           RevokeDragDrop (OLE2.36)
118  */
119 HRESULT WINAPI RevokeDragDrop16(
120         HWND16 hwnd
121 ) {
122         FIXME("(0x%04x),stub!\n",hwnd);
123         return S_OK;
124 }
125
126 /******************************************************************************
127  * OleMetaFilePictFromIconAndLabel (OLE2.56)
128  *
129  * Returns a global memory handle to a metafile which contains the icon and
130  * label given.
131  * I guess the result of that should look somehow like desktop icons.
132  * If no hIcon is given, we load the icon via lpszSourceFile and iIconIndex.
133  * This code might be wrong at some places.
134  */
135 HGLOBAL16 WINAPI OleMetafilePictFromIconAndLabel16(
136         HICON16 icon16,
137         LPCOLESTR16 lpszLabel,
138         LPCOLESTR16 lpszSourceFile,
139         UINT16 iIconIndex
140 ) {
141     METAFILEPICT *pict;
142     HGLOBAL hmf;
143     HGLOBAL16 hmf16;
144     LPWSTR label = NULL, source = NULL;
145     DWORD len;
146     HICON icon = convert_icon_to_32( icon16 );
147
148     if (lpszLabel)
149     {
150         len = MultiByteToWideChar( CP_ACP, 0, lpszLabel, -1, NULL, 0 );
151         label = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
152         MultiByteToWideChar( CP_ACP, 0, lpszLabel, -1, label, len );
153     }
154     if (lpszSourceFile)
155     {
156         len = MultiByteToWideChar( CP_ACP, 0, lpszSourceFile, -1, NULL, 0 );
157         source = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
158         MultiByteToWideChar( CP_ACP, 0, lpszSourceFile, -1, source, len );
159     }
160     hmf = OleMetafilePictFromIconAndLabel( icon, label, source, iIconIndex );
161     HeapFree( GetProcessHeap(), 0, label );
162     HeapFree( GetProcessHeap(), 0, source );
163     DestroyIcon( icon );
164
165     if (!hmf) return 0;
166     pict = GlobalLock( hmf );
167
168     hmf16 = GlobalAlloc16(0, sizeof(METAFILEPICT16));
169     if (hmf16)
170     {
171         METAFILEPICT16 *pict16 = GlobalLock16( hmf16 );
172         pict16->mm   = pict->mm;
173         pict16->xExt = pict->xExt;
174         pict16->yExt = pict->yExt;
175         len = GetMetaFileBitsEx( pict->hMF, 0, 0 );
176         pict16->hMF = GlobalAlloc16( GMEM_MOVEABLE, len );
177         GetMetaFileBitsEx( pict->hMF, len, GlobalLock16( pict16->hMF) );
178         GlobalUnlock16( pict16->hMF );
179         GlobalUnlock16( hmf16 );
180     }
181     DeleteMetaFile( pict->hMF );
182     GlobalUnlock( hmf );
183     GlobalFree( hmf );
184     return hmf16;
185 }
186
187
188 /******************************************************************************
189  *        CreateItemMoniker     (OLE2.27)
190  */
191 HRESULT WINAPI CreateItemMoniker16(LPCOLESTR16 lpszDelim,LPCOLESTR16 lpszItem,LPMONIKER* ppmk)
192 {
193     FIXME("(%s,%p),stub!\n",lpszDelim,ppmk);
194     *ppmk = NULL;
195     return E_NOTIMPL;
196 }
197
198
199 /******************************************************************************
200  *        CreateFileMoniker (OLE2.28)
201  */
202 HRESULT WINAPI CreateFileMoniker16(LPCOLESTR16 lpszPathName,LPMONIKER* ppmk)
203 {
204     FIXME("(%s,%p),stub!\n",lpszPathName,ppmk);
205     return E_NOTIMPL;
206 }
207
208 /******************************************************************************
209  *        OleSetMenuDescriptor (OLE2.41)
210  *
211  * PARAMS
212  *  hOleMenu  FIXME: Should probably be an HOLEMENU16.
213  */
214 HRESULT WINAPI OleSetMenuDescriptor16(
215     HOLEMENU               hOleMenu,
216     HWND16                 hwndFrame,
217     HWND16                 hwndActiveObject,
218     LPOLEINPLACEFRAME        lpFrame,
219     LPOLEINPLACEACTIVEOBJECT lpActiveObject)
220 {
221     FIXME("(%p, %x, %x, %p, %p), stub!\n", hOleMenu, hwndFrame, hwndActiveObject, lpFrame, lpActiveObject);
222     return E_NOTIMPL;
223 }
224
225 /******************************************************************************
226  *              OleLoad        [OLE2.12]
227  *
228  * PARAMS
229  *  pStg Segmented LPSTORAGE pointer.
230  *  pClientSite Segmented LPOLECLIENTSITE pointer.
231  */
232 HRESULT WINAPI OleLoad16(
233     SEGPTR              pStg,
234     REFIID              riid,
235     SEGPTR              pClientSite,
236     LPVOID*             ppvObj)
237 {
238   FIXME("(%x,%s,%x,%p), stub!\n", pStg, debugstr_guid(riid), pClientSite, ppvObj);
239   return E_NOTIMPL;
240 }
241
242 /******************************************************************************
243  *              OleDoAutoConvert        [OLE2.79]
244  */
245 HRESULT WINAPI OleDoAutoConvert16(LPSTORAGE pStg, LPCLSID pClsidNew)
246 {
247     FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
248     return E_NOTIMPL;
249 }
250
251 /***********************************************************************
252  *           OleSetClipboard                            [OLE2.49]
253  */
254 HRESULT WINAPI OleSetClipboard16(IDataObject* pDataObj)
255 {
256   FIXME("(%p): stub\n", pDataObj);
257   return S_OK;
258 }
259
260 /***********************************************************************
261  *           OleGetClipboard                            [OLE2.50]
262  */
263 HRESULT WINAPI OleGetClipboard16(IDataObject** ppDataObj)
264 {
265   FIXME("(%p): stub\n", ppDataObj);
266   return E_NOTIMPL;
267 }
268
269 /***********************************************************************
270  *           OleFlushClipboard   [OLE2.76]
271  */
272
273 HRESULT WINAPI OleFlushClipboard16(void)
274 {
275   return OleFlushClipboard();
276 }
277
278 /***********************************************************************
279  *    ReadClassStg (OLE2.18)
280  *
281  * This method reads the CLSID previously written to a storage object with
282  * the WriteClassStg.
283  *
284  * PARAMS
285  *  pstg    [I] Segmented LPSTORAGE pointer.
286  *  pclsid  [O] Pointer to where the CLSID is written
287  *
288  * RETURNS
289  *  Success: S_OK.
290  *  Failure: HRESULT code.
291  */
292 HRESULT WINAPI ReadClassStg16(SEGPTR pstg, CLSID *pclsid)
293 {
294         STATSTG16 statstg;
295         HANDLE16 hstatstg;
296         HRESULT hres;
297         DWORD args[3];
298
299         TRACE("(%x, %p)\n", pstg, pclsid);
300
301         if(pclsid==NULL)
302                 return E_POINTER;
303         /*
304          * read a STATSTG structure (contains the clsid) from the storage
305          */
306         args[0] = (DWORD)pstg;  /* iface */
307         args[1] = WOWGlobalAllocLock16( 0, sizeof(STATSTG16), &hstatstg );
308         args[2] = STATFLAG_DEFAULT;
309
310         if (!WOWCallback16Ex(
311             (DWORD)((const IStorage16Vtbl*)MapSL(
312                         (SEGPTR)((LPSTORAGE16)MapSL(pstg))->lpVtbl)
313             )->Stat,
314             WCB16_PASCAL,
315             3*sizeof(DWORD),
316             (LPVOID)args,
317             (LPDWORD)&hres
318         )) {
319             WOWGlobalUnlockFree16(args[1]);
320             ERR("CallTo16 IStorage16::Stat() failed, hres %x\n",hres);
321             return hres;
322         }
323         memcpy(&statstg, MapSL(args[1]), sizeof(STATSTG16));
324         WOWGlobalUnlockFree16(args[1]);
325
326         if(SUCCEEDED(hres)) {
327                 *pclsid=statstg.clsid;
328                 TRACE("clsid is %s\n", debugstr_guid(&statstg.clsid));
329         }
330         return hres;
331 }
332
333 /***********************************************************************
334  *              GetConvertStg (OLE2.82)
335  */
336 HRESULT WINAPI GetConvertStg16(LPSTORAGE stg) {
337     FIXME("unimplemented stub!\n");
338     return E_FAIL;
339 }