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