shell32: Update German resources.
[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
30 #include "windef.h"
31 #include "winbase.h"
32 #include "shellapi.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "shlobj.h"
36 #include "shlguid.h"
37 #include "winreg.h"
38 #include "winerror.h"
39
40 #include "undocshell.h"
41 #include "wine/unicode.h"
42 #include "shell32_main.h"
43
44 #include "wine/debug.h"
45 #include "shlwapi.h"
46 #include "debughlp.h"
47
48 WINE_DEFAULT_DEBUG_CHANNEL(shell);
49
50 extern HRESULT WINAPI IFSFolder_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
51
52 static const WCHAR sShell32[12] = {'S','H','E','L','L','3','2','.','D','L','L','\0'};
53
54 /**************************************************************************
55  * Default ClassFactory types
56  */
57 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
58 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
59
60 /* this table contains all CLSID's of shell32 objects */
61 static const struct {
62         REFIID                  riid;
63         LPFNCREATEINSTANCE      lpfnCI;
64 } InterfaceTable[] = {
65         {&CLSID_ShellFSFolder,  &IFSFolder_Constructor},
66         {&CLSID_MyComputer,     &ISF_MyComputer_Constructor},
67         {&CLSID_ShellDesktop,   &ISF_Desktop_Constructor},
68         {&CLSID_ShellLink,      &IShellLink_Constructor},
69         {&CLSID_DragDropHelper, &IDropTargetHelper_Constructor},
70         {&CLSID_ControlPanel,   &IControlPanel_Constructor},
71         {&CLSID_AutoComplete,   &IAutoComplete_Constructor},
72         {&CLSID_UnixFolder,     &UnixFolder_Constructor},
73         {&CLSID_UnixDosFolder,  &UnixDosFolder_Constructor},
74         {&CLSID_FolderShortcut, &FolderShortcut_Constructor},
75         {&CLSID_MyDocuments,    &MyDocuments_Constructor},
76         {&CLSID_RecycleBin,     &RecycleBin_Constructor},
77         {NULL,NULL}
78 };
79
80
81 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
82
83 DWORD WINAPI __SHGUIDToStringW (REFGUID guid, LPWSTR str)
84 {
85     WCHAR sFormat[52] = {'{','%','0','8','l','x','-','%','0','4',
86                          'x','-','%','0','4','x','-','%','0','2',
87                          'x','%','0','2','x','-','%','0','2','x',
88                          '%','0','2','x','%','0','2','x','%','0',
89                          '2','x','%','0','2','x','%','0','2','x',
90                          '}','\0'};
91
92     return wsprintfW ( str, sFormat,
93              guid->Data1, guid->Data2, guid->Data3,
94              guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
95              guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
96
97 }
98
99 /*************************************************************************
100  * SHCoCreateInstance [SHELL32.102]
101  *
102  * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
103  * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
104  * SHLoadOLE for details.
105  *
106  * Under wine if a "LoadWithoutCOM" value is present or the object resides in
107  * shell32.dll the function will load the object manually without the help of ole32
108  *
109  * NOTES
110  *     exported by ordinal
111  *
112  * SEE ALSO
113  *     CoCreateInstace, SHLoadOLE
114  */
115 HRESULT WINAPI SHCoCreateInstance(
116         LPCWSTR aclsid,
117         const CLSID *clsid,
118         LPUNKNOWN pUnkOuter,
119         REFIID refiid,
120         LPVOID *ppv)
121 {
122         DWORD   hres;
123         IID     iid;
124         const   CLSID * myclsid = clsid;
125         WCHAR   sKeyName[MAX_PATH];
126         const   WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
127         WCHAR   sClassID[60];
128         const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
129         const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
130         WCHAR   sDllPath[MAX_PATH];
131         HKEY    hKey;
132         DWORD   dwSize;
133         BOOLEAN bLoadFromShell32 = FALSE;
134         BOOLEAN bLoadWithoutCOM = FALSE;
135         IClassFactory * pcf = NULL;
136
137         if(!ppv) return E_POINTER;
138         *ppv=NULL;
139
140         /* if the clsid is a string, convert it */
141         if (!clsid)
142         {
143           if (!aclsid) return REGDB_E_CLASSNOTREG;
144           SHCLSIDFromStringW(aclsid, &iid);
145           myclsid = &iid;
146         }
147
148         TRACE("(%p,%s,unk:%p,%s,%p)\n",
149                 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
150
151         /* we look up the dll path in the registry */
152         __SHGUIDToStringW(myclsid, sClassID);
153         lstrcpyW(sKeyName, sCLSID);
154         lstrcatW(sKeyName, sClassID);
155         lstrcatW(sKeyName, sInProcServer32);
156
157         if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey)) {
158             dwSize = sizeof(sDllPath);
159             SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
160
161             /* if a special registry key is set, we load a shell extension without help of OLE32 */
162             bLoadWithoutCOM = (ERROR_SUCCESS == SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0));
163
164             /* if the com object is inside shell32, omit use of ole32 */
165             bLoadFromShell32 = (0==lstrcmpiW( PathFindFileNameW(sDllPath), sShell32));
166
167             RegCloseKey (hKey);
168         } else {
169             /* since we can't find it in the registry we try internally */
170             bLoadFromShell32 = TRUE;
171         }
172
173         TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM, bLoadFromShell32);
174
175         /* now we create an instance */
176         if (bLoadFromShell32) {
177             if (! SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf))) {
178                 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid));
179             }
180         } else if (bLoadWithoutCOM) {
181
182             /* load an external dll without ole32 */
183             HANDLE hLibrary;
184             typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
185             DllGetClassObjectFunc DllGetClassObject;
186
187             if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
188                 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
189                 hres = E_ACCESSDENIED;
190                 goto end;
191             } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
192                 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
193                 FreeLibrary( hLibrary );
194                 hres = E_ACCESSDENIED;
195                 goto end;
196             } else if (! SUCCEEDED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
197                     TRACE("GetClassObject failed 0x%08x\n", hres);
198                     goto end;
199             }
200
201         } else {
202
203             /* load an external dll in the usual way */
204             hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
205             goto end;
206         }
207
208         /* here we should have a ClassFactory */
209         if (!pcf) return E_ACCESSDENIED;
210
211         hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
212         IClassFactory_Release(pcf);
213 end:
214         if(hres!=S_OK)
215         {
216           ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
217               hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
218           ERR("class not found in registry\n");
219         }
220
221         TRACE("-- instance: %p\n",*ppv);
222         return hres;
223 }
224
225 /*************************************************************************
226  * DllGetClassObject     [SHELL32.@]
227  * SHDllGetClassObject   [SHELL32.128]
228  */
229 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
230 {
231         HRESULT hres = E_OUTOFMEMORY;
232         IClassFactory * pcf = NULL;
233         int i;
234
235         TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
236
237         if (!ppv) return E_INVALIDARG;
238         *ppv = NULL;
239
240         /* search our internal interface table */
241         for(i=0;InterfaceTable[i].riid;i++) {
242             if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
243                 TRACE("index[%u]\n", i);
244                 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
245             }
246         }
247
248         if (!pcf) {
249             FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
250             return CLASS_E_CLASSNOTAVAILABLE;
251         }
252
253         hres = IClassFactory_QueryInterface(pcf, iid, ppv);
254         IClassFactory_Release(pcf);
255
256         TRACE("-- pointer to class factory: %p\n",*ppv);
257         return hres;
258 }
259
260 /*************************************************************************
261  * SHCLSIDFromString                            [SHELL32.147]
262  *
263  * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
264  * to avoid dependency on ole32.dll (see SHLoadOLE for details).
265  *
266  * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
267  *
268  * NOTES
269  *     exported by ordinal
270  *
271  * SEE ALSO
272  *     CLSIDFromString, SHLoadOLE
273  */
274 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
275 {
276     WCHAR buffer[40];
277     TRACE("(%p(%s) %p)\n", clsid, clsid, id);
278     if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
279         return CO_E_CLASSSTRING;
280     return CLSIDFromString( buffer, id );
281 }
282 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
283 {
284         TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
285         return CLSIDFromString((LPWSTR)clsid, id);
286 }
287 DWORD WINAPI SHCLSIDFromStringAW (LPVOID clsid, CLSID *id)
288 {
289         if (SHELL_OsIsUnicode())
290           return SHCLSIDFromStringW (clsid, id);
291         return SHCLSIDFromStringA (clsid, id);
292 }
293
294 /*************************************************************************
295  *                       SHGetMalloc                    [SHELL32.@]
296  *
297  * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
298  * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
299  * see SHLoadOLE for details. 
300  *
301  * PARAMS
302  *  lpmal [O] Destination for IMalloc interface.
303  *
304  * RETURNS
305  *  Success: S_OK. lpmal contains the shells IMalloc interface.
306  *  Failure. An HRESULT error code.
307  *
308  * SEE ALSO
309  *  CoGetMalloc, SHLoadOLE
310  */
311 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
312 {
313         TRACE("(%p)\n", lpmal);
314         return CoGetMalloc(MEMCTX_TASK, lpmal);
315 }
316
317 /*************************************************************************
318  * SHAlloc                                      [SHELL32.196]
319  *
320  * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
321  * the shell32 built-in "mini-COM" without the need to load ole32.dll -
322  * see SHLoadOLE for details. 
323  *
324  * NOTES
325  *     exported by ordinal
326  *
327  * SEE ALSO
328  *     CoTaskMemAlloc, SHLoadOLE
329  */
330 LPVOID WINAPI SHAlloc(DWORD len)
331 {
332         LPVOID ret;
333
334         ret = CoTaskMemAlloc(len);
335         TRACE("%u bytes at %p\n",len, ret);
336         return ret;
337 }
338
339 /*************************************************************************
340  * SHFree                                       [SHELL32.195]
341  *
342  * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
343  * the shell32 built-in "mini-COM" without the need to load ole32.dll -
344  * see SHLoadOLE for details. 
345  *
346  * NOTES
347  *     exported by ordinal
348  *
349  * SEE ALSO
350  *     CoTaskMemFree, SHLoadOLE
351  */
352 void WINAPI SHFree(LPVOID pv)
353 {
354         TRACE("%p\n",pv);
355         CoTaskMemFree(pv);
356 }
357
358 /*************************************************************************
359  * SHGetDesktopFolder                   [SHELL32.@]
360  */
361 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
362 {
363         HRESULT hres = S_OK;
364         TRACE("\n");
365
366         if(!psf) return E_INVALIDARG;
367         *psf = NULL;
368         hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder,(LPVOID*)psf);
369
370         TRACE("-- %p->(%p)\n",psf, *psf);
371         return hres;
372 }
373 /**************************************************************************
374  * Default ClassFactory Implementation
375  *
376  * SHCreateDefClassObject
377  *
378  * NOTES
379  *  Helper function for dlls without their own classfactory.
380  *  A generic classfactory is returned.
381  *  When the CreateInstance of the cf is called the callback is executed.
382  */
383
384 typedef struct
385 {
386     const IClassFactoryVtbl    *lpVtbl;
387     LONG                        ref;
388     CLSID                       *rclsid;
389     LPFNCREATEINSTANCE          lpfnCI;
390     const IID *                 riidInst;
391     LONG *                      pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
392 } IDefClFImpl;
393
394 static const IClassFactoryVtbl dclfvt;
395
396 /**************************************************************************
397  *  IDefClF_fnConstructor
398  */
399
400 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
401 {
402         IDefClFImpl* lpclf;
403
404         lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
405         lpclf->ref = 1;
406         lpclf->lpVtbl = &dclfvt;
407         lpclf->lpfnCI = lpfnCI;
408         lpclf->pcRefDll = pcRefDll;
409
410         if (pcRefDll) InterlockedIncrement(pcRefDll);
411         lpclf->riidInst = riidInst;
412
413         TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
414         return (LPCLASSFACTORY)lpclf;
415 }
416 /**************************************************************************
417  *  IDefClF_fnQueryInterface
418  */
419 static HRESULT WINAPI IDefClF_fnQueryInterface(
420   LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
421 {
422         IDefClFImpl *This = (IDefClFImpl *)iface;
423
424         TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
425
426         *ppvObj = NULL;
427
428         if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
429           *ppvObj = This;
430           InterlockedIncrement(&This->ref);
431           return S_OK;
432         }
433
434         TRACE("-- E_NOINTERFACE\n");
435         return E_NOINTERFACE;
436 }
437 /******************************************************************************
438  * IDefClF_fnAddRef
439  */
440 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
441 {
442         IDefClFImpl *This = (IDefClFImpl *)iface;
443         ULONG refCount = InterlockedIncrement(&This->ref);
444
445         TRACE("(%p)->(count=%u)\n", This, refCount - 1);
446
447         return refCount;
448 }
449 /******************************************************************************
450  * IDefClF_fnRelease
451  */
452 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
453 {
454         IDefClFImpl *This = (IDefClFImpl *)iface;
455         ULONG refCount = InterlockedDecrement(&This->ref);
456         
457         TRACE("(%p)->(count=%u)\n", This, refCount + 1);
458
459         if (!refCount)
460         {
461           if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
462
463           TRACE("-- destroying IClassFactory(%p)\n",This);
464           HeapFree(GetProcessHeap(),0,This);
465           return 0;
466         }
467         return refCount;
468 }
469 /******************************************************************************
470  * IDefClF_fnCreateInstance
471  */
472 static HRESULT WINAPI IDefClF_fnCreateInstance(
473   LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
474 {
475         IDefClFImpl *This = (IDefClFImpl *)iface;
476
477         TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
478
479         *ppvObject = NULL;
480
481         if ( This->riidInst==NULL ||
482              IsEqualCLSID(riid, This->riidInst) ||
483              IsEqualCLSID(riid, &IID_IUnknown) )
484         {
485           return This->lpfnCI(pUnkOuter, riid, ppvObject);
486         }
487
488         ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
489         return E_NOINTERFACE;
490 }
491 /******************************************************************************
492  * IDefClF_fnLockServer
493  */
494 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
495 {
496         IDefClFImpl *This = (IDefClFImpl *)iface;
497         TRACE("%p->(0x%x), not implemented\n",This, fLock);
498         return E_NOTIMPL;
499 }
500
501 static const IClassFactoryVtbl dclfvt =
502 {
503     IDefClF_fnQueryInterface,
504     IDefClF_fnAddRef,
505   IDefClF_fnRelease,
506   IDefClF_fnCreateInstance,
507   IDefClF_fnLockServer
508 };
509
510 /******************************************************************************
511  * SHCreateDefClassObject                       [SHELL32.70]
512  */
513 HRESULT WINAPI SHCreateDefClassObject(
514         REFIID  riid,
515         LPVOID* ppv,
516         LPFNCREATEINSTANCE lpfnCI,      /* [in] create instance callback entry */
517         LPDWORD pcRefDll,               /* [in/out] ref count of the dll */
518         REFIID  riidInst)               /* [in] optional interface to the instance */
519 {
520         IClassFactory * pcf;
521
522         TRACE("%s %p %p %p %s\n",
523               shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
524
525         if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
526         if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
527         *ppv = pcf;
528         return NOERROR;
529 }
530
531 /*************************************************************************
532  *  DragAcceptFiles             [SHELL32.@]
533  */
534 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
535 {
536         LONG exstyle;
537
538         if( !IsWindow(hWnd) ) return;
539         exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
540         if (b)
541           exstyle |= WS_EX_ACCEPTFILES;
542         else
543           exstyle &= ~WS_EX_ACCEPTFILES;
544         SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
545 }
546
547 /*************************************************************************
548  * DragFinish           [SHELL32.@]
549  */
550 void WINAPI DragFinish(HDROP h)
551 {
552         TRACE("\n");
553         GlobalFree((HGLOBAL)h);
554 }
555
556 /*************************************************************************
557  * DragQueryPoint               [SHELL32.@]
558  */
559 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
560 {
561         DROPFILES *lpDropFileStruct;
562         BOOL bRet;
563
564         TRACE("\n");
565
566         lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
567
568         *p = lpDropFileStruct->pt;
569         bRet = lpDropFileStruct->fNC;
570
571         GlobalUnlock(hDrop);
572         return bRet;
573 }
574
575 /*************************************************************************
576  *  DragQueryFileA              [SHELL32.@]
577  *  DragQueryFile               [SHELL32.@]
578  */
579 UINT WINAPI DragQueryFileA(
580         HDROP hDrop,
581         UINT lFile,
582         LPSTR lpszFile,
583         UINT lLength)
584 {
585         LPSTR lpDrop;
586         UINT i = 0;
587         DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
588
589         TRACE("(%p, %x, %p, %u)\n",     hDrop,lFile,lpszFile,lLength);
590
591         if(!lpDropFileStruct) goto end;
592
593         lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
594
595         if(lpDropFileStruct->fWide) {
596             LPWSTR lpszFileW = NULL;
597
598             if(lpszFile) {
599                 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
600                 if(lpszFileW == NULL) {
601                     goto end;
602                 }
603             }
604             i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
605
606             if(lpszFileW) {
607                 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
608                 HeapFree(GetProcessHeap(), 0, lpszFileW);
609             }
610             goto end;
611         }
612
613         while (i++ < lFile)
614         {
615           while (*lpDrop++); /* skip filename */
616           if (!*lpDrop)
617           {
618             i = (lFile == 0xFFFFFFFF) ? i : 0;
619             goto end;
620           }
621         }
622
623         i = strlen(lpDrop);
624         i++;
625         if (!lpszFile ) goto end;   /* needed buffer size */
626         i = (lLength > i) ? i : lLength;
627         lstrcpynA (lpszFile,  lpDrop,  i);
628 end:
629         GlobalUnlock(hDrop);
630         return i;
631 }
632
633 /*************************************************************************
634  *  DragQueryFileW              [SHELL32.@]
635  */
636 UINT WINAPI DragQueryFileW(
637         HDROP hDrop,
638         UINT lFile,
639         LPWSTR lpszwFile,
640         UINT lLength)
641 {
642         LPWSTR lpwDrop;
643         UINT i = 0;
644         DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
645
646         TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
647
648         if(!lpDropFileStruct) goto end;
649
650         lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
651
652         if(lpDropFileStruct->fWide == FALSE) {
653             LPSTR lpszFileA = NULL;
654
655             if(lpszwFile) {
656                 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
657                 if(lpszFileA == NULL) {
658                     goto end;
659                 }
660             }
661             i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
662
663             if(lpszFileA) {
664                 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
665                 HeapFree(GetProcessHeap(), 0, lpszFileA);
666             }
667             goto end;
668         }
669
670         i = 0;
671         while (i++ < lFile)
672         {
673           while (*lpwDrop++); /* skip filename */
674           if (!*lpwDrop)
675           {
676             i = (lFile == 0xFFFFFFFF) ? i : 0;
677             goto end;
678           }
679         }
680
681         i = strlenW(lpwDrop);
682         i++;
683         if ( !lpszwFile) goto end;   /* needed buffer size */
684
685         i = (lLength > i) ? i : lLength;
686         lstrcpynW (lpszwFile, lpwDrop, i);
687 end:
688         GlobalUnlock(hDrop);
689         return i;
690 }