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