shell32: Added partial implementation of SHPropStgWriteMultiple.
[wine] / dlls / shell32 / shellole.c
1 /*
2  *      handling of SHELL32.DLL OLE-Objects
3  *
4  *      Copyright 1997  Marcus Meissner
5  *      Copyright 1998  Juergen Schmied  <juergen.schmied@metronet.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #define COBJMACROS
29 #define NONAMELESSUNION
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "shellapi.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "shlobj.h"
37 #include "shlguid.h"
38 #include "winreg.h"
39 #include "winerror.h"
40
41 #include "undocshell.h"
42 #include "wine/unicode.h"
43 #include "shell32_main.h"
44
45 #include "wine/debug.h"
46 #include "shlwapi.h"
47 #include "debughlp.h"
48
49 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50
51 extern INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax);  /* shlwapi.24 */
52
53 /**************************************************************************
54  * Default ClassFactory types
55  */
56 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
57 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
58
59 /* this table contains all CLSID's of shell32 objects */
60 static const struct {
61         REFIID                  riid;
62         LPFNCREATEINSTANCE      lpfnCI;
63 } InterfaceTable[] = {
64
65         {&CLSID_AutoComplete,   IAutoComplete_Constructor},
66         {&CLSID_ControlPanel,   IControlPanel_Constructor},
67         {&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
68         {&CLSID_FolderShortcut, FolderShortcut_Constructor},
69         {&CLSID_MyComputer,     ISF_MyComputer_Constructor},
70         {&CLSID_MyDocuments,    MyDocuments_Constructor},
71         {&CLSID_NetworkPlaces,  ISF_NetworkPlaces_Constructor},
72         {&CLSID_Printers,       Printers_Constructor},
73         {&CLSID_QueryAssociations, QueryAssociations_Constructor},
74         {&CLSID_RecycleBin,     RecycleBin_Constructor},
75         {&CLSID_ShellDesktop,   ISF_Desktop_Constructor},
76         {&CLSID_ShellFSFolder,  IFSFolder_Constructor},
77         {&CLSID_ShellItem,      IShellItem_Constructor},
78         {&CLSID_ShellLink,      IShellLink_Constructor},
79         {&CLSID_UnixDosFolder,  UnixDosFolder_Constructor},
80         {&CLSID_UnixFolder,     UnixFolder_Constructor},
81         {&CLSID_ExplorerBrowser,ExplorerBrowser_Constructor},
82         {&CLSID_KnownFolderManager, KnownFolderManager_Constructor},
83         {NULL, NULL}
84 };
85
86 /*************************************************************************
87  * SHCoCreateInstance [SHELL32.102]
88  *
89  * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
90  * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
91  * SHLoadOLE for details.
92  *
93  * Under wine if a "LoadWithoutCOM" value is present or the object resides in
94  * shell32.dll the function will load the object manually without the help of ole32
95  *
96  * NOTES
97  *     exported by ordinal
98  *
99  * SEE ALSO
100  *     CoCreateInstace, SHLoadOLE
101  */
102 HRESULT WINAPI SHCoCreateInstance(
103         LPCWSTR aclsid,
104         const CLSID *clsid,
105         LPUNKNOWN pUnkOuter,
106         REFIID refiid,
107         LPVOID *ppv)
108 {
109         DWORD   hres;
110         IID     iid;
111         const   CLSID * myclsid = clsid;
112         WCHAR   sKeyName[MAX_PATH];
113         const   WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
114         WCHAR   sClassID[60];
115         const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
116         const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
117         WCHAR   sDllPath[MAX_PATH];
118         HKEY    hKey = 0;
119         DWORD   dwSize;
120         IClassFactory * pcf = NULL;
121
122         if(!ppv) return E_POINTER;
123         *ppv=NULL;
124
125         /* if the clsid is a string, convert it */
126         if (!clsid)
127         {
128           if (!aclsid) return REGDB_E_CLASSNOTREG;
129           SHCLSIDFromStringW(aclsid, &iid);
130           myclsid = &iid;
131         }
132
133         TRACE("(%p,%s,unk:%p,%s,%p)\n",
134                 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
135
136         if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
137         {
138             hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
139             IClassFactory_Release(pcf);
140             goto end;
141         }
142
143         /* we look up the dll path in the registry */
144         SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
145         lstrcpyW(sKeyName, sCLSID);
146         lstrcatW(sKeyName, sClassID);
147         lstrcatW(sKeyName, sInProcServer32);
148
149         if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
150             return E_ACCESSDENIED;
151
152         /* if a special registry key is set, we load a shell extension without help of OLE32 */
153         if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
154         {
155             /* load an external dll without ole32 */
156             HANDLE hLibrary;
157             typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
158             DllGetClassObjectFunc DllGetClassObject;
159
160             dwSize = sizeof(sDllPath);
161             SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
162
163             if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
164                 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
165                 hres = E_ACCESSDENIED;
166                 goto end;
167             } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
168                 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
169                 FreeLibrary( hLibrary );
170                 hres = E_ACCESSDENIED;
171                 goto end;
172             } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
173                     TRACE("GetClassObject failed 0x%08x\n", hres);
174                     goto end;
175             }
176
177             hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
178             IClassFactory_Release(pcf);
179         } else {
180
181             /* load an external dll in the usual way */
182             hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
183         }
184
185 end:
186         if (hKey) RegCloseKey(hKey);
187         if(hres!=S_OK)
188         {
189           ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
190               hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
191           ERR("class not found in registry\n");
192         }
193
194         TRACE("-- instance: %p\n",*ppv);
195         return hres;
196 }
197
198 /*************************************************************************
199  * DllGetClassObject     [SHELL32.@]
200  * SHDllGetClassObject   [SHELL32.128]
201  */
202 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
203 {
204         HRESULT hres = E_OUTOFMEMORY;
205         IClassFactory * pcf = NULL;
206         int i;
207
208         TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
209
210         if (!ppv) return E_INVALIDARG;
211         *ppv = NULL;
212
213         /* search our internal interface table */
214         for(i=0;InterfaceTable[i].riid;i++) {
215             if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
216                 TRACE("index[%u]\n", i);
217                 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
218             }
219         }
220
221         if (!pcf) {
222             FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
223             return CLASS_E_CLASSNOTAVAILABLE;
224         }
225
226         hres = IClassFactory_QueryInterface(pcf, iid, ppv);
227         IClassFactory_Release(pcf);
228
229         TRACE("-- pointer to class factory: %p\n",*ppv);
230         return hres;
231 }
232
233 /*************************************************************************
234  * SHCLSIDFromString                            [SHELL32.147]
235  *
236  * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
237  * to avoid dependency on ole32.dll (see SHLoadOLE for details).
238  *
239  * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
240  *
241  * NOTES
242  *     exported by ordinal
243  *
244  * SEE ALSO
245  *     CLSIDFromString, SHLoadOLE
246  */
247 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
248 {
249     WCHAR buffer[40];
250     TRACE("(%p(%s) %p)\n", clsid, clsid, id);
251     if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
252         return CO_E_CLASSSTRING;
253     return CLSIDFromString( buffer, id );
254 }
255 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
256 {
257         TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
258         return CLSIDFromString(clsid, id);
259 }
260 DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
261 {
262         if (SHELL_OsIsUnicode())
263           return SHCLSIDFromStringW (clsid, id);
264         return SHCLSIDFromStringA (clsid, id);
265 }
266
267 /*************************************************************************
268  *                       SHGetMalloc                    [SHELL32.@]
269  *
270  * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
271  * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
272  * see SHLoadOLE for details. 
273  *
274  * PARAMS
275  *  lpmal [O] Destination for IMalloc interface.
276  *
277  * RETURNS
278  *  Success: S_OK. lpmal contains the shells IMalloc interface.
279  *  Failure. An HRESULT error code.
280  *
281  * SEE ALSO
282  *  CoGetMalloc, SHLoadOLE
283  */
284 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
285 {
286         TRACE("(%p)\n", lpmal);
287         return CoGetMalloc(MEMCTX_TASK, lpmal);
288 }
289
290 /*************************************************************************
291  * SHAlloc                                      [SHELL32.196]
292  *
293  * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
294  * the shell32 built-in "mini-COM" without the need to load ole32.dll -
295  * see SHLoadOLE for details. 
296  *
297  * NOTES
298  *     exported by ordinal
299  *
300  * SEE ALSO
301  *     CoTaskMemAlloc, SHLoadOLE
302  */
303 LPVOID WINAPI SHAlloc(DWORD len)
304 {
305         LPVOID ret;
306
307         ret = CoTaskMemAlloc(len);
308         TRACE("%u bytes at %p\n",len, ret);
309         return ret;
310 }
311
312 /*************************************************************************
313  * SHFree                                       [SHELL32.195]
314  *
315  * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
316  * the shell32 built-in "mini-COM" without the need to load ole32.dll -
317  * see SHLoadOLE for details. 
318  *
319  * NOTES
320  *     exported by ordinal
321  *
322  * SEE ALSO
323  *     CoTaskMemFree, SHLoadOLE
324  */
325 void WINAPI SHFree(LPVOID pv)
326 {
327         TRACE("%p\n",pv);
328         CoTaskMemFree(pv);
329 }
330
331 /*************************************************************************
332  * SHGetDesktopFolder                   [SHELL32.@]
333  */
334 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
335 {
336         HRESULT hres;
337
338         TRACE("(%p)\n", psf);
339
340         if(!psf) return E_INVALIDARG;
341
342         *psf = NULL;
343         hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
344
345         TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
346         return hres;
347 }
348 /**************************************************************************
349  * Default ClassFactory Implementation
350  *
351  * SHCreateDefClassObject
352  *
353  * NOTES
354  *  Helper function for dlls without their own classfactory.
355  *  A generic classfactory is returned.
356  *  When the CreateInstance of the cf is called the callback is executed.
357  */
358
359 typedef struct
360 {
361     const IClassFactoryVtbl    *lpVtbl;
362     LONG                        ref;
363     CLSID                       *rclsid;
364     LPFNCREATEINSTANCE          lpfnCI;
365     const IID *                 riidInst;
366     LONG *                      pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
367 } IDefClFImpl;
368
369 static const IClassFactoryVtbl dclfvt;
370
371 /**************************************************************************
372  *  IDefClF_fnConstructor
373  */
374
375 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
376 {
377         IDefClFImpl* lpclf;
378
379         lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
380         lpclf->ref = 1;
381         lpclf->lpVtbl = &dclfvt;
382         lpclf->lpfnCI = lpfnCI;
383         lpclf->pcRefDll = pcRefDll;
384
385         if (pcRefDll) InterlockedIncrement(pcRefDll);
386         lpclf->riidInst = riidInst;
387
388         TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
389         return (LPCLASSFACTORY)lpclf;
390 }
391 /**************************************************************************
392  *  IDefClF_fnQueryInterface
393  */
394 static HRESULT WINAPI IDefClF_fnQueryInterface(
395   LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
396 {
397         IDefClFImpl *This = (IDefClFImpl *)iface;
398
399         TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
400
401         *ppvObj = NULL;
402
403         if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
404           *ppvObj = This;
405           InterlockedIncrement(&This->ref);
406           return S_OK;
407         }
408
409         TRACE("-- E_NOINTERFACE\n");
410         return E_NOINTERFACE;
411 }
412 /******************************************************************************
413  * IDefClF_fnAddRef
414  */
415 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
416 {
417         IDefClFImpl *This = (IDefClFImpl *)iface;
418         ULONG refCount = InterlockedIncrement(&This->ref);
419
420         TRACE("(%p)->(count=%u)\n", This, refCount - 1);
421
422         return refCount;
423 }
424 /******************************************************************************
425  * IDefClF_fnRelease
426  */
427 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
428 {
429         IDefClFImpl *This = (IDefClFImpl *)iface;
430         ULONG refCount = InterlockedDecrement(&This->ref);
431         
432         TRACE("(%p)->(count=%u)\n", This, refCount + 1);
433
434         if (!refCount)
435         {
436           if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
437
438           TRACE("-- destroying IClassFactory(%p)\n",This);
439           HeapFree(GetProcessHeap(),0,This);
440           return 0;
441         }
442         return refCount;
443 }
444 /******************************************************************************
445  * IDefClF_fnCreateInstance
446  */
447 static HRESULT WINAPI IDefClF_fnCreateInstance(
448   LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
449 {
450         IDefClFImpl *This = (IDefClFImpl *)iface;
451
452         TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
453
454         *ppvObject = NULL;
455
456         if ( This->riidInst==NULL ||
457              IsEqualCLSID(riid, This->riidInst) ||
458              IsEqualCLSID(riid, &IID_IUnknown) )
459         {
460           return This->lpfnCI(pUnkOuter, riid, ppvObject);
461         }
462
463         ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
464         return E_NOINTERFACE;
465 }
466 /******************************************************************************
467  * IDefClF_fnLockServer
468  */
469 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
470 {
471         IDefClFImpl *This = (IDefClFImpl *)iface;
472         TRACE("%p->(0x%x), not implemented\n",This, fLock);
473         return E_NOTIMPL;
474 }
475
476 static const IClassFactoryVtbl dclfvt =
477 {
478     IDefClF_fnQueryInterface,
479     IDefClF_fnAddRef,
480   IDefClF_fnRelease,
481   IDefClF_fnCreateInstance,
482   IDefClF_fnLockServer
483 };
484
485 /******************************************************************************
486  * SHCreateDefClassObject                       [SHELL32.70]
487  */
488 HRESULT WINAPI SHCreateDefClassObject(
489         REFIID  riid,
490         LPVOID* ppv,
491         LPFNCREATEINSTANCE lpfnCI,      /* [in] create instance callback entry */
492         LPDWORD pcRefDll,               /* [in/out] ref count of the dll */
493         REFIID  riidInst)               /* [in] optional interface to the instance */
494 {
495         IClassFactory * pcf;
496
497         TRACE("%s %p %p %p %s\n",
498               shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
499
500         if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
501         if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
502         *ppv = pcf;
503         return NOERROR;
504 }
505
506 /*************************************************************************
507  *  DragAcceptFiles             [SHELL32.@]
508  */
509 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
510 {
511         LONG exstyle;
512
513         if( !IsWindow(hWnd) ) return;
514         exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
515         if (b)
516           exstyle |= WS_EX_ACCEPTFILES;
517         else
518           exstyle &= ~WS_EX_ACCEPTFILES;
519         SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
520 }
521
522 /*************************************************************************
523  * DragFinish           [SHELL32.@]
524  */
525 void WINAPI DragFinish(HDROP h)
526 {
527         TRACE("\n");
528         GlobalFree(h);
529 }
530
531 /*************************************************************************
532  * DragQueryPoint               [SHELL32.@]
533  */
534 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
535 {
536         DROPFILES *lpDropFileStruct;
537         BOOL bRet;
538
539         TRACE("\n");
540
541         lpDropFileStruct = GlobalLock(hDrop);
542
543         *p = lpDropFileStruct->pt;
544         bRet = lpDropFileStruct->fNC;
545
546         GlobalUnlock(hDrop);
547         return bRet;
548 }
549
550 /*************************************************************************
551  *  DragQueryFileA              [SHELL32.@]
552  *  DragQueryFile               [SHELL32.@]
553  */
554 UINT WINAPI DragQueryFileA(
555         HDROP hDrop,
556         UINT lFile,
557         LPSTR lpszFile,
558         UINT lLength)
559 {
560         LPSTR lpDrop;
561         UINT i = 0;
562         DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
563
564         TRACE("(%p, %x, %p, %u)\n",     hDrop,lFile,lpszFile,lLength);
565
566         if(!lpDropFileStruct) goto end;
567
568         lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
569
570         if(lpDropFileStruct->fWide) {
571             LPWSTR lpszFileW = NULL;
572
573             if(lpszFile) {
574                 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
575                 if(lpszFileW == NULL) {
576                     goto end;
577                 }
578             }
579             i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
580
581             if(lpszFileW) {
582                 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
583                 HeapFree(GetProcessHeap(), 0, lpszFileW);
584             }
585             goto end;
586         }
587
588         while (i++ < lFile)
589         {
590           while (*lpDrop++); /* skip filename */
591           if (!*lpDrop)
592           {
593             i = (lFile == 0xFFFFFFFF) ? i : 0;
594             goto end;
595           }
596         }
597
598         i = strlen(lpDrop);
599         if (!lpszFile ) goto end;   /* needed buffer size */
600         lstrcpynA (lpszFile, lpDrop, lLength);
601 end:
602         GlobalUnlock(hDrop);
603         return i;
604 }
605
606 /*************************************************************************
607  *  DragQueryFileW              [SHELL32.@]
608  */
609 UINT WINAPI DragQueryFileW(
610         HDROP hDrop,
611         UINT lFile,
612         LPWSTR lpszwFile,
613         UINT lLength)
614 {
615         LPWSTR lpwDrop;
616         UINT i = 0;
617         DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
618
619         TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
620
621         if(!lpDropFileStruct) goto end;
622
623         lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
624
625         if(lpDropFileStruct->fWide == FALSE) {
626             LPSTR lpszFileA = NULL;
627
628             if(lpszwFile) {
629                 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
630                 if(lpszFileA == NULL) {
631                     goto end;
632                 }
633             }
634             i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
635
636             if(lpszFileA) {
637                 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
638                 HeapFree(GetProcessHeap(), 0, lpszFileA);
639             }
640             goto end;
641         }
642
643         i = 0;
644         while (i++ < lFile)
645         {
646           while (*lpwDrop++); /* skip filename */
647           if (!*lpwDrop)
648           {
649             i = (lFile == 0xFFFFFFFF) ? i : 0;
650             goto end;
651           }
652         }
653
654         i = strlenW(lpwDrop);
655         if ( !lpszwFile) goto end;   /* needed buffer size */
656         lstrcpynW (lpszwFile, lpwDrop, lLength);
657 end:
658         GlobalUnlock(hDrop);
659         return i;
660 }
661
662 /*************************************************************************
663  *  SHPropStgCreate             [SHELL32.685]
664  */
665 HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
666         const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
667         DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
668 {
669     PROPSPEC prop;
670     PROPVARIANT ret;
671     HRESULT hres;
672
673     TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
674             grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
675
676     hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
677
678     switch(dwDisposition) {
679     case CREATE_ALWAYS:
680         if(SUCCEEDED(hres)) {
681             IPropertyStorage_Release(*ppstg);
682             hres = IPropertySetStorage_Delete(psstg, fmtid);
683             if(FAILED(hres))
684                 return hres;
685             hres = E_FAIL;
686         }
687
688     case OPEN_ALWAYS:
689     case CREATE_NEW:
690         if(FAILED(hres))
691             hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
692                     grfFlags, grfMode, ppstg);
693
694     case OPEN_EXISTING:
695         if(FAILED(hres))
696             return hres;
697
698         if(puCodePage) {
699             prop.ulKind = PRSPEC_PROPID;
700             prop.u.propid = PID_CODEPAGE;
701             hres = IPropertyStorage_ReadMultiple(*ppstg, 1, &prop, &ret);
702             if(FAILED(hres) || ret.vt!=VT_I2)
703                 *puCodePage = 0;
704             else
705                 *puCodePage = ret.u.iVal;
706         }
707     }
708
709     return S_OK;
710 }
711
712 /*************************************************************************
713  *  SHPropStgReadMultiple       [SHELL32.688]
714  */
715 HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
716         ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
717 {
718     STATPROPSETSTG stat;
719     HRESULT hres;
720
721     FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
722
723     memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
724     hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
725     if(FAILED(hres))
726         return hres;
727
728     if(!uCodePage) {
729         PROPSPEC prop;
730         PROPVARIANT ret;
731
732         prop.ulKind = PRSPEC_PROPID;
733         prop.u.propid = PID_CODEPAGE;
734         hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
735         if(FAILED(hres) || ret.vt!=VT_I2)
736             return S_OK;
737
738         uCodePage = ret.u.iVal;
739     }
740
741     hres = IPropertyStorage_Stat(pps, &stat);
742     if(FAILED(hres))
743         return S_OK;
744
745     /* TODO: do something with codepage and stat */
746     return S_OK;
747 }
748
749 /*************************************************************************
750  *  SHPropStgWriteMultiple      [SHELL32.689]
751  */
752 HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
753         ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
754 {
755     STATPROPSETSTG stat;
756     UINT codepage;
757     HRESULT hres;
758
759     FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
760
761     hres = IPropertyStorage_Stat(pps, &stat);
762     if(FAILED(hres))
763         return hres;
764
765     if(uCodePage && *uCodePage)
766         codepage = *uCodePage;
767     else {
768         PROPSPEC prop;
769         PROPVARIANT ret;
770
771         prop.ulKind = PRSPEC_PROPID;
772         prop.u.propid = PID_CODEPAGE;
773         hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
774         if(FAILED(hres))
775             return hres;
776         if(ret.vt!=VT_I2 || !ret.u.iVal)
777             return E_FAIL;
778
779         codepage = ret.u.iVal;
780         if(uCodePage)
781             *uCodePage = codepage;
782     }
783
784     /* TODO: do something with codepage and stat */
785
786     hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
787     return hres;
788 }