Use LMEM_ flags for LocalAlloc(), not GMEM_ (GlobalAlloc).
[wine/hacks.git] / dlls / shell32 / shellole.c
blobb572fcd9490dc7f9f415ed8520bb7388257f3aaf
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 {NULL,NULL}
78 /*************************************************************************
79 * SHCoCreateInstance [SHELL32.102]
81 * NOTES
82 * exported by ordinal
85 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
87 DWORD WINAPI __SHGUIDToStringW (REFGUID guid, LPWSTR str)
89 WCHAR sFormat[52] = {'{','%','0','8','l','x','-','%','0','4',
90 'x','-','%','0','4','x','-','%','0','2',
91 'x','%','0','2','x','-','%','0','2','x',
92 '%','0','2','x','%','0','2','x','%','0',
93 '2','x','%','0','2','x','%','0','2','x',
94 '}','\0'};
96 return wsprintfW ( str, sFormat,
97 guid->Data1, guid->Data2, guid->Data3,
98 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
99 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
103 /************************************************************************/
105 HRESULT WINAPI SHCoCreateInstance(
106 LPCWSTR aclsid,
107 const CLSID *clsid,
108 LPUNKNOWN pUnkOuter,
109 REFIID refiid,
110 LPVOID *ppv)
112 DWORD hres;
113 IID iid;
114 CLSID * myclsid = (CLSID*)clsid;
115 WCHAR sKeyName[MAX_PATH];
116 const WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
117 WCHAR sClassID[60];
118 const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
119 const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
120 WCHAR sDllPath[MAX_PATH];
121 HKEY hKey;
122 DWORD dwSize;
123 BOOLEAN bLoadFromShell32 = FALSE;
124 BOOLEAN bLoadWithoutCOM = FALSE;
125 IClassFactory * pcf = NULL;
127 if(!ppv) return E_POINTER;
128 *ppv=NULL;
130 /* if the clsid is a string, convert it */
131 if (!clsid)
133 if (!aclsid) return REGDB_E_CLASSNOTREG;
134 SHCLSIDFromStringW(aclsid, &iid);
135 myclsid = &iid;
138 TRACE("(%p,%s,unk:%p,%s,%p)\n",
139 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
141 /* we look up the dll path in the registry */
142 __SHGUIDToStringW(myclsid, sClassID);
143 lstrcpyW(sKeyName, sCLSID);
144 lstrcatW(sKeyName, sClassID);
145 lstrcatW(sKeyName, sInProcServer32);
147 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey)) {
148 dwSize = sizeof(sDllPath);
149 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
151 /* if a special registry key is set, we load a shell extension without help of OLE32 */
152 bLoadWithoutCOM = (ERROR_SUCCESS == SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0));
154 /* if the com object is inside shell32, omit use of ole32 */
155 bLoadFromShell32 = (0==lstrcmpiW( PathFindFileNameW(sDllPath), sShell32));
157 RegCloseKey (hKey);
158 } else {
159 /* since we can't find it in the registry we try internally */
160 bLoadFromShell32 = TRUE;
163 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM, bLoadFromShell32);
165 /* now we create a instance */
166 if (bLoadFromShell32) {
167 if (! SUCCEEDED(SHELL32_DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf))) {
168 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid));
170 } else if (bLoadWithoutCOM) {
172 /* load a external dll without ole32 */
173 HANDLE hLibrary;
174 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
175 DllGetClassObjectFunc DllGetClassObject;
177 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
178 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
179 hres = E_ACCESSDENIED;
180 goto end;
181 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
182 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
183 FreeLibrary( hLibrary );
184 hres = E_ACCESSDENIED;
185 goto end;
186 } else if (! SUCCEEDED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
187 TRACE("GetClassObject failed 0x%08lx\n", hres);
188 goto end;
191 } else {
193 /* load a external dll in the usual way */
194 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
195 goto end;
198 /* here we should have a ClassFactory */
199 if (!pcf) return E_ACCESSDENIED;
201 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
202 IClassFactory_Release(pcf);
203 end:
204 if(hres!=S_OK)
206 ERR("failed (0x%08lx) to create CLSID:%s IID:%s\n",
207 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
208 ERR("class not found in registry\n");
211 TRACE("-- instance: %p\n",*ppv);
212 return hres;
215 /*************************************************************************
216 * DllGetClassObject [SHELL32.128]
218 HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
220 HRESULT hres = E_OUTOFMEMORY;
221 IClassFactory * pcf = NULL;
222 int i;
224 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
226 if (!ppv) return E_INVALIDARG;
227 *ppv = NULL;
229 /* search our internal interface table */
230 for(i=0;InterfaceTable[i].riid;i++) {
231 if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
232 TRACE("index[%u]\n", i);
233 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
237 if (!pcf) {
238 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
239 return CLASS_E_CLASSNOTAVAILABLE;
242 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
243 IClassFactory_Release(pcf);
245 TRACE("-- pointer to class factory: %p\n",*ppv);
246 return hres;
249 /*************************************************************************
250 * SHCLSIDFromString [SHELL32.147]
252 * NOTES
253 * exported by ordinal
255 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
257 WCHAR buffer[40];
258 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
259 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
260 return CO_E_CLASSSTRING;
261 return CLSIDFromString( buffer, id );
263 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
265 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
266 return CLSIDFromString((LPWSTR)clsid, id);
268 DWORD WINAPI SHCLSIDFromStringAW (LPVOID clsid, CLSID *id)
270 if (SHELL_OsIsUnicode())
271 return SHCLSIDFromStringW (clsid, id);
272 return SHCLSIDFromStringA (clsid, id);
275 /*************************************************************************
276 * Shell Memory Allocator
279 /* set the vtable later */
280 static IMallocVtbl VT_Shell_IMalloc32;
282 /* this is the static object instance */
283 typedef struct {
284 IMallocVtbl *lpVtbl;
285 DWORD dummy;
286 } _ShellMalloc;
288 static _ShellMalloc Shell_Malloc = { &VT_Shell_IMalloc32,1};
290 /* this is the global allocator of shell32 */
291 static IMalloc * ShellTaskAllocator = NULL;
293 /******************************************************************************
294 * IShellMalloc_QueryInterface [VTABLE]
296 static HRESULT WINAPI IShellMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid, LPVOID *obj)
298 TRACE("(%s,%p)\n",shdebugstr_guid(refiid),obj);
299 if (IsEqualIID(refiid, &IID_IUnknown) || IsEqualIID(refiid, &IID_IMalloc)) {
300 *obj = (LPMALLOC) &Shell_Malloc;
301 return S_OK;
303 return E_NOINTERFACE;
306 /******************************************************************************
307 * IShellMalloc_AddRefRelease [VTABLE]
309 static ULONG WINAPI IShellMalloc_fnAddRefRelease(LPMALLOC iface)
311 return 1;
314 /******************************************************************************
315 * IShellMalloc_Alloc [VTABLE]
317 static LPVOID WINAPI IShellMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
319 LPVOID addr;
321 addr = (LPVOID) LocalAlloc(LMEM_ZEROINIT, cb);
322 TRACE("(%p,%ld);\n",addr,cb);
323 return addr;
326 /******************************************************************************
327 * IShellMalloc_Realloc [VTABLE]
329 static LPVOID WINAPI IShellMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
331 LPVOID addr;
333 if (pv) {
334 if (cb) {
335 addr = (LPVOID) LocalReAlloc((HANDLE) pv, cb, LMEM_ZEROINIT | LMEM_MOVEABLE);
336 } else {
337 LocalFree((HANDLE) pv);
338 addr = NULL;
340 } else {
341 if (cb) {
342 addr = (LPVOID) LocalAlloc(LMEM_ZEROINIT, cb);
343 } else {
344 addr = NULL;
348 TRACE("(%p->%p,%ld)\n",pv,addr,cb);
349 return addr;
352 /******************************************************************************
353 * IShellMalloc_Free [VTABLE]
355 static VOID WINAPI IShellMalloc_fnFree(LPMALLOC iface, LPVOID pv)
357 TRACE("(%p)\n",pv);
358 LocalFree((HANDLE) pv);
361 /******************************************************************************
362 * IShellMalloc_GetSize [VTABLE]
364 static DWORD WINAPI IShellMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
366 DWORD cb = (DWORD) LocalSize((HANDLE)pv);
367 TRACE("(%p,%ld)\n", pv, cb);
368 return cb;
371 /******************************************************************************
372 * IShellMalloc_DidAlloc [VTABLE]
374 static INT WINAPI IShellMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
376 TRACE("(%p)\n",pv);
377 return -1;
380 /******************************************************************************
381 * IShellMalloc_HeapMinimize [VTABLE]
383 static VOID WINAPI IShellMalloc_fnHeapMinimize(LPMALLOC iface)
385 TRACE("()\n");
388 static IMallocVtbl VT_Shell_IMalloc32 =
390 IShellMalloc_fnQueryInterface,
391 IShellMalloc_fnAddRefRelease,
392 IShellMalloc_fnAddRefRelease,
393 IShellMalloc_fnAlloc,
394 IShellMalloc_fnRealloc,
395 IShellMalloc_fnFree,
396 IShellMalloc_fnGetSize,
397 IShellMalloc_fnDidAlloc,
398 IShellMalloc_fnHeapMinimize
401 /*************************************************************************
402 * SHGetMalloc [SHELL32.@]
404 * Return the shell IMalloc interface.
406 * PARAMS
407 * lpmal [O] Destination for IMalloc interface.
409 * RETURNS
410 * Success: S_OK. lpmal contains the shells IMalloc interface.
411 * Failure. An HRESULT error code.
413 * NOTES
414 * This function will use CoGetMalloc() if OLE32.DLL is already loaded.
415 * If not it uses an internal implementation as a fallback.
417 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
419 TRACE("(%p)\n", lpmal);
421 if (!ShellTaskAllocator)
423 HMODULE hOle32 = GetModuleHandleA("OLE32.DLL");
424 /* this is very suspect. we should not being using a different
425 * allocator from deallocator based on something undeterministic
426 * like whether ole32 is loaded. as it happens currently, they
427 * both map to the same allocator deep down, but this could
428 * change in the future. */
429 if(hOle32) {
430 CoGetMalloc(MEMCTX_TASK, &ShellTaskAllocator);
431 TRACE("got ole32 IMalloc\n");
433 if(!ShellTaskAllocator) {
434 ShellTaskAllocator = (IMalloc* ) &Shell_Malloc;
435 TRACE("use fallback allocator\n");
438 *lpmal = ShellTaskAllocator;
439 return S_OK;
442 /*************************************************************************
443 * SHAlloc [SHELL32.196]
445 * NOTES
446 * exported by ordinal
448 LPVOID WINAPI SHAlloc(DWORD len)
450 IMalloc * ppv;
451 LPBYTE ret;
453 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
455 ret = (LPVOID) IMalloc_Alloc(ShellTaskAllocator, len);
456 TRACE("%lu bytes at %p\n",len, ret);
457 return (LPVOID)ret;
460 /*************************************************************************
461 * SHFree [SHELL32.195]
463 * NOTES
464 * exported by ordinal
466 void WINAPI SHFree(LPVOID pv)
468 IMalloc * ppv;
470 TRACE("%p\n",pv);
471 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
472 IMalloc_Free(ShellTaskAllocator, pv);
475 /*************************************************************************
476 * SHGetDesktopFolder [SHELL32.@]
478 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
480 HRESULT hres = S_OK;
481 TRACE("\n");
483 if(!psf) return E_INVALIDARG;
484 *psf = NULL;
485 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder,(LPVOID*)psf);
487 TRACE("-- %p->(%p)\n",psf, *psf);
488 return hres;
490 /**************************************************************************
491 * Default ClassFactory Implementation
493 * SHCreateDefClassObject
495 * NOTES
496 * helper function for dll's without a own classfactory
497 * a generic classfactory is returned
498 * when the CreateInstance of the cf is called the callback is executed
501 typedef struct
503 IClassFactoryVtbl *lpVtbl;
504 DWORD ref;
505 CLSID *rclsid;
506 LPFNCREATEINSTANCE lpfnCI;
507 const IID * riidInst;
508 ULONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
509 } IDefClFImpl;
511 static IClassFactoryVtbl dclfvt;
513 /**************************************************************************
514 * IDefClF_fnConstructor
517 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
519 IDefClFImpl* lpclf;
521 lpclf = (IDefClFImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
522 lpclf->ref = 1;
523 lpclf->lpVtbl = &dclfvt;
524 lpclf->lpfnCI = lpfnCI;
525 lpclf->pcRefDll = pcRefDll;
527 if (pcRefDll) InterlockedIncrement(pcRefDll);
528 lpclf->riidInst = riidInst;
530 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
531 return (LPCLASSFACTORY)lpclf;
533 /**************************************************************************
534 * IDefClF_fnQueryInterface
536 static HRESULT WINAPI IDefClF_fnQueryInterface(
537 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
539 IDefClFImpl *This = (IDefClFImpl *)iface;
541 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
543 *ppvObj = NULL;
545 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
546 *ppvObj = This;
547 InterlockedIncrement(&This->ref);
548 return S_OK;
551 TRACE("-- E_NOINTERFACE\n");
552 return E_NOINTERFACE;
554 /******************************************************************************
555 * IDefClF_fnAddRef
557 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
559 IDefClFImpl *This = (IDefClFImpl *)iface;
560 ULONG refCount = InterlockedIncrement(&This->ref);
562 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
564 return refCount;
566 /******************************************************************************
567 * IDefClF_fnRelease
569 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
571 IDefClFImpl *This = (IDefClFImpl *)iface;
572 ULONG refCount = InterlockedDecrement(&This->ref);
574 TRACE("(%p)->(count=%lu)\n", This, refCount + 1);
576 if (!refCount)
578 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
580 TRACE("-- destroying IClassFactory(%p)\n",This);
581 HeapFree(GetProcessHeap(),0,This);
582 return 0;
584 return refCount;
586 /******************************************************************************
587 * IDefClF_fnCreateInstance
589 static HRESULT WINAPI IDefClF_fnCreateInstance(
590 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
592 IDefClFImpl *This = (IDefClFImpl *)iface;
594 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
596 *ppvObject = NULL;
598 if ( This->riidInst==NULL ||
599 IsEqualCLSID(riid, This->riidInst) ||
600 IsEqualCLSID(riid, &IID_IUnknown) )
602 return This->lpfnCI(pUnkOuter, riid, ppvObject);
605 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
606 return E_NOINTERFACE;
608 /******************************************************************************
609 * IDefClF_fnLockServer
611 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
613 IDefClFImpl *This = (IDefClFImpl *)iface;
614 TRACE("%p->(0x%x), not implemented\n",This, fLock);
615 return E_NOTIMPL;
618 static IClassFactoryVtbl dclfvt =
620 IDefClF_fnQueryInterface,
621 IDefClF_fnAddRef,
622 IDefClF_fnRelease,
623 IDefClF_fnCreateInstance,
624 IDefClF_fnLockServer
627 /******************************************************************************
628 * SHCreateDefClassObject [SHELL32.70]
630 HRESULT WINAPI SHCreateDefClassObject(
631 REFIID riid,
632 LPVOID* ppv,
633 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
634 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
635 REFIID riidInst) /* [in] optional interface to the instance */
637 IClassFactory * pcf;
639 TRACE("%s %p %p %p %s\n",
640 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
642 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
643 if (! (pcf = IDefClF_fnConstructor(lpfnCI, pcRefDll, riidInst))) return E_OUTOFMEMORY;
644 *ppv = pcf;
645 return NOERROR;
648 /*************************************************************************
649 * DragAcceptFiles [SHELL32.54]
651 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
653 LONG exstyle;
655 if( !IsWindow(hWnd) ) return;
656 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
657 if (b)
658 exstyle |= WS_EX_ACCEPTFILES;
659 else
660 exstyle &= ~WS_EX_ACCEPTFILES;
661 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
664 /*************************************************************************
665 * DragFinish [SHELL32.80]
667 void WINAPI DragFinish(HDROP h)
669 TRACE("\n");
670 GlobalFree((HGLOBAL)h);
673 /*************************************************************************
674 * DragQueryPoint [SHELL32.135]
676 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
678 DROPFILES *lpDropFileStruct;
679 BOOL bRet;
681 TRACE("\n");
683 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
685 *p = lpDropFileStruct->pt;
686 bRet = lpDropFileStruct->fNC;
688 GlobalUnlock(hDrop);
689 return bRet;
692 /*************************************************************************
693 * DragQueryFile [SHELL32.81]
694 * DragQueryFileA [SHELL32.82]
696 UINT WINAPI DragQueryFileA(
697 HDROP hDrop,
698 UINT lFile,
699 LPSTR lpszFile,
700 UINT lLength)
702 LPSTR lpDrop;
703 UINT i = 0;
704 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
706 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
708 if(!lpDropFileStruct) goto end;
710 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
712 if(lpDropFileStruct->fWide) {
713 LPWSTR lpszFileW = NULL;
715 if(lpszFile) {
716 lpszFileW = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
717 if(lpszFileW == NULL) {
718 goto end;
721 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
723 if(lpszFileW) {
724 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
725 HeapFree(GetProcessHeap(), 0, lpszFileW);
727 goto end;
730 while (i++ < lFile)
732 while (*lpDrop++); /* skip filename */
733 if (!*lpDrop)
735 i = (lFile == 0xFFFFFFFF) ? i : 0;
736 goto end;
740 i = strlen(lpDrop);
741 i++;
742 if (!lpszFile ) goto end; /* needed buffer size */
743 i = (lLength > i) ? i : lLength;
744 lstrcpynA (lpszFile, lpDrop, i);
745 end:
746 GlobalUnlock(hDrop);
747 return i;
750 /*************************************************************************
751 * DragQueryFileW [SHELL32.133]
753 UINT WINAPI DragQueryFileW(
754 HDROP hDrop,
755 UINT lFile,
756 LPWSTR lpszwFile,
757 UINT lLength)
759 LPWSTR lpwDrop;
760 UINT i = 0;
761 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
763 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
765 if(!lpDropFileStruct) goto end;
767 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
769 if(lpDropFileStruct->fWide == FALSE) {
770 LPSTR lpszFileA = NULL;
772 if(lpszwFile) {
773 lpszFileA = (LPSTR) HeapAlloc(GetProcessHeap(), 0, lLength);
774 if(lpszFileA == NULL) {
775 goto end;
778 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
780 if(lpszFileA) {
781 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
782 HeapFree(GetProcessHeap(), 0, lpszFileA);
784 goto end;
787 i = 0;
788 while (i++ < lFile)
790 while (*lpwDrop++); /* skip filename */
791 if (!*lpwDrop)
793 i = (lFile == 0xFFFFFFFF) ? i : 0;
794 goto end;
798 i = strlenW(lpwDrop);
799 i++;
800 if ( !lpszwFile) goto end; /* needed buffer size */
802 i = (lLength > i) ? i : lLength;
803 lstrcpynW (lpszwFile, lpwDrop, i);
804 end:
805 GlobalUnlock(hDrop);
806 return i;