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
33 #include "undocshell.h"
34 #include "wine/unicode.h"
35 #include "shell32_main.h"
37 #include "wine/debug.h"
41 #include "wine/obj_dragdrophelper.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
45 extern HRESULT WINAPI
IFSFolder_Constructor(IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppv
);
47 const WCHAR sShell32
[12] = {'S','H','E','L','L','3','2','.','D','L','L','\0'};
48 const WCHAR sOLE32
[10] = {'O','L','E','3','2','.','D','L','L','\0'};
50 HINSTANCE hShellOle32
= 0;
51 /**************************************************************************
52 * Default ClassFactory types
54 typedef HRESULT (CALLBACK
*LPFNCREATEINSTANCE
)(IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppvObject
);
55 IClassFactory
* IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI
, PLONG pcRefDll
, REFIID riidInst
);
57 /* this table contains all CLSID's of shell32 objects */
60 LPFNCREATEINSTANCE lpfnCI
;
61 } InterfaceTable
[6] = {
62 {&CLSID_ShellFSFolder
, &IFSFolder_Constructor
},
63 {&CLSID_MyComputer
, &ISF_MyComputer_Constructor
},
64 {&CLSID_ShellDesktop
, &ISF_Desktop_Constructor
},
65 {&CLSID_ShellLink
, &IShellLink_Constructor
},
66 {&CLSID_DragDropHelper
, &IDropTargetHelper_Constructor
},
70 /*************************************************************************
71 * __CoCreateInstance [internal]
74 * wraper for late bound call to OLE32.DLL
77 HRESULT (WINAPI
*pCoCreateInstance
)(REFCLSID rclsid
, LPUNKNOWN pUnkOuter
, DWORD dwClsContext
, REFIID iid
, LPVOID
*ppv
) = NULL
;
79 void * __GetExternalFunc(HMODULE
* phModule
, LPCWSTR szModuleName
, LPCSTR szProcName
)
81 if (!*phModule
) *phModule
= GetModuleHandleW(szModuleName
);
82 if (!*phModule
) *phModule
= LoadLibraryW(szModuleName
);
83 if (*phModule
) return GetProcAddress(*phModule
, szProcName
);
87 HRESULT
__CoCreateInstance(REFCLSID rclsid
, LPUNKNOWN pUnkOuter
, DWORD dwClsContext
, REFIID iid
, LPVOID
*ppv
)
89 if(!pCoCreateInstance
) pCoCreateInstance
= __GetExternalFunc(&hShellOle32
, sOLE32
, "CoCreateInstance");
90 if(!pCoCreateInstance
) return E_FAIL
;
91 return pCoCreateInstance(rclsid
, pUnkOuter
, dwClsContext
, iid
, ppv
);
94 /*************************************************************************
95 * SHCoCreateInstance [SHELL32.102]
101 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
103 DWORD WINAPI
__SHGUIDToStringW (REFGUID guid
, LPWSTR str
)
105 WCHAR sFormat
[52] = {'{','%','0','8','l','x','-','%','0','4',
106 'x','-','%','0','4','x','-','%','0','2',
107 'x','%','0','2','x','-','%','0','2','x',
108 '%','0','2','x','%','0','2','x','%','0',
109 '2','x','%','0','2','x','%','0','2','x',
112 return wsprintfW ( str
, sFormat
,
113 guid
->Data1
, guid
->Data2
, guid
->Data3
,
114 guid
->Data4
[0], guid
->Data4
[1], guid
->Data4
[2], guid
->Data4
[3],
115 guid
->Data4
[4], guid
->Data4
[5], guid
->Data4
[6], guid
->Data4
[7] );
119 /************************************************************************/
121 LRESULT WINAPI
SHCoCreateInstance(
130 CLSID
* myclsid
= (CLSID
*)clsid
;
131 WCHAR sKeyName
[MAX_PATH
];
132 const WCHAR sCLSID
[7] = {'C','L','S','I','D','\\','\0'};
134 const WCHAR sInProcServer32
[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
135 const WCHAR sLoadWithoutCOM
[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
136 WCHAR sDllPath
[MAX_PATH
];
139 BOOLEAN bLoadFromShell32
= FALSE
;
140 BOOLEAN bLoadWithoutCOM
= FALSE
;
141 IClassFactory
* pcf
= NULL
;
143 if(!ppv
) return E_POINTER
;
146 /* if the clsid is a string, convert it */
149 if (!aclsid
) return REGDB_E_CLASSNOTREG
;
150 SHCLSIDFromStringA(aclsid
, &iid
);
154 TRACE("(%p,%s,unk:%p,%s,%p)\n",
155 aclsid
,shdebugstr_guid(myclsid
),pUnkOuter
,shdebugstr_guid(refiid
),ppv
);
157 /* we look up the dll path in the registry */
158 __SHGUIDToStringW(myclsid
, sClassID
);
159 lstrcpyW(sKeyName
, sCLSID
);
160 lstrcatW(sKeyName
, sClassID
);
161 lstrcatW(sKeyName
, sInProcServer32
);
163 if (ERROR_SUCCESS
== RegOpenKeyExW(HKEY_CLASSES_ROOT
, sKeyName
, 0, KEY_READ
, &hKey
)) {
164 dwSize
= sizeof(sDllPath
);
165 SHQueryValueExW(hKey
, NULL
, 0,0, sDllPath
, &dwSize
);
167 /* if a special registry key is set, we load a shell extension without help of OLE32 */
168 bLoadWithoutCOM
= (ERROR_SUCCESS
== SHQueryValueExW(hKey
, sLoadWithoutCOM
, 0, 0, 0, 0));
170 /* if the com object is inside shell32, omit use of ole32 */
171 bLoadFromShell32
= (0==lstrcmpiW( PathFindFileNameW(sDllPath
), sShell32
));
175 /* since we can't find it in the registry we try internally */
176 bLoadFromShell32
= TRUE
;
179 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM
, bLoadFromShell32
);
181 /* now we create a instance */
182 if (bLoadFromShell32
) {
183 if (! SUCCEEDED(SHELL32_DllGetClassObject(myclsid
, &IID_IClassFactory
,(LPVOID
*)&pcf
))) {
184 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid
));
186 } else if (bLoadWithoutCOM
) {
188 /* load a external dll without ole32 */
190 typedef HRESULT (CALLBACK
*DllGetClassObjectFunc
)(REFCLSID clsid
, REFIID iid
, LPVOID
*ppv
);
191 DllGetClassObjectFunc DllGetClassObject
;
193 if ((hLibrary
= LoadLibraryExW(sDllPath
, 0, LOAD_WITH_ALTERED_SEARCH_PATH
)) == 0) {
194 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath
));
195 hres
= E_ACCESSDENIED
;
197 } else if (!(DllGetClassObject
= (DllGetClassObjectFunc
)GetProcAddress(hLibrary
, "DllGetClassObject"))) {
198 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath
));
199 FreeLibrary( hLibrary
);
200 hres
= E_ACCESSDENIED
;
202 } else if (! SUCCEEDED(hres
= DllGetClassObject(myclsid
, &IID_IClassFactory
, (LPVOID
*)&pcf
))) {
203 TRACE("GetClassObject failed 0x%08lx\n", hres
);
209 /* load a external dll in the usual way */
210 hres
= __CoCreateInstance(myclsid
, pUnkOuter
, CLSCTX_INPROC_SERVER
, refiid
, ppv
);
214 /* here we should have a ClassFactory */
215 if (!pcf
) return E_ACCESSDENIED
;
217 hres
= IClassFactory_CreateInstance(pcf
, pUnkOuter
, refiid
, ppv
);
218 IClassFactory_Release(pcf
);
222 ERR("failed (0x%08lx) to create CLSID:%s IID:%s\n",
223 hres
, shdebugstr_guid(myclsid
), shdebugstr_guid(refiid
));
224 ERR("class not found in registry\n");
227 TRACE("-- instance: %p\n",*ppv
);
231 /*************************************************************************
232 * DllGetClassObject [SHELL32.128]
234 HRESULT WINAPI
SHELL32_DllGetClassObject(REFCLSID rclsid
, REFIID iid
, LPVOID
*ppv
)
236 HRESULT hres
= E_OUTOFMEMORY
;
237 IClassFactory
* pcf
= NULL
;
240 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid
),shdebugstr_guid(iid
));
242 if (!ppv
) return E_INVALIDARG
;
245 /* search our internal interface table */
246 for(i
=0;InterfaceTable
[i
].riid
;i
++) {
247 if(IsEqualIID(InterfaceTable
[i
].riid
, rclsid
)) {
248 TRACE("index[%u]\n", i
);
249 pcf
= IDefClF_fnConstructor(InterfaceTable
[i
].lpfnCI
, NULL
, NULL
);
254 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid
));
255 return CLASS_E_CLASSNOTAVAILABLE
;
258 hres
= IClassFactory_QueryInterface(pcf
, iid
, ppv
);
259 IClassFactory_Release(pcf
);
261 TRACE("-- pointer to class factory: %p\n",*ppv
);
265 /*************************************************************************
266 * SHCLSIDFromString [SHELL32.147]
269 * exported by ordinal
271 DWORD WINAPI
SHCLSIDFromStringA (LPCSTR clsid
, CLSID
*id
)
274 TRACE("(%p(%s) %p)\n", clsid
, clsid
, id
);
275 if (!MultiByteToWideChar( CP_ACP
, 0, clsid
, -1, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
276 return CO_E_CLASSSTRING
;
277 return CLSIDFromString( buffer
, id
);
279 DWORD WINAPI
SHCLSIDFromStringW (LPWSTR clsid
, CLSID
*id
)
281 TRACE("(%p(%s) %p)\n", clsid
, debugstr_w(clsid
), id
);
282 return CLSIDFromString(clsid
, id
);
284 DWORD WINAPI
SHCLSIDFromStringAW (LPVOID clsid
, CLSID
*id
)
286 if (SHELL_OsIsUnicode())
287 return SHCLSIDFromStringW (clsid
, id
);
288 return SHCLSIDFromStringA (clsid
, id
);
291 /*************************************************************************
292 * Shell Memory Allocator
295 /* set the vtable later */
296 extern ICOM_VTABLE(IMalloc
) VT_Shell_IMalloc32
;
298 /* this is the static object instance */
300 ICOM_VFIELD(IMalloc
);
304 _ShellMalloc Shell_Malloc
= { &VT_Shell_IMalloc32
,1};
306 /* this is the global allocator of shell32 */
307 IMalloc
* ShellTaskAllocator
= NULL
;
309 /******************************************************************************
310 * IShellMalloc_QueryInterface [VTABLE]
312 static HRESULT WINAPI
IShellMalloc_fnQueryInterface(LPMALLOC iface
, REFIID refiid
, LPVOID
*obj
)
314 TRACE("(%s,%p)\n",shdebugstr_guid(refiid
),obj
);
315 if (IsEqualIID(refiid
, &IID_IUnknown
) || IsEqualIID(refiid
, &IID_IMalloc
)) {
316 *obj
= (LPMALLOC
) &Shell_Malloc
;
319 return E_NOINTERFACE
;
322 /******************************************************************************
323 * IShellMalloc_AddRefRelease [VTABLE]
325 static ULONG WINAPI
IShellMalloc_fnAddRefRelease(LPMALLOC iface
)
330 /******************************************************************************
331 * IShellMalloc_Alloc [VTABLE]
333 static LPVOID WINAPI
IShellMalloc_fnAlloc(LPMALLOC iface
, DWORD cb
)
337 addr
= (LPVOID
) LocalAlloc(GMEM_ZEROINIT
, cb
);
338 TRACE("(%p,%ld);\n",addr
,cb
);
342 /******************************************************************************
343 * IShellMalloc_Realloc [VTABLE]
345 static LPVOID WINAPI
IShellMalloc_fnRealloc(LPMALLOC iface
, LPVOID pv
, DWORD cb
)
351 addr
= (LPVOID
) LocalReAlloc((HANDLE
) pv
, cb
, GMEM_ZEROINIT
| GMEM_MOVEABLE
);
353 LocalFree((HANDLE
) pv
);
358 addr
= (LPVOID
) LocalAlloc(GMEM_ZEROINIT
, cb
);
364 TRACE("(%p->%p,%ld)\n",pv
,addr
,cb
);
368 /******************************************************************************
369 * IShellMalloc_Free [VTABLE]
371 static VOID WINAPI
IShellMalloc_fnFree(LPMALLOC iface
, LPVOID pv
)
374 LocalFree((HANDLE
) pv
);
377 /******************************************************************************
378 * IShellMalloc_GetSize [VTABLE]
380 static DWORD WINAPI
IShellMalloc_fnGetSize(LPMALLOC iface
, LPVOID pv
)
382 DWORD cb
= (DWORD
) LocalSize((HANDLE
)pv
);
383 TRACE("(%p,%ld)\n", pv
, cb
);
387 /******************************************************************************
388 * IShellMalloc_DidAlloc [VTABLE]
390 static INT WINAPI
IShellMalloc_fnDidAlloc(LPMALLOC iface
, LPVOID pv
)
396 /******************************************************************************
397 * IShellMalloc_HeapMinimize [VTABLE]
399 static VOID WINAPI
IShellMalloc_fnHeapMinimize(LPMALLOC iface
)
404 static ICOM_VTABLE(IMalloc
) VT_Shell_IMalloc32
=
406 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
407 IShellMalloc_fnQueryInterface
,
408 IShellMalloc_fnAddRefRelease
,
409 IShellMalloc_fnAddRefRelease
,
410 IShellMalloc_fnAlloc
,
411 IShellMalloc_fnRealloc
,
413 IShellMalloc_fnGetSize
,
414 IShellMalloc_fnDidAlloc
,
415 IShellMalloc_fnHeapMinimize
418 /*************************************************************************
419 * SHGetMalloc [SHELL32.@]
421 * Return the shell IMalloc interface.
424 * lpmal [O] Destination for IMalloc interface.
427 * Success: S_OK. lpmal contains the shells IMalloc interface.
428 * Failure. An HRESULT error code.
431 * This function will use CoGetMalloc() if OLE32.DLL is already loaded.
432 * If not it uses an internal implementation as a fallback.
434 HRESULT WINAPI
SHGetMalloc(LPMALLOC
*lpmal
)
436 HRESULT (WINAPI
*pCoGetMalloc
)(DWORD
,LPMALLOC
*);
439 TRACE("(%p)\n", lpmal
);
441 if (!ShellTaskAllocator
)
443 hOle32
= GetModuleHandleA("OLE32.DLL");
445 pCoGetMalloc
= (void*) GetProcAddress(hOle32
, "CoGetMalloc");
446 if (pCoGetMalloc
) pCoGetMalloc(MEMCTX_TASK
, &ShellTaskAllocator
);
447 TRACE("got ole32 IMalloc\n");
449 if(!ShellTaskAllocator
) {
450 ShellTaskAllocator
= (IMalloc
* ) &Shell_Malloc
;
451 TRACE("use fallback allocator\n");
454 *lpmal
= ShellTaskAllocator
;
458 /*************************************************************************
459 * SHAlloc [SHELL32.196]
462 * exported by ordinal
464 LPVOID WINAPI
SHAlloc(DWORD len
)
469 if (!ShellTaskAllocator
) SHGetMalloc(&ppv
);
471 ret
= (LPVOID
) IMalloc_Alloc(ShellTaskAllocator
, len
);
472 TRACE("%lu bytes at %p\n",len
, ret
);
476 /*************************************************************************
477 * SHFree [SHELL32.195]
480 * exported by ordinal
482 void WINAPI
SHFree(LPVOID pv
)
487 if (!ShellTaskAllocator
) SHGetMalloc(&ppv
);
488 IMalloc_Free(ShellTaskAllocator
, pv
);
491 /*************************************************************************
492 * SHGetDesktopFolder [SHELL32.@]
494 DWORD WINAPI
SHGetDesktopFolder(IShellFolder
**psf
)
499 if(!psf
) return E_INVALIDARG
;
501 hres
= ISF_Desktop_Constructor(NULL
, &IID_IShellFolder
,(LPVOID
*)psf
);
503 TRACE("-- %p->(%p)\n",psf
, *psf
);
506 /**************************************************************************
507 * Default ClassFactory Implementation
509 * SHCreateDefClassObject
512 * helper function for dll's without a own classfactory
513 * a generic classfactory is returned
514 * when the CreateInstance of the cf is called the callback is executed
519 ICOM_VFIELD(IClassFactory
);
522 LPFNCREATEINSTANCE lpfnCI
;
523 const IID
* riidInst
;
524 ULONG
* pcRefDll
; /* pointer to refcounter in external dll (ugrrr...) */
527 static ICOM_VTABLE(IClassFactory
) dclfvt
;
529 /**************************************************************************
530 * IDefClF_fnConstructor
533 IClassFactory
* IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI
, PLONG pcRefDll
, REFIID riidInst
)
537 lpclf
= (IDefClFImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl
));
539 ICOM_VTBL(lpclf
) = &dclfvt
;
540 lpclf
->lpfnCI
= lpfnCI
;
541 lpclf
->pcRefDll
= pcRefDll
;
543 if (pcRefDll
) InterlockedIncrement(pcRefDll
);
544 lpclf
->riidInst
= riidInst
;
546 TRACE("(%p)%s\n",lpclf
, shdebugstr_guid(riidInst
));
547 return (LPCLASSFACTORY
)lpclf
;
549 /**************************************************************************
550 * IDefClF_fnQueryInterface
552 static HRESULT WINAPI
IDefClF_fnQueryInterface(
553 LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppvObj
)
555 ICOM_THIS(IDefClFImpl
,iface
);
557 TRACE("(%p)->(%s)\n",This
,shdebugstr_guid(riid
));
561 if(IsEqualIID(riid
, &IID_IUnknown
) || IsEqualIID(riid
, &IID_IClassFactory
)) {
563 InterlockedIncrement(&This
->ref
);
567 TRACE("-- E_NOINTERFACE\n");
568 return E_NOINTERFACE
;
570 /******************************************************************************
573 static ULONG WINAPI
IDefClF_fnAddRef(LPCLASSFACTORY iface
)
575 ICOM_THIS(IDefClFImpl
,iface
);
576 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
578 return InterlockedIncrement(&This
->ref
);
580 /******************************************************************************
583 static ULONG WINAPI
IDefClF_fnRelease(LPCLASSFACTORY iface
)
585 ICOM_THIS(IDefClFImpl
,iface
);
586 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
588 if (!InterlockedDecrement(&This
->ref
))
590 if (This
->pcRefDll
) InterlockedDecrement(This
->pcRefDll
);
592 TRACE("-- destroying IClassFactory(%p)\n",This
);
593 HeapFree(GetProcessHeap(),0,This
);
598 /******************************************************************************
599 * IDefClF_fnCreateInstance
601 static HRESULT WINAPI
IDefClF_fnCreateInstance(
602 LPCLASSFACTORY iface
, LPUNKNOWN pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
604 ICOM_THIS(IDefClFImpl
,iface
);
606 TRACE("%p->(%p,%s,%p)\n",This
,pUnkOuter
,shdebugstr_guid(riid
),ppvObject
);
610 if ( This
->riidInst
==NULL
||
611 IsEqualCLSID(riid
, This
->riidInst
) ||
612 IsEqualCLSID(riid
, &IID_IUnknown
) )
614 return This
->lpfnCI(pUnkOuter
, riid
, ppvObject
);
617 ERR("unknown IID requested %s\n",shdebugstr_guid(riid
));
618 return E_NOINTERFACE
;
620 /******************************************************************************
621 * IDefClF_fnLockServer
623 static HRESULT WINAPI
IDefClF_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
625 ICOM_THIS(IDefClFImpl
,iface
);
626 TRACE("%p->(0x%x), not implemented\n",This
, fLock
);
630 static ICOM_VTABLE(IClassFactory
) dclfvt
=
632 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
633 IDefClF_fnQueryInterface
,
636 IDefClF_fnCreateInstance
,
640 /******************************************************************************
641 * SHCreateDefClassObject [SHELL32.70]
643 HRESULT WINAPI
SHCreateDefClassObject(
646 LPFNCREATEINSTANCE lpfnCI
, /* [in] create instance callback entry */
647 LPDWORD pcRefDll
, /* [in/out] ref count of the dll */
648 REFIID riidInst
) /* [in] optional interface to the instance */
652 TRACE("%s %p %p %p %s\n",
653 shdebugstr_guid(riid
), ppv
, lpfnCI
, pcRefDll
, shdebugstr_guid(riidInst
));
655 if (! IsEqualCLSID(riid
, &IID_IClassFactory
) ) return E_NOINTERFACE
;
656 if (! (pcf
= IDefClF_fnConstructor(lpfnCI
, pcRefDll
, riidInst
))) return E_OUTOFMEMORY
;
661 /*************************************************************************
662 * DragAcceptFiles [SHELL32.54]
664 void WINAPI
DragAcceptFiles(HWND hWnd
, BOOL b
)
668 if( !IsWindow(hWnd
) ) return;
669 exstyle
= GetWindowLongA(hWnd
,GWL_EXSTYLE
);
671 exstyle
|= WS_EX_ACCEPTFILES
;
673 exstyle
&= ~WS_EX_ACCEPTFILES
;
674 SetWindowLongA(hWnd
,GWL_EXSTYLE
,exstyle
);
677 /*************************************************************************
678 * DragFinish [SHELL32.80]
680 void WINAPI
DragFinish(HDROP h
)
683 GlobalFree((HGLOBAL
)h
);
686 /*************************************************************************
687 * DragQueryPoint [SHELL32.135]
689 BOOL WINAPI
DragQueryPoint(HDROP hDrop
, POINT
*p
)
691 DROPFILES
*lpDropFileStruct
;
696 lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
698 *p
= lpDropFileStruct
->pt
;
699 bRet
= lpDropFileStruct
->fNC
;
705 /*************************************************************************
706 * DragQueryFile [SHELL32.81]
707 * DragQueryFileA [SHELL32.82]
709 UINT WINAPI
DragQueryFileA(
717 DROPFILES
*lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
719 TRACE("(%p, %x, %p, %u)\n", hDrop
,lFile
,lpszFile
,lLength
);
721 if(!lpDropFileStruct
) goto end
;
723 lpDrop
= (LPSTR
) lpDropFileStruct
+ lpDropFileStruct
->pFiles
;
725 if(lpDropFileStruct
->fWide
== TRUE
) {
726 LPWSTR lpszFileW
= NULL
;
729 lpszFileW
= (LPWSTR
) HeapAlloc(GetProcessHeap(), 0, lLength
*sizeof(WCHAR
));
730 if(lpszFileW
== NULL
) {
734 i
= DragQueryFileW(hDrop
, lFile
, lpszFileW
, lLength
);
737 WideCharToMultiByte(CP_ACP
, 0, lpszFileW
, -1, lpszFile
, lLength
, 0, NULL
);
738 HeapFree(GetProcessHeap(), 0, lpszFileW
);
745 while (*lpDrop
++); /* skip filename */
748 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
755 if (!lpszFile
) goto end
; /* needed buffer size */
756 i
= (lLength
> i
) ? i
: lLength
;
757 lstrcpynA (lpszFile
, lpDrop
, i
);
763 /*************************************************************************
764 * DragQueryFileW [SHELL32.133]
766 UINT WINAPI
DragQueryFileW(
774 DROPFILES
*lpDropFileStruct
= (DROPFILES
*) GlobalLock(hDrop
);
776 TRACE("(%p, %x, %p, %u)\n", hDrop
,lFile
,lpszwFile
,lLength
);
778 if(!lpDropFileStruct
) goto end
;
780 lpwDrop
= (LPWSTR
) ((LPSTR
)lpDropFileStruct
+ lpDropFileStruct
->pFiles
);
782 if(lpDropFileStruct
->fWide
== FALSE
) {
783 LPSTR lpszFileA
= NULL
;
786 lpszFileA
= (LPSTR
) HeapAlloc(GetProcessHeap(), 0, lLength
);
787 if(lpszFileA
== NULL
) {
791 i
= DragQueryFileA(hDrop
, lFile
, lpszFileA
, lLength
);
794 MultiByteToWideChar(CP_ACP
, 0, lpszFileA
, -1, lpszwFile
, lLength
);
795 HeapFree(GetProcessHeap(), 0, lpszFileA
);
803 while (*lpwDrop
++); /* skip filename */
806 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
811 i
= strlenW(lpwDrop
);
813 if ( !lpszwFile
) goto end
; /* needed buffer size */
815 i
= (lLength
> i
) ? i
: lLength
;
816 lstrcpynW (lpszwFile
, lpwDrop
, i
);