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