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