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