Break out all the file related actions and helper functions into
[wine/multimedia.git] / dlls / shell32 / shellole.c
blobae413a2ac2366d7afe110cf651502cb6a7c8b7fd
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 #define COBJMACROS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "shellapi.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "shlobj.h"
36 #include "shlguid.h"
37 #include "winreg.h"
38 #include "winerror.h"
40 #include "undocshell.h"
41 #include "wine/unicode.h"
42 #include "shell32_main.h"
44 #include "wine/debug.h"
45 #include "shlwapi.h"
46 #include "debughlp.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(shell);
50 extern HRESULT WINAPI IFSFolder_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv);
52 const WCHAR sShell32[12] = {'S','H','E','L','L','3','2','.','D','L','L','\0'};
53 const WCHAR sOLE32[10] = {'O','L','E','3','2','.','D','L','L','\0'};
55 HINSTANCE hShellOle32 = 0;
56 /**************************************************************************
57 * Default ClassFactory types
59 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
60 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
62 /* this table contains all CLSID's of shell32 objects */
63 struct {
64 REFIID riid;
65 LPFNCREATEINSTANCE lpfnCI;
66 } InterfaceTable[] = {
67 {&CLSID_ShellFSFolder, &IFSFolder_Constructor},
68 {&CLSID_MyComputer, &ISF_MyComputer_Constructor},
69 {&CLSID_ShellDesktop, &ISF_Desktop_Constructor},
70 {&CLSID_ShellLink, &IShellLink_Constructor},
71 {&CLSID_DragDropHelper, &IDropTargetHelper_Constructor},
72 {&CLSID_ControlPanel, &IControlPanel_Constructor},
73 {&CLSID_AutoComplete, &IAutoComplete_Constructor},
74 {&CLSID_UnixFolder, &UnixFolder_Constructor},
75 {&CLSID_UnixDosFolder, &UnixDosFolder_Constructor},
76 {NULL,NULL}
79 /*************************************************************************
80 * SHCoCreateInstance [SHELL32.102]
82 * NOTES
83 * exported by ordinal
86 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
88 DWORD WINAPI __SHGUIDToStringW (REFGUID guid, LPWSTR str)
90 WCHAR sFormat[52] = {'{','%','0','8','l','x','-','%','0','4',
91 'x','-','%','0','4','x','-','%','0','2',
92 'x','%','0','2','x','-','%','0','2','x',
93 '%','0','2','x','%','0','2','x','%','0',
94 '2','x','%','0','2','x','%','0','2','x',
95 '}','\0'};
97 return wsprintfW ( str, sFormat,
98 guid->Data1, guid->Data2, guid->Data3,
99 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
100 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
104 /************************************************************************/
106 HRESULT WINAPI SHCoCreateInstance(
107 LPCWSTR aclsid,
108 const CLSID *clsid,
109 LPUNKNOWN pUnkOuter,
110 REFIID refiid,
111 LPVOID *ppv)
113 DWORD hres;
114 IID iid;
115 CLSID * myclsid = (CLSID*)clsid;
116 WCHAR sKeyName[MAX_PATH];
117 const WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
118 WCHAR sClassID[60];
119 const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
120 const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
121 WCHAR sDllPath[MAX_PATH];
122 HKEY hKey;
123 DWORD dwSize;
124 BOOLEAN bLoadFromShell32 = FALSE;
125 BOOLEAN bLoadWithoutCOM = FALSE;
126 IClassFactory * pcf = NULL;
128 if(!ppv) return E_POINTER;
129 *ppv=NULL;
131 /* if the clsid is a string, convert it */
132 if (!clsid)
134 if (!aclsid) return REGDB_E_CLASSNOTREG;
135 SHCLSIDFromStringW(aclsid, &iid);
136 myclsid = &iid;
139 TRACE("(%p,%s,unk:%p,%s,%p)\n",
140 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
142 /* we look up the dll path in the registry */
143 __SHGUIDToStringW(myclsid, sClassID);
144 lstrcpyW(sKeyName, sCLSID);
145 lstrcatW(sKeyName, sClassID);
146 lstrcatW(sKeyName, sInProcServer32);
148 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey)) {
149 dwSize = sizeof(sDllPath);
150 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
152 /* if a special registry key is set, we load a shell extension without help of OLE32 */
153 bLoadWithoutCOM = (ERROR_SUCCESS == SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0));
155 /* if the com object is inside shell32, omit use of ole32 */
156 bLoadFromShell32 = (0==lstrcmpiW( PathFindFileNameW(sDllPath), sShell32));
158 RegCloseKey (hKey);
159 } else {
160 /* since we can't find it in the registry we try internally */
161 bLoadFromShell32 = TRUE;
164 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM, bLoadFromShell32);
166 /* now we create an instance */
167 if (bLoadFromShell32) {
168 if (! SUCCEEDED(SHELL32_DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf))) {
169 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid));
171 } else if (bLoadWithoutCOM) {
173 /* load an external dll without ole32 */
174 HANDLE hLibrary;
175 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
176 DllGetClassObjectFunc DllGetClassObject;
178 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
179 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
180 hres = E_ACCESSDENIED;
181 goto end;
182 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
183 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
184 FreeLibrary( hLibrary );
185 hres = E_ACCESSDENIED;
186 goto end;
187 } else if (! SUCCEEDED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
188 TRACE("GetClassObject failed 0x%08lx\n", hres);
189 goto end;
192 } else {
194 /* load an external dll in the usual way */
195 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
196 goto end;
199 /* here we should have a ClassFactory */
200 if (!pcf) return E_ACCESSDENIED;
202 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
203 IClassFactory_Release(pcf);
204 end:
205 if(hres!=S_OK)
207 ERR("failed (0x%08lx) to create CLSID:%s IID:%s\n",
208 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
209 ERR("class not found in registry\n");
212 TRACE("-- instance: %p\n",*ppv);
213 return hres;
216 /*************************************************************************
217 * DllGetClassObject [SHELL32.@]
219 HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
221 HRESULT hres = E_OUTOFMEMORY;
222 IClassFactory * pcf = NULL;
223 int i;
225 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
227 if (!ppv) return E_INVALIDARG;
228 *ppv = NULL;
230 /* search our internal interface table */
231 for(i=0;InterfaceTable[i].riid;i++) {
232 if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
233 TRACE("index[%u]\n", i);
234 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
238 if (!pcf) {
239 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
240 return CLASS_E_CLASSNOTAVAILABLE;
243 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
244 IClassFactory_Release(pcf);
246 TRACE("-- pointer to class factory: %p\n",*ppv);
247 return hres;
250 /*************************************************************************
251 * SHCLSIDFromString [SHELL32.147]
253 * NOTES
254 * exported by ordinal
256 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
258 WCHAR buffer[40];
259 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
260 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
261 return CO_E_CLASSSTRING;
262 return CLSIDFromString( buffer, id );
264 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
266 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
267 return CLSIDFromString((LPWSTR)clsid, id);
269 DWORD WINAPI SHCLSIDFromStringAW (LPVOID clsid, CLSID *id)
271 if (SHELL_OsIsUnicode())
272 return SHCLSIDFromStringW (clsid, id);
273 return SHCLSIDFromStringA (clsid, id);
276 /*************************************************************************
277 * Shell Memory Allocator
280 /* set the vtable later */
281 static const IMallocVtbl VT_Shell_IMalloc32;
283 /* this is the static object instance */
284 typedef struct {
285 const IMallocVtbl *lpVtbl;
286 DWORD dummy;
287 } _ShellMalloc;
289 static _ShellMalloc Shell_Malloc = { &VT_Shell_IMalloc32,1};
291 /* this is the global allocator of shell32 */
292 static IMalloc * ShellTaskAllocator = NULL;
294 /******************************************************************************
295 * IShellMalloc_QueryInterface [VTABLE]
297 static HRESULT WINAPI IShellMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid, LPVOID *obj)
299 TRACE("(%s,%p)\n",shdebugstr_guid(refiid),obj);
300 if (IsEqualIID(refiid, &IID_IUnknown) || IsEqualIID(refiid, &IID_IMalloc)) {
301 *obj = (LPMALLOC) &Shell_Malloc;
302 return S_OK;
304 return E_NOINTERFACE;
307 /******************************************************************************
308 * IShellMalloc_AddRefRelease [VTABLE]
310 static ULONG WINAPI IShellMalloc_fnAddRefRelease(LPMALLOC iface)
312 return 1;
315 /******************************************************************************
316 * IShellMalloc_Alloc [VTABLE]
318 static LPVOID WINAPI IShellMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
320 LPVOID addr;
322 addr = (LPVOID) LocalAlloc(LMEM_ZEROINIT, cb);
323 TRACE("(%p,%ld);\n",addr,cb);
324 return addr;
327 /******************************************************************************
328 * IShellMalloc_Realloc [VTABLE]
330 static LPVOID WINAPI IShellMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
332 LPVOID addr;
334 if (pv) {
335 if (cb) {
336 addr = (LPVOID) LocalReAlloc((HANDLE) pv, cb, LMEM_ZEROINIT | LMEM_MOVEABLE);
337 } else {
338 LocalFree((HANDLE) pv);
339 addr = NULL;
341 } else {
342 if (cb) {
343 addr = (LPVOID) LocalAlloc(LMEM_ZEROINIT, cb);
344 } else {
345 addr = NULL;
349 TRACE("(%p->%p,%ld)\n",pv,addr,cb);
350 return addr;
353 /******************************************************************************
354 * IShellMalloc_Free [VTABLE]
356 static VOID WINAPI IShellMalloc_fnFree(LPMALLOC iface, LPVOID pv)
358 TRACE("(%p)\n",pv);
359 LocalFree((HANDLE) pv);
362 /******************************************************************************
363 * IShellMalloc_GetSize [VTABLE]
365 static DWORD WINAPI IShellMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
367 DWORD cb = (DWORD) LocalSize((HANDLE)pv);
368 TRACE("(%p,%ld)\n", pv, cb);
369 return cb;
372 /******************************************************************************
373 * IShellMalloc_DidAlloc [VTABLE]
375 static INT WINAPI IShellMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
377 TRACE("(%p)\n",pv);
378 return -1;
381 /******************************************************************************
382 * IShellMalloc_HeapMinimize [VTABLE]
384 static VOID WINAPI IShellMalloc_fnHeapMinimize(LPMALLOC iface)
386 TRACE("()\n");
389 static const IMallocVtbl VT_Shell_IMalloc32 =
391 IShellMalloc_fnQueryInterface,
392 IShellMalloc_fnAddRefRelease,
393 IShellMalloc_fnAddRefRelease,
394 IShellMalloc_fnAlloc,
395 IShellMalloc_fnRealloc,
396 IShellMalloc_fnFree,
397 IShellMalloc_fnGetSize,
398 IShellMalloc_fnDidAlloc,
399 IShellMalloc_fnHeapMinimize
402 /*************************************************************************
403 * SHGetMalloc [SHELL32.@]
405 * Return the shell IMalloc interface.
407 * PARAMS
408 * lpmal [O] Destination for IMalloc interface.
410 * RETURNS
411 * Success: S_OK. lpmal contains the shells IMalloc interface.
412 * Failure. An HRESULT error code.
414 * NOTES
415 * This function will use CoGetMalloc() if OLE32.DLL is already loaded.
416 * If not it uses an internal implementation as a fallback.
418 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
420 TRACE("(%p)\n", lpmal);
422 if (!ShellTaskAllocator)
424 HMODULE hOle32 = GetModuleHandleA("OLE32.DLL");
425 /* this is very suspect. we should not being using a different
426 * allocator from deallocator based on something undeterministic
427 * like whether ole32 is loaded. as it happens currently, they
428 * both map to the same allocator deep down, but this could
429 * change in the future. */
430 if(hOle32) {
431 CoGetMalloc(MEMCTX_TASK, &ShellTaskAllocator);
432 TRACE("got ole32 IMalloc\n");
434 if(!ShellTaskAllocator) {
435 ShellTaskAllocator = (IMalloc* ) &Shell_Malloc;
436 TRACE("use fallback allocator\n");
439 *lpmal = ShellTaskAllocator;
440 return S_OK;
443 /*************************************************************************
444 * SHAlloc [SHELL32.196]
446 * NOTES
447 * exported by ordinal
449 LPVOID WINAPI SHAlloc(DWORD len)
451 IMalloc * ppv;
452 LPBYTE ret;
454 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
456 ret = (LPVOID) IMalloc_Alloc(ShellTaskAllocator, len);
457 TRACE("%lu bytes at %p\n",len, ret);
458 return (LPVOID)ret;
461 /*************************************************************************
462 * SHFree [SHELL32.195]
464 * NOTES
465 * exported by ordinal
467 void WINAPI SHFree(LPVOID pv)
469 IMalloc * ppv;
471 TRACE("%p\n",pv);
472 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
473 IMalloc_Free(ShellTaskAllocator, pv);
476 /*************************************************************************
477 * SHGetDesktopFolder [SHELL32.@]
479 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
481 HRESULT hres = S_OK;
482 TRACE("\n");
484 if(!psf) return E_INVALIDARG;
485 *psf = NULL;
486 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder,(LPVOID*)psf);
488 TRACE("-- %p->(%p)\n",psf, *psf);
489 return hres;
491 /**************************************************************************
492 * Default ClassFactory Implementation
494 * SHCreateDefClassObject
496 * NOTES
497 * Helper function for dlls without their own classfactory.
498 * A generic classfactory is returned.
499 * When the CreateInstance of the cf is called the callback is executed.
502 typedef struct
504 const IClassFactoryVtbl *lpVtbl;
505 DWORD ref;
506 CLSID *rclsid;
507 LPFNCREATEINSTANCE lpfnCI;
508 const IID * riidInst;
509 ULONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
510 } IDefClFImpl;
512 static const IClassFactoryVtbl dclfvt;
514 /**************************************************************************
515 * IDefClF_fnConstructor
518 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
520 IDefClFImpl* lpclf;
522 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
523 lpclf->ref = 1;
524 lpclf->lpVtbl = &dclfvt;
525 lpclf->lpfnCI = lpfnCI;
526 lpclf->pcRefDll = pcRefDll;
528 if (pcRefDll) InterlockedIncrement(pcRefDll);
529 lpclf->riidInst = riidInst;
531 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
532 return (LPCLASSFACTORY)lpclf;
534 /**************************************************************************
535 * IDefClF_fnQueryInterface
537 static HRESULT WINAPI IDefClF_fnQueryInterface(
538 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
540 IDefClFImpl *This = (IDefClFImpl *)iface;
542 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
544 *ppvObj = NULL;
546 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
547 *ppvObj = This;
548 InterlockedIncrement(&This->ref);
549 return S_OK;
552 TRACE("-- E_NOINTERFACE\n");
553 return E_NOINTERFACE;
555 /******************************************************************************
556 * IDefClF_fnAddRef
558 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
560 IDefClFImpl *This = (IDefClFImpl *)iface;
561 ULONG refCount = InterlockedIncrement(&This->ref);
563 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
565 return refCount;
567 /******************************************************************************
568 * IDefClF_fnRelease
570 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
572 IDefClFImpl *This = (IDefClFImpl *)iface;
573 ULONG refCount = InterlockedDecrement(&This->ref);
575 TRACE("(%p)->(count=%lu)\n", This, refCount + 1);
577 if (!refCount)
579 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
581 TRACE("-- destroying IClassFactory(%p)\n",This);
582 HeapFree(GetProcessHeap(),0,This);
583 return 0;
585 return refCount;
587 /******************************************************************************
588 * IDefClF_fnCreateInstance
590 static HRESULT WINAPI IDefClF_fnCreateInstance(
591 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
593 IDefClFImpl *This = (IDefClFImpl *)iface;
595 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
597 *ppvObject = NULL;
599 if ( This->riidInst==NULL ||
600 IsEqualCLSID(riid, This->riidInst) ||
601 IsEqualCLSID(riid, &IID_IUnknown) )
603 return This->lpfnCI(pUnkOuter, riid, ppvObject);
606 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
607 return E_NOINTERFACE;
609 /******************************************************************************
610 * IDefClF_fnLockServer
612 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
614 IDefClFImpl *This = (IDefClFImpl *)iface;
615 TRACE("%p->(0x%x), not implemented\n",This, fLock);
616 return E_NOTIMPL;
619 static const IClassFactoryVtbl dclfvt =
621 IDefClF_fnQueryInterface,
622 IDefClF_fnAddRef,
623 IDefClF_fnRelease,
624 IDefClF_fnCreateInstance,
625 IDefClF_fnLockServer
628 /******************************************************************************
629 * SHCreateDefClassObject [SHELL32.70]
631 HRESULT WINAPI SHCreateDefClassObject(
632 REFIID riid,
633 LPVOID* ppv,
634 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
635 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
636 REFIID riidInst) /* [in] optional interface to the instance */
638 IClassFactory * pcf;
640 TRACE("%s %p %p %p %s\n",
641 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
643 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
644 if (! (pcf = IDefClF_fnConstructor(lpfnCI, pcRefDll, riidInst))) return E_OUTOFMEMORY;
645 *ppv = pcf;
646 return NOERROR;
649 /*************************************************************************
650 * DragAcceptFiles [SHELL32.@]
652 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
654 LONG exstyle;
656 if( !IsWindow(hWnd) ) return;
657 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
658 if (b)
659 exstyle |= WS_EX_ACCEPTFILES;
660 else
661 exstyle &= ~WS_EX_ACCEPTFILES;
662 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
665 /*************************************************************************
666 * DragFinish [SHELL32.@]
668 void WINAPI DragFinish(HDROP h)
670 TRACE("\n");
671 GlobalFree((HGLOBAL)h);
674 /*************************************************************************
675 * DragQueryPoint [SHELL32.@]
677 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
679 DROPFILES *lpDropFileStruct;
680 BOOL bRet;
682 TRACE("\n");
684 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
686 *p = lpDropFileStruct->pt;
687 bRet = lpDropFileStruct->fNC;
689 GlobalUnlock(hDrop);
690 return bRet;
693 /*************************************************************************
694 * DragQueryFile [SHELL32.@]
695 * DragQueryFileA [SHELL32.@]
697 UINT WINAPI DragQueryFileA(
698 HDROP hDrop,
699 UINT lFile,
700 LPSTR lpszFile,
701 UINT lLength)
703 LPSTR lpDrop;
704 UINT i = 0;
705 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
707 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
709 if(!lpDropFileStruct) goto end;
711 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
713 if(lpDropFileStruct->fWide) {
714 LPWSTR lpszFileW = NULL;
716 if(lpszFile) {
717 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
718 if(lpszFileW == NULL) {
719 goto end;
722 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
724 if(lpszFileW) {
725 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
726 HeapFree(GetProcessHeap(), 0, lpszFileW);
728 goto end;
731 while (i++ < lFile)
733 while (*lpDrop++); /* skip filename */
734 if (!*lpDrop)
736 i = (lFile == 0xFFFFFFFF) ? i : 0;
737 goto end;
741 i = strlen(lpDrop);
742 i++;
743 if (!lpszFile ) goto end; /* needed buffer size */
744 i = (lLength > i) ? i : lLength;
745 lstrcpynA (lpszFile, lpDrop, i);
746 end:
747 GlobalUnlock(hDrop);
748 return i;
751 /*************************************************************************
752 * DragQueryFileW [SHELL32.@]
754 UINT WINAPI DragQueryFileW(
755 HDROP hDrop,
756 UINT lFile,
757 LPWSTR lpszwFile,
758 UINT lLength)
760 LPWSTR lpwDrop;
761 UINT i = 0;
762 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
764 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
766 if(!lpDropFileStruct) goto end;
768 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
770 if(lpDropFileStruct->fWide == FALSE) {
771 LPSTR lpszFileA = NULL;
773 if(lpszwFile) {
774 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
775 if(lpszFileA == NULL) {
776 goto end;
779 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
781 if(lpszFileA) {
782 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
783 HeapFree(GetProcessHeap(), 0, lpszFileA);
785 goto end;
788 i = 0;
789 while (i++ < lFile)
791 while (*lpwDrop++); /* skip filename */
792 if (!*lpwDrop)
794 i = (lFile == 0xFFFFFFFF) ? i : 0;
795 goto end;
799 i = strlenW(lpwDrop);
800 i++;
801 if ( !lpszwFile) goto end; /* needed buffer size */
803 i = (lLength > i) ? i : lLength;
804 lstrcpynW (lpszwFile, lpwDrop, i);
805 end:
806 GlobalUnlock(hDrop);
807 return i;