Get rid of the no longer used ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
[wine.git] / dlls / shell32 / shellole.c
bloba4d0ae54a9da4b9158ae47e31aa32a4a3773ea32
1 /*
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
22 #include "config.h"
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "shellapi.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "shlobj.h"
34 #include "shlguid.h"
35 #include "winreg.h"
36 #include "winerror.h"
38 #include "undocshell.h"
39 #include "wine/unicode.h"
40 #include "shell32_main.h"
42 #include "wine/debug.h"
43 #include "shlwapi.h"
44 #include "debughlp.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 */
61 struct {
62 REFIID riid;
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},
72 {NULL,NULL}
75 /*************************************************************************
76 * SHCoCreateInstance [SHELL32.102]
78 * NOTES
79 * exported by ordinal
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',
91 '}','\0'};
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(
103 LPCWSTR aclsid,
104 const CLSID *clsid,
105 LPUNKNOWN pUnkOuter,
106 REFIID refiid,
107 LPVOID *ppv)
109 DWORD hres;
110 IID iid;
111 CLSID * myclsid = (CLSID*)clsid;
112 WCHAR sKeyName[MAX_PATH];
113 const WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
114 WCHAR sClassID[60];
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];
118 HKEY hKey;
119 DWORD dwSize;
120 BOOLEAN bLoadFromShell32 = FALSE;
121 BOOLEAN bLoadWithoutCOM = FALSE;
122 IClassFactory * pcf = NULL;
124 if(!ppv) return E_POINTER;
125 *ppv=NULL;
127 /* if the clsid is a string, convert it */
128 if (!clsid)
130 if (!aclsid) return REGDB_E_CLASSNOTREG;
131 SHCLSIDFromStringW(aclsid, &iid);
132 myclsid = &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));
154 RegCloseKey (hKey);
155 } else {
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 */
170 HANDLE hLibrary;
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;
177 goto end;
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;
182 goto end;
183 } else if (! SUCCEEDED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
184 TRACE("GetClassObject failed 0x%08lx\n", hres);
185 goto end;
188 } else {
190 /* load a external dll in the usual way */
191 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
192 goto end;
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);
200 end:
201 if(hres!=S_OK)
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);
209 return hres;
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;
219 int i;
221 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
223 if (!ppv) return E_INVALIDARG;
224 *ppv = NULL;
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);
234 if (!pcf) {
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);
243 return hres;
246 /*************************************************************************
247 * SHCLSIDFromString [SHELL32.147]
249 * NOTES
250 * exported by ordinal
252 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
254 WCHAR buffer[40];
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 static IMallocVtbl VT_Shell_IMalloc32;
279 /* this is the static object instance */
280 typedef struct {
281 IMallocVtbl *lpVtbl;
282 DWORD dummy;
283 } _ShellMalloc;
285 static _ShellMalloc Shell_Malloc = { &VT_Shell_IMalloc32,1};
287 /* this is the global allocator of shell32 */
288 static 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;
298 return S_OK;
300 return E_NOINTERFACE;
303 /******************************************************************************
304 * IShellMalloc_AddRefRelease [VTABLE]
306 static ULONG WINAPI IShellMalloc_fnAddRefRelease(LPMALLOC iface)
308 return 1;
311 /******************************************************************************
312 * IShellMalloc_Alloc [VTABLE]
314 static LPVOID WINAPI IShellMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
316 LPVOID addr;
318 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
319 TRACE("(%p,%ld);\n",addr,cb);
320 return addr;
323 /******************************************************************************
324 * IShellMalloc_Realloc [VTABLE]
326 static LPVOID WINAPI IShellMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
328 LPVOID addr;
330 if (pv) {
331 if (cb) {
332 addr = (LPVOID) LocalReAlloc((HANDLE) pv, cb, GMEM_ZEROINIT | GMEM_MOVEABLE);
333 } else {
334 LocalFree((HANDLE) pv);
335 addr = NULL;
337 } else {
338 if (cb) {
339 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
340 } else {
341 addr = NULL;
345 TRACE("(%p->%p,%ld)\n",pv,addr,cb);
346 return addr;
349 /******************************************************************************
350 * IShellMalloc_Free [VTABLE]
352 static VOID WINAPI IShellMalloc_fnFree(LPMALLOC iface, LPVOID pv)
354 TRACE("(%p)\n",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);
365 return cb;
368 /******************************************************************************
369 * IShellMalloc_DidAlloc [VTABLE]
371 static INT WINAPI IShellMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
373 TRACE("(%p)\n",pv);
374 return -1;
377 /******************************************************************************
378 * IShellMalloc_HeapMinimize [VTABLE]
380 static VOID WINAPI IShellMalloc_fnHeapMinimize(LPMALLOC iface)
382 TRACE("()\n");
385 static IMallocVtbl VT_Shell_IMalloc32 =
387 IShellMalloc_fnQueryInterface,
388 IShellMalloc_fnAddRefRelease,
389 IShellMalloc_fnAddRefRelease,
390 IShellMalloc_fnAlloc,
391 IShellMalloc_fnRealloc,
392 IShellMalloc_fnFree,
393 IShellMalloc_fnGetSize,
394 IShellMalloc_fnDidAlloc,
395 IShellMalloc_fnHeapMinimize
398 /*************************************************************************
399 * SHGetMalloc [SHELL32.@]
401 * Return the shell IMalloc interface.
403 * PARAMS
404 * lpmal [O] Destination for IMalloc interface.
406 * RETURNS
407 * Success: S_OK. lpmal contains the shells IMalloc interface.
408 * Failure. An HRESULT error code.
410 * NOTES
411 * This function will use CoGetMalloc() if OLE32.DLL is already loaded.
412 * If not it uses an internal implementation as a fallback.
414 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
416 TRACE("(%p)\n", lpmal);
418 if (!ShellTaskAllocator)
420 HMODULE hOle32 = GetModuleHandleA("OLE32.DLL");
421 /* this is very suspect. we should not being using a different
422 * allocator from deallocator based on something undeterministic
423 * like whether ole32 is loaded. as it happens currently, they
424 * both map to the same allocator deep down, but this could
425 * change in the future. */
426 if(hOle32) {
427 CoGetMalloc(MEMCTX_TASK, &ShellTaskAllocator);
428 TRACE("got ole32 IMalloc\n");
430 if(!ShellTaskAllocator) {
431 ShellTaskAllocator = (IMalloc* ) &Shell_Malloc;
432 TRACE("use fallback allocator\n");
435 *lpmal = ShellTaskAllocator;
436 return S_OK;
439 /*************************************************************************
440 * SHAlloc [SHELL32.196]
442 * NOTES
443 * exported by ordinal
445 LPVOID WINAPI SHAlloc(DWORD len)
447 IMalloc * ppv;
448 LPBYTE ret;
450 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
452 ret = (LPVOID) IMalloc_Alloc(ShellTaskAllocator, len);
453 TRACE("%lu bytes at %p\n",len, ret);
454 return (LPVOID)ret;
457 /*************************************************************************
458 * SHFree [SHELL32.195]
460 * NOTES
461 * exported by ordinal
463 void WINAPI SHFree(LPVOID pv)
465 IMalloc * ppv;
467 TRACE("%p\n",pv);
468 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
469 IMalloc_Free(ShellTaskAllocator, pv);
472 /*************************************************************************
473 * SHGetDesktopFolder [SHELL32.@]
475 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
477 HRESULT hres = S_OK;
478 TRACE("\n");
480 if(!psf) return E_INVALIDARG;
481 *psf = NULL;
482 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder,(LPVOID*)psf);
484 TRACE("-- %p->(%p)\n",psf, *psf);
485 return hres;
487 /**************************************************************************
488 * Default ClassFactory Implementation
490 * SHCreateDefClassObject
492 * NOTES
493 * helper function for dll's without a own classfactory
494 * a generic classfactory is returned
495 * when the CreateInstance of the cf is called the callback is executed
498 typedef struct
500 IClassFactoryVtbl *lpVtbl;
501 DWORD ref;
502 CLSID *rclsid;
503 LPFNCREATEINSTANCE lpfnCI;
504 const IID * riidInst;
505 ULONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
506 } IDefClFImpl;
508 static IClassFactoryVtbl dclfvt;
510 /**************************************************************************
511 * IDefClF_fnConstructor
514 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
516 IDefClFImpl* lpclf;
518 lpclf = (IDefClFImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
519 lpclf->ref = 1;
520 lpclf->lpVtbl = &dclfvt;
521 lpclf->lpfnCI = lpfnCI;
522 lpclf->pcRefDll = pcRefDll;
524 if (pcRefDll) InterlockedIncrement(pcRefDll);
525 lpclf->riidInst = riidInst;
527 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
528 return (LPCLASSFACTORY)lpclf;
530 /**************************************************************************
531 * IDefClF_fnQueryInterface
533 static HRESULT WINAPI IDefClF_fnQueryInterface(
534 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
536 ICOM_THIS(IDefClFImpl,iface);
538 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
540 *ppvObj = NULL;
542 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
543 *ppvObj = This;
544 InterlockedIncrement(&This->ref);
545 return S_OK;
548 TRACE("-- E_NOINTERFACE\n");
549 return E_NOINTERFACE;
551 /******************************************************************************
552 * IDefClF_fnAddRef
554 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
556 ICOM_THIS(IDefClFImpl,iface);
557 TRACE("(%p)->(count=%lu)\n",This,This->ref);
559 return InterlockedIncrement(&This->ref);
561 /******************************************************************************
562 * IDefClF_fnRelease
564 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
566 ICOM_THIS(IDefClFImpl,iface);
567 TRACE("(%p)->(count=%lu)\n",This,This->ref);
569 if (!InterlockedDecrement(&This->ref))
571 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
573 TRACE("-- destroying IClassFactory(%p)\n",This);
574 HeapFree(GetProcessHeap(),0,This);
575 return 0;
577 return This->ref;
579 /******************************************************************************
580 * IDefClF_fnCreateInstance
582 static HRESULT WINAPI IDefClF_fnCreateInstance(
583 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
585 ICOM_THIS(IDefClFImpl,iface);
587 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
589 *ppvObject = NULL;
591 if ( This->riidInst==NULL ||
592 IsEqualCLSID(riid, This->riidInst) ||
593 IsEqualCLSID(riid, &IID_IUnknown) )
595 return This->lpfnCI(pUnkOuter, riid, ppvObject);
598 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
599 return E_NOINTERFACE;
601 /******************************************************************************
602 * IDefClF_fnLockServer
604 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
606 ICOM_THIS(IDefClFImpl,iface);
607 TRACE("%p->(0x%x), not implemented\n",This, fLock);
608 return E_NOTIMPL;
611 static IClassFactoryVtbl dclfvt =
613 IDefClF_fnQueryInterface,
614 IDefClF_fnAddRef,
615 IDefClF_fnRelease,
616 IDefClF_fnCreateInstance,
617 IDefClF_fnLockServer
620 /******************************************************************************
621 * SHCreateDefClassObject [SHELL32.70]
623 HRESULT WINAPI SHCreateDefClassObject(
624 REFIID riid,
625 LPVOID* ppv,
626 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
627 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
628 REFIID riidInst) /* [in] optional interface to the instance */
630 IClassFactory * pcf;
632 TRACE("%s %p %p %p %s\n",
633 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
635 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
636 if (! (pcf = IDefClF_fnConstructor(lpfnCI, pcRefDll, riidInst))) return E_OUTOFMEMORY;
637 *ppv = pcf;
638 return NOERROR;
641 /*************************************************************************
642 * DragAcceptFiles [SHELL32.54]
644 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
646 LONG exstyle;
648 if( !IsWindow(hWnd) ) return;
649 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
650 if (b)
651 exstyle |= WS_EX_ACCEPTFILES;
652 else
653 exstyle &= ~WS_EX_ACCEPTFILES;
654 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
657 /*************************************************************************
658 * DragFinish [SHELL32.80]
660 void WINAPI DragFinish(HDROP h)
662 TRACE("\n");
663 GlobalFree((HGLOBAL)h);
666 /*************************************************************************
667 * DragQueryPoint [SHELL32.135]
669 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
671 DROPFILES *lpDropFileStruct;
672 BOOL bRet;
674 TRACE("\n");
676 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
678 *p = lpDropFileStruct->pt;
679 bRet = lpDropFileStruct->fNC;
681 GlobalUnlock(hDrop);
682 return bRet;
685 /*************************************************************************
686 * DragQueryFile [SHELL32.81]
687 * DragQueryFileA [SHELL32.82]
689 UINT WINAPI DragQueryFileA(
690 HDROP hDrop,
691 UINT lFile,
692 LPSTR lpszFile,
693 UINT lLength)
695 LPSTR lpDrop;
696 UINT i = 0;
697 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
699 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
701 if(!lpDropFileStruct) goto end;
703 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
705 if(lpDropFileStruct->fWide == TRUE) {
706 LPWSTR lpszFileW = NULL;
708 if(lpszFile) {
709 lpszFileW = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
710 if(lpszFileW == NULL) {
711 goto end;
714 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
716 if(lpszFileW) {
717 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
718 HeapFree(GetProcessHeap(), 0, lpszFileW);
720 goto end;
723 while (i++ < lFile)
725 while (*lpDrop++); /* skip filename */
726 if (!*lpDrop)
728 i = (lFile == 0xFFFFFFFF) ? i : 0;
729 goto end;
733 i = strlen(lpDrop);
734 i++;
735 if (!lpszFile ) goto end; /* needed buffer size */
736 i = (lLength > i) ? i : lLength;
737 lstrcpynA (lpszFile, lpDrop, i);
738 end:
739 GlobalUnlock(hDrop);
740 return i;
743 /*************************************************************************
744 * DragQueryFileW [SHELL32.133]
746 UINT WINAPI DragQueryFileW(
747 HDROP hDrop,
748 UINT lFile,
749 LPWSTR lpszwFile,
750 UINT lLength)
752 LPWSTR lpwDrop;
753 UINT i = 0;
754 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
756 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
758 if(!lpDropFileStruct) goto end;
760 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
762 if(lpDropFileStruct->fWide == FALSE) {
763 LPSTR lpszFileA = NULL;
765 if(lpszwFile) {
766 lpszFileA = (LPSTR) HeapAlloc(GetProcessHeap(), 0, lLength);
767 if(lpszFileA == NULL) {
768 goto end;
771 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
773 if(lpszFileA) {
774 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
775 HeapFree(GetProcessHeap(), 0, lpszFileA);
777 goto end;
780 i = 0;
781 while (i++ < lFile)
783 while (*lpwDrop++); /* skip filename */
784 if (!*lpwDrop)
786 i = (lFile == 0xFFFFFFFF) ? i : 0;
787 goto end;
791 i = strlenW(lpwDrop);
792 i++;
793 if ( !lpszwFile) goto end; /* needed buffer size */
795 i = (lLength > i) ? i : lLength;
796 lstrcpynW (lpszwFile, lpwDrop, i);
797 end:
798 GlobalUnlock(hDrop);
799 return i;