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 * __CoCreateInstance [internal]
79 * wraper for late bound call to OLE32.DLL
82 HRESULT (WINAPI
*pCoCreateInstance
)(REFCLSID rclsid
, LPUNKNOWN pUnkOuter
, DWORD dwClsContext
, REFIID iid
, LPVOID
*ppv
) = NULL
;
84 void * __GetExternalFunc(HMODULE
* phModule
, LPCWSTR szModuleName
, LPCSTR szProcName
)
86 if (!*phModule
) *phModule
= GetModuleHandleW(szModuleName
);
87 if (!*phModule
) *phModule
= LoadLibraryW(szModuleName
);
88 if (*phModule
) return GetProcAddress(*phModule
, szProcName
);
92 HRESULT
__CoCreateInstance(REFCLSID rclsid
, LPUNKNOWN pUnkOuter
, DWORD dwClsContext
, REFIID iid
, LPVOID
*ppv
)
94 if(!pCoCreateInstance
) pCoCreateInstance
= __GetExternalFunc(&hShellOle32
, sOLE32
, "CoCreateInstance");
95 if(!pCoCreateInstance
) return E_FAIL
;
96 return pCoCreateInstance(rclsid
, pUnkOuter
, dwClsContext
, iid
, ppv
);
99 /*************************************************************************
100 * SHCoCreateInstance [SHELL32.102]
103 * exported by ordinal
106 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
108 DWORD WINAPI
__SHGUIDToStringW (REFGUID guid
, LPWSTR str
)
110 WCHAR sFormat
[52] = {'{','%','0','8','l','x','-','%','0','4',
111 'x','-','%','0','4','x','-','%','0','2',
112 'x','%','0','2','x','-','%','0','2','x',
113 '%','0','2','x','%','0','2','x','%','0',
114 '2','x','%','0','2','x','%','0','2','x',
117 return wsprintfW ( str
, sFormat
,
118 guid
->Data1
, guid
->Data2
, guid
->Data3
,
119 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
120 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
124 /************************************************************************/
126 LRESULT WINAPI
SHCoCreateInstance(
135 CLSID
* myclsid
= (CLSID
*)clsid
;
136 WCHAR sKeyName
[MAX_PATH
];
137 const WCHAR sCLSID
[7] = {'C','L','S','I','D','\\','\0'};
139 const WCHAR sInProcServer32
[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
140 const WCHAR sLoadWithoutCOM
[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
141 WCHAR sDllPath
[MAX_PATH
];
144 BOOLEAN bLoadFromShell32
= FALSE
;
145 BOOLEAN bLoadWithoutCOM
= FALSE
;
146 IClassFactory
* pcf
= NULL
;
148 if(!ppv
) return E_POINTER
;
151 /* if the clsid is a string, convert it */
154 if (!aclsid
) return REGDB_E_CLASSNOTREG
;
155 SHCLSIDFromStringW(aclsid
, &iid
);
159 TRACE("(%p,%s,unk:%p,%s,%p)\n",
160 aclsid
,shdebugstr_guid(myclsid
),pUnkOuter
,shdebugstr_guid(refiid
),ppv
);
162 /* we look up the dll path in the registry */
163 __SHGUIDToStringW(myclsid
, sClassID
);
164 lstrcpyW(sKeyName
, sCLSID
);
165 lstrcatW(sKeyName
, sClassID
);
166 lstrcatW(sKeyName
, sInProcServer32
);
168 if (ERROR_SUCCESS
== RegOpenKeyExW(HKEY_CLASSES_ROOT
, sKeyName
, 0, KEY_READ
, &hKey
)) {
169 dwSize
= sizeof(sDllPath
);
170 SHQueryValueExW(hKey
, NULL
, 0,0, sDllPath
, &dwSize
);
172 /* if a special registry key is set, we load a shell extension without help of OLE32 */
173 bLoadWithoutCOM
= (ERROR_SUCCESS
== SHQueryValueExW(hKey
, sLoadWithoutCOM
, 0, 0, 0, 0));
175 /* if the com object is inside shell32, omit use of ole32 */
176 bLoadFromShell32
= (0==lstrcmpiW( PathFindFileNameW(sDllPath
), sShell32
));
180 /* since we can't find it in the registry we try internally */
181 bLoadFromShell32
= TRUE
;
184 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM
, bLoadFromShell32
);
186 /* now we create a instance */
187 if (bLoadFromShell32
) {
188 if (! SUCCEEDED(SHELL32_DllGetClassObject(myclsid
, &IID_IClassFactory
,(LPVOID
*)&pcf
))) {
189 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid
));
191 } else if (bLoadWithoutCOM
) {
193 /* load a external dll without ole32 */
195 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
, REFIID iid
, LPVOID
*ppv
);
196 DllGetClassObjectFunc DllGetClassObject
;
198 if ((hLibrary
= LoadLibraryExW(sDllPath
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
)) == 0) {
199 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath
));
200 hres
= E_ACCESSDENIED
;
202 } else if (!(DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress(hLibrary
, "DllGetClassObject"))) {
203 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath
));
204 FreeLibrary( hLibrary
);
205 hres
= E_ACCESSDENIED
;
207 } else if (! SUCCEEDED(hres
= DllGetClassObject(myclsid
, &IID_IClassFactory
, (LPVOID
*)&pcf
))) {
208 TRACE("GetClassObject failed 0x%08lx\n", hres
);
214 /* load a external dll in the usual way */
215 hres
= __CoCreateInstance(myclsid
, pUnkOuter
, CLSCTX_INPROC_SERVER
, refiid
, ppv
);
219 /* here we should have a ClassFactory */
220 if (!pcf
) return E_ACCESSDENIED
;
222 hres
= IClassFactory_CreateInstance(pcf
, pUnkOuter
, refiid
, ppv
);
223 IClassFactory_Release(pcf
);
227 ERR("failed (0x%08lx) to create CLSID:%s IID:%s\n",
228 hres
, shdebugstr_guid(myclsid
), shdebugstr_guid(refiid
));
229 ERR("class not found in registry\n");
232 TRACE("-- instance: %p\n",*ppv
);
236 /*************************************************************************
237 * DllGetClassObject [SHELL32.128]
239 HRESULT WINAPI
SHELL32_DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
241 HRESULT hres
= E_OUTOFMEMORY
;
242 IClassFactory
* pcf
= NULL
;
245 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid
),shdebugstr_guid(iid
));
247 if (!ppv
) return E_INVALIDARG
;
250 /* search our internal interface table */
251 for(i
=0;InterfaceTable
[i
].riid
;i
++) {
252 if(IsEqualIID(InterfaceTable
[i
].riid
, rclsid
)) {
253 TRACE("index[%u]\n", i
);
254 pcf
= IDefClF_fnConstructor(InterfaceTable
[i
].lpfnCI
, NULL
, NULL
);
259 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid
));
260 return CLASS_E_CLASSNOTAVAILABLE
;
263 hres
= IClassFactory_QueryInterface(pcf
, iid
, ppv
);
264 IClassFactory_Release(pcf
);
266 TRACE("-- pointer to class factory: %p\n",*ppv
);
270 /*************************************************************************
271 * SHCLSIDFromString [SHELL32.147]
274 * exported by ordinal
276 DWORD WINAPI
SHCLSIDFromStringA (LPCSTR clsid
, CLSID
*id
)
279 TRACE("(%p(%s) %p)\n", clsid
, clsid
, id
);
280 if (!MultiByteToWideChar( CP_ACP
, 0, clsid
, -1, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
281 return CO_E_CLASSSTRING
;
282 return CLSIDFromString( buffer
, id
);
284 DWORD WINAPI
SHCLSIDFromStringW (LPCWSTR clsid
, CLSID
*id
)
286 TRACE("(%p(%s) %p)\n", clsid
, debugstr_w(clsid
), id
);
287 return CLSIDFromString((LPWSTR
)clsid
, id
);
289 DWORD WINAPI
SHCLSIDFromStringAW (LPVOID clsid
, CLSID
*id
)
291 if (SHELL_OsIsUnicode())
292 return SHCLSIDFromStringW (clsid
, id
);
293 return SHCLSIDFromStringA (clsid
, id
);
296 /*************************************************************************
297 * Shell Memory Allocator
300 /* set the vtable later */
301 extern ICOM_VTABLE(IMalloc
) VT_Shell_IMalloc32
;
303 /* this is the static object instance */
305 ICOM_VFIELD(IMalloc
);
309 _ShellMalloc Shell_Malloc
= { &VT_Shell_IMalloc32
,1};
311 /* this is the global allocator of shell32 */
312 IMalloc
* ShellTaskAllocator
= NULL
;
314 /******************************************************************************
315 * IShellMalloc_QueryInterface [VTABLE]
317 static HRESULT WINAPI
IShellMalloc_fnQueryInterface(LPMALLOC iface
, REFIID refiid
, LPVOID
*obj
)
319 TRACE("(%s,%p)\n",shdebugstr_guid(refiid
),obj
);
320 if (IsEqualIID(refiid
, &IID_IUnknown
) || IsEqualIID(refiid
, &IID_IMalloc
)) {
321 *obj
= (LPMALLOC
) &Shell_Malloc
;
324 return E_NOINTERFACE
;
327 /******************************************************************************
328 * IShellMalloc_AddRefRelease [VTABLE]
330 static ULONG WINAPI
IShellMalloc_fnAddRefRelease(LPMALLOC iface
)
335 /******************************************************************************
336 * IShellMalloc_Alloc [VTABLE]
338 static LPVOID WINAPI
IShellMalloc_fnAlloc(LPMALLOC iface
, DWORD cb
)
342 addr
= (LPVOID
) LocalAlloc(GMEM_ZEROINIT
, cb
);
343 TRACE("(%p,%ld);\n",addr
,cb
);
347 /******************************************************************************
348 * IShellMalloc_Realloc [VTABLE]
350 static LPVOID WINAPI
IShellMalloc_fnRealloc(LPMALLOC iface
, LPVOID pv
, DWORD cb
)
356 addr
= (LPVOID
) LocalReAlloc((HANDLE
) pv
, cb
, GMEM_ZEROINIT
| GMEM_MOVEABLE
);
358 LocalFree((HANDLE
) pv
);
363 addr
= (LPVOID
) LocalAlloc(GMEM_ZEROINIT
, cb
);
369 TRACE("(%p->%p,%ld)\n",pv
,addr
,cb
);
373 /******************************************************************************
374 * IShellMalloc_Free [VTABLE]
376 static VOID WINAPI
IShellMalloc_fnFree(LPMALLOC iface
, LPVOID pv
)
379 LocalFree((HANDLE
) pv
);
382 /******************************************************************************
383 * IShellMalloc_GetSize [VTABLE]
385 static DWORD WINAPI
IShellMalloc_fnGetSize(LPMALLOC iface
, LPVOID pv
)
387 DWORD cb
= (DWORD
) LocalSize((HANDLE
)pv
);
388 TRACE("(%p,%ld)\n", pv
, cb
);
392 /******************************************************************************
393 * IShellMalloc_DidAlloc [VTABLE]
395 static INT WINAPI
IShellMalloc_fnDidAlloc(LPMALLOC iface
, LPVOID pv
)
401 /******************************************************************************
402 * IShellMalloc_HeapMinimize [VTABLE]
404 static VOID WINAPI
IShellMalloc_fnHeapMinimize(LPMALLOC iface
)
409 static ICOM_VTABLE(IMalloc
) VT_Shell_IMalloc32
=
411 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
412 IShellMalloc_fnQueryInterface
,
413 IShellMalloc_fnAddRefRelease
,
414 IShellMalloc_fnAddRefRelease
,
415 IShellMalloc_fnAlloc
,
416 IShellMalloc_fnRealloc
,
418 IShellMalloc_fnGetSize
,
419 IShellMalloc_fnDidAlloc
,
420 IShellMalloc_fnHeapMinimize
423 /*************************************************************************
424 * SHGetMalloc [SHELL32.@]
426 * Return the shell IMalloc interface.
429 * lpmal [O] Destination for IMalloc interface.
432 * Success: S_OK. lpmal contains the shells IMalloc interface.
433 * Failure. An HRESULT error code.
436 * This function will use CoGetMalloc() if OLE32.DLL is already loaded.
437 * If not it uses an internal implementation as a fallback.
439 HRESULT WINAPI
SHGetMalloc(LPMALLOC
*lpmal
)
441 HRESULT (WINAPI
*pCoGetMalloc
)(DWORD
,LPMALLOC
*);
444 TRACE("(%p)\n", lpmal
);
446 if (!ShellTaskAllocator
)
448 hOle32
= GetModuleHandleA("OLE32.DLL");
450 pCoGetMalloc
= (void*) GetProcAddress(hOle32
, "CoGetMalloc");
451 if (pCoGetMalloc
) pCoGetMalloc(MEMCTX_TASK
, &ShellTaskAllocator
);
452 TRACE("got ole32 IMalloc\n");
454 if(!ShellTaskAllocator
) {
455 ShellTaskAllocator
= (IMalloc
* ) &Shell_Malloc
;
456 TRACE("use fallback allocator\n");
459 *lpmal
= ShellTaskAllocator
;
463 /*************************************************************************
464 * SHAlloc [SHELL32.196]
467 * exported by ordinal
469 LPVOID WINAPI
SHAlloc(DWORD len
)
474 if (!ShellTaskAllocator
) SHGetMalloc(&ppv
);
476 ret
= (LPVOID
) IMalloc_Alloc(ShellTaskAllocator
, len
);
477 TRACE("%lu bytes at %p\n",len
, ret
);
481 /*************************************************************************
482 * SHFree [SHELL32.195]
485 * exported by ordinal
487 void WINAPI
SHFree(LPVOID pv
)
492 if (!ShellTaskAllocator
) SHGetMalloc(&ppv
);
493 IMalloc_Free(ShellTaskAllocator
, pv
);
496 /*************************************************************************
497 * SHGetDesktopFolder [SHELL32.@]
499 DWORD WINAPI
SHGetDesktopFolder(IShellFolder
**psf
)
504 if(!psf
) return E_INVALIDARG
;
506 hres
= ISF_Desktop_Constructor(NULL
, &IID_IShellFolder
,(LPVOID
*)psf
);
508 TRACE("-- %p->(%p)\n",psf
, *psf
);
511 /**************************************************************************
512 * Default ClassFactory Implementation
514 * SHCreateDefClassObject
517 * helper function for dll's without a own classfactory
518 * a generic classfactory is returned
519 * when the CreateInstance of the cf is called the callback is executed
524 ICOM_VFIELD(IClassFactory
);
527 LPFNCREATEINSTANCE lpfnCI
;
528 const IID
* riidInst
;
529 ULONG
* pcRefDll
; /* pointer to refcounter in external dll (ugrrr...) */
532 static ICOM_VTABLE(IClassFactory
) dclfvt
;
534 /**************************************************************************
535 * IDefClF_fnConstructor
538 IClassFactory
* IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI
, PLONG pcRefDll
, REFIID riidInst
)
542 lpclf
= (IDefClFImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl
));
544 lpclf
->lpVtbl
= &dclfvt
;
545 lpclf
->lpfnCI
= lpfnCI
;
546 lpclf
->pcRefDll
= pcRefDll
;
548 if (pcRefDll
) InterlockedIncrement(pcRefDll
);
549 lpclf
->riidInst
= riidInst
;
551 TRACE("(%p)%s\n",lpclf
, shdebugstr_guid(riidInst
));
552 return (LPCLASSFACTORY
)lpclf
;
554 /**************************************************************************
555 * IDefClF_fnQueryInterface
557 static HRESULT WINAPI
IDefClF_fnQueryInterface(
558 LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppvObj
)
560 ICOM_THIS(IDefClFImpl
,iface
);
562 TRACE("(%p)->(%s)\n",This
,shdebugstr_guid(riid
));
566 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
)) {
568 InterlockedIncrement(&This
->ref
);
572 TRACE("-- E_NOINTERFACE\n");
573 return E_NOINTERFACE
;
575 /******************************************************************************
578 static ULONG WINAPI
IDefClF_fnAddRef(LPCLASSFACTORY iface
)
580 ICOM_THIS(IDefClFImpl
,iface
);
581 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
583 return InterlockedIncrement(&This
->ref
);
585 /******************************************************************************
588 static ULONG WINAPI
IDefClF_fnRelease(LPCLASSFACTORY iface
)
590 ICOM_THIS(IDefClFImpl
,iface
);
591 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
593 if (!InterlockedDecrement(&This
->ref
))
595 if (This
->pcRefDll
) InterlockedDecrement(This
->pcRefDll
);
597 TRACE("-- destroying IClassFactory(%p)\n",This
);
598 HeapFree(GetProcessHeap(),0,This
);
603 /******************************************************************************
604 * IDefClF_fnCreateInstance
606 static HRESULT WINAPI
IDefClF_fnCreateInstance(
607 LPCLASSFACTORY iface
, LPUNKNOWN pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
609 ICOM_THIS(IDefClFImpl
,iface
);
611 TRACE("%p->(%p,%s,%p)\n",This
,pUnkOuter
,shdebugstr_guid(riid
),ppvObject
);
615 if ( This
->riidInst
==NULL
||
616 IsEqualCLSID(riid
, This
->riidInst
) ||
617 IsEqualCLSID(riid
, &IID_IUnknown
) )
619 return This
->lpfnCI(pUnkOuter
, riid
, ppvObject
);
622 ERR("unknown IID requested %s\n",shdebugstr_guid(riid
));
623 return E_NOINTERFACE
;
625 /******************************************************************************
626 * IDefClF_fnLockServer
628 static HRESULT WINAPI
IDefClF_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
630 ICOM_THIS(IDefClFImpl
,iface
);
631 TRACE("%p->(0x%x), not implemented\n",This
, fLock
);
635 static ICOM_VTABLE(IClassFactory
) dclfvt
=
637 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
638 IDefClF_fnQueryInterface
,
641 IDefClF_fnCreateInstance
,
645 /******************************************************************************
646 * SHCreateDefClassObject [SHELL32.70]
648 HRESULT WINAPI
SHCreateDefClassObject(
651 LPFNCREATEINSTANCE lpfnCI
, /* [in] create instance callback entry */
652 LPDWORD pcRefDll
, /* [in/out] ref count of the dll */
653 REFIID riidInst
) /* [in] optional interface to the instance */
657 TRACE("%s %p %p %p %s\n",
658 shdebugstr_guid(riid
), ppv
, lpfnCI
, pcRefDll
, shdebugstr_guid(riidInst
));
660 if (! IsEqualCLSID(riid
, &IID_IClassFactory
) ) return E_NOINTERFACE
;
661 if (! (pcf
= IDefClF_fnConstructor(lpfnCI
, pcRefDll
, riidInst
))) return E_OUTOFMEMORY
;
666 /*************************************************************************
667 * DragAcceptFiles [SHELL32.54]
669 void WINAPI
DragAcceptFiles(HWND hWnd
, BOOL b
)
673 if( !IsWindow(hWnd
) ) return;
674 exstyle
= GetWindowLongA(hWnd
,GWL_EXSTYLE
);
676 exstyle
|= WS_EX_ACCEPTFILES
;
678 exstyle
&= ~WS_EX_ACCEPTFILES
;
679 SetWindowLongA(hWnd
,GWL_EXSTYLE
,exstyle
);
682 /*************************************************************************
683 * DragFinish [SHELL32.80]
685 void WINAPI
DragFinish(HDROP h
)
688 GlobalFree((HGLOBAL
)h
);
691 /*************************************************************************
692 * DragQueryPoint [SHELL32.135]
694 BOOL WINAPI
DragQueryPoint(HDROP hDrop
, POINT
*p
)
696 DROPFILES
*lpDropFileStruct
;
701 lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
703 *p
= lpDropFileStruct
->pt
;
704 bRet
= lpDropFileStruct
->fNC
;
710 /*************************************************************************
711 * DragQueryFile [SHELL32.81]
712 * DragQueryFileA [SHELL32.82]
714 UINT WINAPI
DragQueryFileA(
722 DROPFILES
*lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
724 TRACE("(%p, %x, %p, %u)\n", hDrop
,lFile
,lpszFile
,lLength
);
726 if(!lpDropFileStruct
) goto end
;
728 lpDrop
= (LPSTR
) lpDropFileStruct
+ lpDropFileStruct
->pFiles
;
730 if(lpDropFileStruct
->fWide
== TRUE
) {
731 LPWSTR lpszFileW
= NULL
;
734 lpszFileW
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, lLength
*sizeof(WCHAR
));
735 if(lpszFileW
== NULL
) {
739 i
= DragQueryFileW(hDrop
, lFile
, lpszFileW
, lLength
);
742 WideCharToMultiByte(CP_ACP
, 0, lpszFileW
, -1, lpszFile
, lLength
, 0, NULL
);
743 HeapFree(GetProcessHeap(), 0, lpszFileW
);
750 while (*lpDrop
++); /* skip filename */
753 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
760 if (!lpszFile
) goto end
; /* needed buffer size */
761 i
= (lLength
> i
) ? i
: lLength
;
762 lstrcpynA (lpszFile
, lpDrop
, i
);
768 /*************************************************************************
769 * DragQueryFileW [SHELL32.133]
771 UINT WINAPI
DragQueryFileW(
779 DROPFILES
*lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
781 TRACE("(%p, %x, %p, %u)\n", hDrop
,lFile
,lpszwFile
,lLength
);
783 if(!lpDropFileStruct
) goto end
;
785 lpwDrop
= (LPWSTR
) ((LPSTR
)lpDropFileStruct
+ lpDropFileStruct
->pFiles
);
787 if(lpDropFileStruct
->fWide
== FALSE
) {
788 LPSTR lpszFileA
= NULL
;
791 lpszFileA
= (LPSTR
) HeapAlloc(GetProcessHeap(), 0, lLength
);
792 if(lpszFileA
== NULL
) {
796 i
= DragQueryFileA(hDrop
, lFile
, lpszFileA
, lLength
);
799 MultiByteToWideChar(CP_ACP
, 0, lpszFileA
, -1, lpszwFile
, lLength
);
800 HeapFree(GetProcessHeap(), 0, lpszFileA
);
808 while (*lpwDrop
++); /* skip filename */
811 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
816 i
= strlenW(lpwDrop
);
818 if ( !lpszwFile
) goto end
; /* needed buffer size */
820 i
= (lLength
> i
) ? i
: lLength
;
821 lstrcpynW (lpszwFile
, lpwDrop
, i
);