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