2 * handling of SHELL32.DLL OLE-Objects
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include "undocshell.h"
39 #include "wine/unicode.h"
40 #include "shell32_main.h"
42 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
48 extern HRESULT WINAPI
IFSFolder_Constructor(IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
);
50 const WCHAR sShell32
[12] = {'S','H','E','L','L','3','2','.','D','L','L','\0'};
51 const WCHAR sOLE32
[10] = {'O','L','E','3','2','.','D','L','L','\0'};
53 HINSTANCE hShellOle32
= 0;
54 /**************************************************************************
55 * Default ClassFactory types
57 typedef HRESULT (CALLBACK
*LPFNCREATEINSTANCE
)(IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppvObject
);
58 IClassFactory
* IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI
, PLONG pcRefDll
, REFIID riidInst
);
60 /* this table contains all CLSID's of shell32 objects */
63 LPFNCREATEINSTANCE lpfnCI
;
64 } InterfaceTable
[] = {
65 {&CLSID_ShellFSFolder
, &IFSFolder_Constructor
},
66 {&CLSID_MyComputer
, &ISF_MyComputer_Constructor
},
67 {&CLSID_ShellDesktop
, &ISF_Desktop_Constructor
},
68 {&CLSID_ShellLink
, &IShellLink_Constructor
},
69 {&CLSID_DragDropHelper
, &IDropTargetHelper_Constructor
},
70 {&CLSID_ControlPanel
, &IControlPanel_Constructor
},
71 {&CLSID_AutoComplete
, &IAutoComplete_Constructor
},
75 /*************************************************************************
76 * SHCoCreateInstance [SHELL32.102]
82 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
84 DWORD WINAPI
__SHGUIDToStringW (REFGUID guid
, LPWSTR str
)
86 WCHAR sFormat
[52] = {'{','%','0','8','l','x','-','%','0','4',
87 'x','-','%','0','4','x','-','%','0','2',
88 'x','%','0','2','x','-','%','0','2','x',
89 '%','0','2','x','%','0','2','x','%','0',
90 '2','x','%','0','2','x','%','0','2','x',
93 return wsprintfW ( str
, sFormat
,
94 guid
->Data1
, guid
->Data2
, guid
->Data3
,
95 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
96 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
100 /************************************************************************/
102 LRESULT WINAPI
SHCoCreateInstance(
111 CLSID
* myclsid
= (CLSID
*)clsid
;
112 WCHAR sKeyName
[MAX_PATH
];
113 const WCHAR sCLSID
[7] = {'C','L','S','I','D','\\','\0'};
115 const WCHAR sInProcServer32
[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
116 const WCHAR sLoadWithoutCOM
[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
117 WCHAR sDllPath
[MAX_PATH
];
120 BOOLEAN bLoadFromShell32
= FALSE
;
121 BOOLEAN bLoadWithoutCOM
= FALSE
;
122 IClassFactory
* pcf
= NULL
;
124 if(!ppv
) return E_POINTER
;
127 /* if the clsid is a string, convert it */
130 if (!aclsid
) return REGDB_E_CLASSNOTREG
;
131 SHCLSIDFromStringW(aclsid
, &iid
);
135 TRACE("(%p,%s,unk:%p,%s,%p)\n",
136 aclsid
,shdebugstr_guid(myclsid
),pUnkOuter
,shdebugstr_guid(refiid
),ppv
);
138 /* we look up the dll path in the registry */
139 __SHGUIDToStringW(myclsid
, sClassID
);
140 lstrcpyW(sKeyName
, sCLSID
);
141 lstrcatW(sKeyName
, sClassID
);
142 lstrcatW(sKeyName
, sInProcServer32
);
144 if (ERROR_SUCCESS
== RegOpenKeyExW(HKEY_CLASSES_ROOT
, sKeyName
, 0, KEY_READ
, &hKey
)) {
145 dwSize
= sizeof(sDllPath
);
146 SHQueryValueExW(hKey
, NULL
, 0,0, sDllPath
, &dwSize
);
148 /* if a special registry key is set, we load a shell extension without help of OLE32 */
149 bLoadWithoutCOM
= (ERROR_SUCCESS
== SHQueryValueExW(hKey
, sLoadWithoutCOM
, 0, 0, 0, 0));
151 /* if the com object is inside shell32, omit use of ole32 */
152 bLoadFromShell32
= (0==lstrcmpiW( PathFindFileNameW(sDllPath
), sShell32
));
156 /* since we can't find it in the registry we try internally */
157 bLoadFromShell32
= TRUE
;
160 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM
, bLoadFromShell32
);
162 /* now we create a instance */
163 if (bLoadFromShell32
) {
164 if (! SUCCEEDED(SHELL32_DllGetClassObject(myclsid
, &IID_IClassFactory
,(LPVOID
*)&pcf
))) {
165 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid
));
167 } else if (bLoadWithoutCOM
) {
169 /* load a external dll without ole32 */
171 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
, REFIID iid
, LPVOID
*ppv
);
172 DllGetClassObjectFunc DllGetClassObject
;
174 if ((hLibrary
= LoadLibraryExW(sDllPath
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
)) == 0) {
175 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath
));
176 hres
= E_ACCESSDENIED
;
178 } else if (!(DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress(hLibrary
, "DllGetClassObject"))) {
179 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath
));
180 FreeLibrary( hLibrary
);
181 hres
= E_ACCESSDENIED
;
183 } else if (! SUCCEEDED(hres
= DllGetClassObject(myclsid
, &IID_IClassFactory
, (LPVOID
*)&pcf
))) {
184 TRACE("GetClassObject failed 0x%08lx\n", hres
);
190 /* load a external dll in the usual way */
191 hres
= CoCreateInstance(myclsid
, pUnkOuter
, CLSCTX_INPROC_SERVER
, refiid
, ppv
);
195 /* here we should have a ClassFactory */
196 if (!pcf
) return E_ACCESSDENIED
;
198 hres
= IClassFactory_CreateInstance(pcf
, pUnkOuter
, refiid
, ppv
);
199 IClassFactory_Release(pcf
);
203 ERR("failed (0x%08lx) to create CLSID:%s IID:%s\n",
204 hres
, shdebugstr_guid(myclsid
), shdebugstr_guid(refiid
));
205 ERR("class not found in registry\n");
208 TRACE("-- instance: %p\n",*ppv
);
212 /*************************************************************************
213 * DllGetClassObject [SHELL32.128]
215 HRESULT WINAPI
SHELL32_DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
217 HRESULT hres
= E_OUTOFMEMORY
;
218 IClassFactory
* pcf
= NULL
;
221 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid
),shdebugstr_guid(iid
));
223 if (!ppv
) return E_INVALIDARG
;
226 /* search our internal interface table */
227 for(i
=0;InterfaceTable
[i
].riid
;i
++) {
228 if(IsEqualIID(InterfaceTable
[i
].riid
, rclsid
)) {
229 TRACE("index[%u]\n", i
);
230 pcf
= IDefClF_fnConstructor(InterfaceTable
[i
].lpfnCI
, NULL
, NULL
);
235 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid
));
236 return CLASS_E_CLASSNOTAVAILABLE
;
239 hres
= IClassFactory_QueryInterface(pcf
, iid
, ppv
);
240 IClassFactory_Release(pcf
);
242 TRACE("-- pointer to class factory: %p\n",*ppv
);
246 /*************************************************************************
247 * SHCLSIDFromString [SHELL32.147]
250 * exported by ordinal
252 DWORD WINAPI
SHCLSIDFromStringA (LPCSTR clsid
, CLSID
*id
)
255 TRACE("(%p(%s) %p)\n", clsid
, clsid
, id
);
256 if (!MultiByteToWideChar( CP_ACP
, 0, clsid
, -1, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
257 return CO_E_CLASSSTRING
;
258 return CLSIDFromString( buffer
, id
);
260 DWORD WINAPI
SHCLSIDFromStringW (LPCWSTR clsid
, CLSID
*id
)
262 TRACE("(%p(%s) %p)\n", clsid
, debugstr_w(clsid
), id
);
263 return CLSIDFromString((LPWSTR
)clsid
, id
);
265 DWORD WINAPI
SHCLSIDFromStringAW (LPVOID clsid
, CLSID
*id
)
267 if (SHELL_OsIsUnicode())
268 return SHCLSIDFromStringW (clsid
, id
);
269 return SHCLSIDFromStringA (clsid
, id
);
272 /*************************************************************************
273 * Shell Memory Allocator
276 /* set the vtable later */
277 extern ICOM_VTABLE(IMalloc
) VT_Shell_IMalloc32
;
279 /* this is the static object instance */
281 ICOM_VFIELD(IMalloc
);
285 _ShellMalloc Shell_Malloc
= { &VT_Shell_IMalloc32
,1};
287 /* this is the global allocator of shell32 */
288 IMalloc
* ShellTaskAllocator
= NULL
;
290 /******************************************************************************
291 * IShellMalloc_QueryInterface [VTABLE]
293 static HRESULT WINAPI
IShellMalloc_fnQueryInterface(LPMALLOC iface
, REFIID refiid
, LPVOID
*obj
)
295 TRACE("(%s,%p)\n",shdebugstr_guid(refiid
),obj
);
296 if (IsEqualIID(refiid
, &IID_IUnknown
) || IsEqualIID(refiid
, &IID_IMalloc
)) {
297 *obj
= (LPMALLOC
) &Shell_Malloc
;
300 return E_NOINTERFACE
;
303 /******************************************************************************
304 * IShellMalloc_AddRefRelease [VTABLE]
306 static ULONG WINAPI
IShellMalloc_fnAddRefRelease(LPMALLOC iface
)
311 /******************************************************************************
312 * IShellMalloc_Alloc [VTABLE]
314 static LPVOID WINAPI
IShellMalloc_fnAlloc(LPMALLOC iface
, DWORD cb
)
318 addr
= (LPVOID
) LocalAlloc(GMEM_ZEROINIT
, cb
);
319 TRACE("(%p,%ld);\n",addr
,cb
);
323 /******************************************************************************
324 * IShellMalloc_Realloc [VTABLE]
326 static LPVOID WINAPI
IShellMalloc_fnRealloc(LPMALLOC iface
, LPVOID pv
, DWORD cb
)
332 addr
= (LPVOID
) LocalReAlloc((HANDLE
) pv
, cb
, GMEM_ZEROINIT
| GMEM_MOVEABLE
);
334 LocalFree((HANDLE
) pv
);
339 addr
= (LPVOID
) LocalAlloc(GMEM_ZEROINIT
, cb
);
345 TRACE("(%p->%p,%ld)\n",pv
,addr
,cb
);
349 /******************************************************************************
350 * IShellMalloc_Free [VTABLE]
352 static VOID WINAPI
IShellMalloc_fnFree(LPMALLOC iface
, LPVOID pv
)
355 LocalFree((HANDLE
) pv
);
358 /******************************************************************************
359 * IShellMalloc_GetSize [VTABLE]
361 static DWORD WINAPI
IShellMalloc_fnGetSize(LPMALLOC iface
, LPVOID pv
)
363 DWORD cb
= (DWORD
) LocalSize((HANDLE
)pv
);
364 TRACE("(%p,%ld)\n", pv
, cb
);
368 /******************************************************************************
369 * IShellMalloc_DidAlloc [VTABLE]
371 static INT WINAPI
IShellMalloc_fnDidAlloc(LPMALLOC iface
, LPVOID pv
)
377 /******************************************************************************
378 * IShellMalloc_HeapMinimize [VTABLE]
380 static VOID WINAPI
IShellMalloc_fnHeapMinimize(LPMALLOC iface
)
385 static ICOM_VTABLE(IMalloc
) VT_Shell_IMalloc32
=
387 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
388 IShellMalloc_fnQueryInterface
,
389 IShellMalloc_fnAddRefRelease
,
390 IShellMalloc_fnAddRefRelease
,
391 IShellMalloc_fnAlloc
,
392 IShellMalloc_fnRealloc
,
394 IShellMalloc_fnGetSize
,
395 IShellMalloc_fnDidAlloc
,
396 IShellMalloc_fnHeapMinimize
399 /*************************************************************************
400 * SHGetMalloc [SHELL32.@]
402 * Return the shell IMalloc interface.
405 * lpmal [O] Destination for IMalloc interface.
408 * Success: S_OK. lpmal contains the shells IMalloc interface.
409 * Failure. An HRESULT error code.
412 * This function will use CoGetMalloc() if OLE32.DLL is already loaded.
413 * If not it uses an internal implementation as a fallback.
415 HRESULT WINAPI
SHGetMalloc(LPMALLOC
*lpmal
)
417 TRACE("(%p)\n", lpmal
);
419 if (!ShellTaskAllocator
)
421 HMODULE hOle32
= GetModuleHandleA("OLE32.DLL");
422 /* this is very suspect. we should not being using a different
423 * allocator from deallocator based on something undeterministic
424 * like whether ole32 is loaded. as it happens currently, they
425 * both map to the same allocator deep down, but this could
426 * change in the future. */
428 CoGetMalloc(MEMCTX_TASK
, &ShellTaskAllocator
);
429 TRACE("got ole32 IMalloc\n");
431 if(!ShellTaskAllocator
) {
432 ShellTaskAllocator
= (IMalloc
* ) &Shell_Malloc
;
433 TRACE("use fallback allocator\n");
436 *lpmal
= ShellTaskAllocator
;
440 /*************************************************************************
441 * SHAlloc [SHELL32.196]
444 * exported by ordinal
446 LPVOID WINAPI
SHAlloc(DWORD len
)
451 if (!ShellTaskAllocator
) SHGetMalloc(&ppv
);
453 ret
= (LPVOID
) IMalloc_Alloc(ShellTaskAllocator
, len
);
454 TRACE("%lu bytes at %p\n",len
, ret
);
458 /*************************************************************************
459 * SHFree [SHELL32.195]
462 * exported by ordinal
464 void WINAPI
SHFree(LPVOID pv
)
469 if (!ShellTaskAllocator
) SHGetMalloc(&ppv
);
470 IMalloc_Free(ShellTaskAllocator
, pv
);
473 /*************************************************************************
474 * SHGetDesktopFolder [SHELL32.@]
476 DWORD WINAPI
SHGetDesktopFolder(IShellFolder
**psf
)
481 if(!psf
) return E_INVALIDARG
;
483 hres
= ISF_Desktop_Constructor(NULL
, &IID_IShellFolder
,(LPVOID
*)psf
);
485 TRACE("-- %p->(%p)\n",psf
, *psf
);
488 /**************************************************************************
489 * Default ClassFactory Implementation
491 * SHCreateDefClassObject
494 * helper function for dll's without a own classfactory
495 * a generic classfactory is returned
496 * when the CreateInstance of the cf is called the callback is executed
501 ICOM_VFIELD(IClassFactory
);
504 LPFNCREATEINSTANCE lpfnCI
;
505 const IID
* riidInst
;
506 ULONG
* pcRefDll
; /* pointer to refcounter in external dll (ugrrr...) */
509 static ICOM_VTABLE(IClassFactory
) dclfvt
;
511 /**************************************************************************
512 * IDefClF_fnConstructor
515 IClassFactory
* IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI
, PLONG pcRefDll
, REFIID riidInst
)
519 lpclf
= (IDefClFImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl
));
521 lpclf
->lpVtbl
= &dclfvt
;
522 lpclf
->lpfnCI
= lpfnCI
;
523 lpclf
->pcRefDll
= pcRefDll
;
525 if (pcRefDll
) InterlockedIncrement(pcRefDll
);
526 lpclf
->riidInst
= riidInst
;
528 TRACE("(%p)%s\n",lpclf
, shdebugstr_guid(riidInst
));
529 return (LPCLASSFACTORY
)lpclf
;
531 /**************************************************************************
532 * IDefClF_fnQueryInterface
534 static HRESULT WINAPI
IDefClF_fnQueryInterface(
535 LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppvObj
)
537 ICOM_THIS(IDefClFImpl
,iface
);
539 TRACE("(%p)->(%s)\n",This
,shdebugstr_guid(riid
));
543 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
)) {
545 InterlockedIncrement(&This
->ref
);
549 TRACE("-- E_NOINTERFACE\n");
550 return E_NOINTERFACE
;
552 /******************************************************************************
555 static ULONG WINAPI
IDefClF_fnAddRef(LPCLASSFACTORY iface
)
557 ICOM_THIS(IDefClFImpl
,iface
);
558 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
560 return InterlockedIncrement(&This
->ref
);
562 /******************************************************************************
565 static ULONG WINAPI
IDefClF_fnRelease(LPCLASSFACTORY iface
)
567 ICOM_THIS(IDefClFImpl
,iface
);
568 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
570 if (!InterlockedDecrement(&This
->ref
))
572 if (This
->pcRefDll
) InterlockedDecrement(This
->pcRefDll
);
574 TRACE("-- destroying IClassFactory(%p)\n",This
);
575 HeapFree(GetProcessHeap(),0,This
);
580 /******************************************************************************
581 * IDefClF_fnCreateInstance
583 static HRESULT WINAPI
IDefClF_fnCreateInstance(
584 LPCLASSFACTORY iface
, LPUNKNOWN pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
586 ICOM_THIS(IDefClFImpl
,iface
);
588 TRACE("%p->(%p,%s,%p)\n",This
,pUnkOuter
,shdebugstr_guid(riid
),ppvObject
);
592 if ( This
->riidInst
==NULL
||
593 IsEqualCLSID(riid
, This
->riidInst
) ||
594 IsEqualCLSID(riid
, &IID_IUnknown
) )
596 return This
->lpfnCI(pUnkOuter
, riid
, ppvObject
);
599 ERR("unknown IID requested %s\n",shdebugstr_guid(riid
));
600 return E_NOINTERFACE
;
602 /******************************************************************************
603 * IDefClF_fnLockServer
605 static HRESULT WINAPI
IDefClF_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
607 ICOM_THIS(IDefClFImpl
,iface
);
608 TRACE("%p->(0x%x), not implemented\n",This
, fLock
);
612 static ICOM_VTABLE(IClassFactory
) dclfvt
=
614 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
615 IDefClF_fnQueryInterface
,
618 IDefClF_fnCreateInstance
,
622 /******************************************************************************
623 * SHCreateDefClassObject [SHELL32.70]
625 HRESULT WINAPI
SHCreateDefClassObject(
628 LPFNCREATEINSTANCE lpfnCI
, /* [in] create instance callback entry */
629 LPDWORD pcRefDll
, /* [in/out] ref count of the dll */
630 REFIID riidInst
) /* [in] optional interface to the instance */
634 TRACE("%s %p %p %p %s\n",
635 shdebugstr_guid(riid
), ppv
, lpfnCI
, pcRefDll
, shdebugstr_guid(riidInst
));
637 if (! IsEqualCLSID(riid
, &IID_IClassFactory
) ) return E_NOINTERFACE
;
638 if (! (pcf
= IDefClF_fnConstructor(lpfnCI
, pcRefDll
, riidInst
))) return E_OUTOFMEMORY
;
643 /*************************************************************************
644 * DragAcceptFiles [SHELL32.54]
646 void WINAPI
DragAcceptFiles(HWND hWnd
, BOOL b
)
650 if( !IsWindow(hWnd
) ) return;
651 exstyle
= GetWindowLongA(hWnd
,GWL_EXSTYLE
);
653 exstyle
|= WS_EX_ACCEPTFILES
;
655 exstyle
&= ~WS_EX_ACCEPTFILES
;
656 SetWindowLongA(hWnd
,GWL_EXSTYLE
,exstyle
);
659 /*************************************************************************
660 * DragFinish [SHELL32.80]
662 void WINAPI
DragFinish(HDROP h
)
665 GlobalFree((HGLOBAL
)h
);
668 /*************************************************************************
669 * DragQueryPoint [SHELL32.135]
671 BOOL WINAPI
DragQueryPoint(HDROP hDrop
, POINT
*p
)
673 DROPFILES
*lpDropFileStruct
;
678 lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
680 *p
= lpDropFileStruct
->pt
;
681 bRet
= lpDropFileStruct
->fNC
;
687 /*************************************************************************
688 * DragQueryFile [SHELL32.81]
689 * DragQueryFileA [SHELL32.82]
691 UINT WINAPI
DragQueryFileA(
699 DROPFILES
*lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
701 TRACE("(%p, %x, %p, %u)\n", hDrop
,lFile
,lpszFile
,lLength
);
703 if(!lpDropFileStruct
) goto end
;
705 lpDrop
= (LPSTR
) lpDropFileStruct
+ lpDropFileStruct
->pFiles
;
707 if(lpDropFileStruct
->fWide
== TRUE
) {
708 LPWSTR lpszFileW
= NULL
;
711 lpszFileW
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, lLength
*sizeof(WCHAR
));
712 if(lpszFileW
== NULL
) {
716 i
= DragQueryFileW(hDrop
, lFile
, lpszFileW
, lLength
);
719 WideCharToMultiByte(CP_ACP
, 0, lpszFileW
, -1, lpszFile
, lLength
, 0, NULL
);
720 HeapFree(GetProcessHeap(), 0, lpszFileW
);
727 while (*lpDrop
++); /* skip filename */
730 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
737 if (!lpszFile
) goto end
; /* needed buffer size */
738 i
= (lLength
> i
) ? i
: lLength
;
739 lstrcpynA (lpszFile
, lpDrop
, i
);
745 /*************************************************************************
746 * DragQueryFileW [SHELL32.133]
748 UINT WINAPI
DragQueryFileW(
756 DROPFILES
*lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
758 TRACE("(%p, %x, %p, %u)\n", hDrop
,lFile
,lpszwFile
,lLength
);
760 if(!lpDropFileStruct
) goto end
;
762 lpwDrop
= (LPWSTR
) ((LPSTR
)lpDropFileStruct
+ lpDropFileStruct
->pFiles
);
764 if(lpDropFileStruct
->fWide
== FALSE
) {
765 LPSTR lpszFileA
= NULL
;
768 lpszFileA
= (LPSTR
) HeapAlloc(GetProcessHeap(), 0, lLength
);
769 if(lpszFileA
== NULL
) {
773 i
= DragQueryFileA(hDrop
, lFile
, lpszFileA
, lLength
);
776 MultiByteToWideChar(CP_ACP
, 0, lpszFileA
, -1, lpszwFile
, lLength
);
777 HeapFree(GetProcessHeap(), 0, lpszFileA
);
785 while (*lpwDrop
++); /* skip filename */
788 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
793 i
= strlenW(lpwDrop
);
795 if ( !lpszwFile
) goto end
; /* needed buffer size */
797 i
= (lLength
> i
) ? i
: lLength
;
798 lstrcpynW (lpszwFile
, lpwDrop
, i
);