Added memicmpW.
[wine.git] / dlls / shell32 / shellole.c
blob5ffed9b2d4264daec47d990657626c92e4c64439
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 {NULL,NULL}
74 /*************************************************************************
75 * __CoCreateInstance [internal]
77 * NOTES
78 * wraper for late bound call to OLE32.DLL
81 HRESULT (WINAPI *pCoCreateInstance)(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv) = NULL;
83 void * __GetExternalFunc(HMODULE * phModule, LPCWSTR szModuleName, LPCSTR szProcName)
85 if (!*phModule) *phModule = GetModuleHandleW(szModuleName);
86 if (!*phModule) *phModule = LoadLibraryW(szModuleName);
87 if (*phModule) return GetProcAddress(*phModule, szProcName);
88 return NULL;
91 HRESULT __CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID iid, LPVOID *ppv)
93 if(!pCoCreateInstance) pCoCreateInstance = __GetExternalFunc(&hShellOle32, sOLE32, "CoCreateInstance");
94 if(!pCoCreateInstance) return E_FAIL;
95 return pCoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, ppv);
98 /*************************************************************************
99 * SHCoCreateInstance [SHELL32.102]
101 * NOTES
102 * exported by ordinal
105 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
107 DWORD WINAPI __SHGUIDToStringW (REFGUID guid, LPWSTR str)
109 WCHAR sFormat[52] = {'{','%','0','8','l','x','-','%','0','4',
110 'x','-','%','0','4','x','-','%','0','2',
111 'x','%','0','2','x','-','%','0','2','x',
112 '%','0','2','x','%','0','2','x','%','0',
113 '2','x','%','0','2','x','%','0','2','x',
114 '}','\0'};
116 return wsprintfW ( str, sFormat,
117 guid->Data1, guid->Data2, guid->Data3,
118 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
119 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
123 /************************************************************************/
125 LRESULT WINAPI SHCoCreateInstance(
126 LPCWSTR aclsid,
127 const CLSID *clsid,
128 LPUNKNOWN pUnkOuter,
129 REFIID refiid,
130 LPVOID *ppv)
132 DWORD hres;
133 IID iid;
134 CLSID * myclsid = (CLSID*)clsid;
135 WCHAR sKeyName[MAX_PATH];
136 const WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
137 WCHAR sClassID[60];
138 const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
139 const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
140 WCHAR sDllPath[MAX_PATH];
141 HKEY hKey;
142 DWORD dwSize;
143 BOOLEAN bLoadFromShell32 = FALSE;
144 BOOLEAN bLoadWithoutCOM = FALSE;
145 IClassFactory * pcf = NULL;
147 if(!ppv) return E_POINTER;
148 *ppv=NULL;
150 /* if the clsid is a string, convert it */
151 if (!clsid)
153 if (!aclsid) return REGDB_E_CLASSNOTREG;
154 SHCLSIDFromStringW(aclsid, &iid);
155 myclsid = &iid;
158 TRACE("(%p,%s,unk:%p,%s,%p)\n",
159 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
161 /* we look up the dll path in the registry */
162 __SHGUIDToStringW(myclsid, sClassID);
163 lstrcpyW(sKeyName, sCLSID);
164 lstrcatW(sKeyName, sClassID);
165 lstrcatW(sKeyName, sInProcServer32);
167 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey)) {
168 dwSize = sizeof(sDllPath);
169 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
171 /* if a special registry key is set, we load a shell extension without help of OLE32 */
172 bLoadWithoutCOM = (ERROR_SUCCESS == SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0));
174 /* if the com object is inside shell32, omit use of ole32 */
175 bLoadFromShell32 = (0==lstrcmpiW( PathFindFileNameW(sDllPath), sShell32));
177 RegCloseKey (hKey);
178 } else {
179 /* since we can't find it in the registry we try internally */
180 bLoadFromShell32 = TRUE;
183 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM, bLoadFromShell32);
185 /* now we create a instance */
186 if (bLoadFromShell32) {
187 if (! SUCCEEDED(SHELL32_DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf))) {
188 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid));
190 } else if (bLoadWithoutCOM) {
192 /* load a external dll without ole32 */
193 HANDLE hLibrary;
194 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
195 DllGetClassObjectFunc DllGetClassObject;
197 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
198 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
199 hres = E_ACCESSDENIED;
200 goto end;
201 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
202 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
203 FreeLibrary( hLibrary );
204 hres = E_ACCESSDENIED;
205 goto end;
206 } else if (! SUCCEEDED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
207 TRACE("GetClassObject failed 0x%08lx\n", hres);
208 goto end;
211 } else {
213 /* load a external dll in the usual way */
214 hres = __CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
215 goto end;
218 /* here we should have a ClassFactory */
219 if (!pcf) return E_ACCESSDENIED;
221 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
222 IClassFactory_Release(pcf);
223 end:
224 if(hres!=S_OK)
226 ERR("failed (0x%08lx) to create CLSID:%s IID:%s\n",
227 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
228 ERR("class not found in registry\n");
231 TRACE("-- instance: %p\n",*ppv);
232 return hres;
235 /*************************************************************************
236 * DllGetClassObject [SHELL32.128]
238 HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
240 HRESULT hres = E_OUTOFMEMORY;
241 IClassFactory * pcf = NULL;
242 int i;
244 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
246 if (!ppv) return E_INVALIDARG;
247 *ppv = NULL;
249 /* search our internal interface table */
250 for(i=0;InterfaceTable[i].riid;i++) {
251 if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
252 TRACE("index[%u]\n", i);
253 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
257 if (!pcf) {
258 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
259 return CLASS_E_CLASSNOTAVAILABLE;
262 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
263 IClassFactory_Release(pcf);
265 TRACE("-- pointer to class factory: %p\n",*ppv);
266 return hres;
269 /*************************************************************************
270 * SHCLSIDFromString [SHELL32.147]
272 * NOTES
273 * exported by ordinal
275 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
277 WCHAR buffer[40];
278 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
279 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
280 return CO_E_CLASSSTRING;
281 return CLSIDFromString( buffer, id );
283 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
285 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
286 return CLSIDFromString((LPWSTR)clsid, id);
288 DWORD WINAPI SHCLSIDFromStringAW (LPVOID clsid, CLSID *id)
290 if (SHELL_OsIsUnicode())
291 return SHCLSIDFromStringW (clsid, id);
292 return SHCLSIDFromStringA (clsid, id);
295 /*************************************************************************
296 * Shell Memory Allocator
299 /* set the vtable later */
300 extern ICOM_VTABLE(IMalloc) VT_Shell_IMalloc32;
302 /* this is the static object instance */
303 typedef struct {
304 ICOM_VFIELD(IMalloc);
305 DWORD dummy;
306 } _ShellMalloc;
308 _ShellMalloc Shell_Malloc = { &VT_Shell_IMalloc32,1};
310 /* this is the global allocator of shell32 */
311 IMalloc * ShellTaskAllocator = NULL;
313 /******************************************************************************
314 * IShellMalloc_QueryInterface [VTABLE]
316 static HRESULT WINAPI IShellMalloc_fnQueryInterface(LPMALLOC iface, REFIID refiid, LPVOID *obj)
318 TRACE("(%s,%p)\n",shdebugstr_guid(refiid),obj);
319 if (IsEqualIID(refiid, &IID_IUnknown) || IsEqualIID(refiid, &IID_IMalloc)) {
320 *obj = (LPMALLOC) &Shell_Malloc;
321 return S_OK;
323 return E_NOINTERFACE;
326 /******************************************************************************
327 * IShellMalloc_AddRefRelease [VTABLE]
329 static ULONG WINAPI IShellMalloc_fnAddRefRelease(LPMALLOC iface)
331 return 1;
334 /******************************************************************************
335 * IShellMalloc_Alloc [VTABLE]
337 static LPVOID WINAPI IShellMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
339 LPVOID addr;
341 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
342 TRACE("(%p,%ld);\n",addr,cb);
343 return addr;
346 /******************************************************************************
347 * IShellMalloc_Realloc [VTABLE]
349 static LPVOID WINAPI IShellMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
351 LPVOID addr;
353 if (pv) {
354 if (cb) {
355 addr = (LPVOID) LocalReAlloc((HANDLE) pv, cb, GMEM_ZEROINIT | GMEM_MOVEABLE);
356 } else {
357 LocalFree((HANDLE) pv);
358 addr = NULL;
360 } else {
361 if (cb) {
362 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
363 } else {
364 addr = NULL;
368 TRACE("(%p->%p,%ld)\n",pv,addr,cb);
369 return addr;
372 /******************************************************************************
373 * IShellMalloc_Free [VTABLE]
375 static VOID WINAPI IShellMalloc_fnFree(LPMALLOC iface, LPVOID pv)
377 TRACE("(%p)\n",pv);
378 LocalFree((HANDLE) pv);
381 /******************************************************************************
382 * IShellMalloc_GetSize [VTABLE]
384 static DWORD WINAPI IShellMalloc_fnGetSize(LPMALLOC iface, LPVOID pv)
386 DWORD cb = (DWORD) LocalSize((HANDLE)pv);
387 TRACE("(%p,%ld)\n", pv, cb);
388 return cb;
391 /******************************************************************************
392 * IShellMalloc_DidAlloc [VTABLE]
394 static INT WINAPI IShellMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
396 TRACE("(%p)\n",pv);
397 return -1;
400 /******************************************************************************
401 * IShellMalloc_HeapMinimize [VTABLE]
403 static VOID WINAPI IShellMalloc_fnHeapMinimize(LPMALLOC iface)
405 TRACE("()\n");
408 static ICOM_VTABLE(IMalloc) VT_Shell_IMalloc32 =
410 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
411 IShellMalloc_fnQueryInterface,
412 IShellMalloc_fnAddRefRelease,
413 IShellMalloc_fnAddRefRelease,
414 IShellMalloc_fnAlloc,
415 IShellMalloc_fnRealloc,
416 IShellMalloc_fnFree,
417 IShellMalloc_fnGetSize,
418 IShellMalloc_fnDidAlloc,
419 IShellMalloc_fnHeapMinimize
422 /*************************************************************************
423 * SHGetMalloc [SHELL32.@]
425 * Return the shell IMalloc interface.
427 * PARAMS
428 * lpmal [O] Destination for IMalloc interface.
430 * RETURNS
431 * Success: S_OK. lpmal contains the shells IMalloc interface.
432 * Failure. An HRESULT error code.
434 * NOTES
435 * This function will use CoGetMalloc() if OLE32.DLL is already loaded.
436 * If not it uses an internal implementation as a fallback.
438 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
440 HRESULT (WINAPI *pCoGetMalloc)(DWORD,LPMALLOC *);
441 HMODULE hOle32;
443 TRACE("(%p)\n", lpmal);
445 if (!ShellTaskAllocator)
447 hOle32 = GetModuleHandleA("OLE32.DLL");
448 if(hOle32) {
449 pCoGetMalloc = (void*) GetProcAddress(hOle32, "CoGetMalloc");
450 if (pCoGetMalloc) pCoGetMalloc(MEMCTX_TASK, &ShellTaskAllocator);
451 TRACE("got ole32 IMalloc\n");
453 if(!ShellTaskAllocator) {
454 ShellTaskAllocator = (IMalloc* ) &Shell_Malloc;
455 TRACE("use fallback allocator\n");
458 *lpmal = ShellTaskAllocator;
459 return S_OK;
462 /*************************************************************************
463 * SHAlloc [SHELL32.196]
465 * NOTES
466 * exported by ordinal
468 LPVOID WINAPI SHAlloc(DWORD len)
470 IMalloc * ppv;
471 LPBYTE ret;
473 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
475 ret = (LPVOID) IMalloc_Alloc(ShellTaskAllocator, len);
476 TRACE("%lu bytes at %p\n",len, ret);
477 return (LPVOID)ret;
480 /*************************************************************************
481 * SHFree [SHELL32.195]
483 * NOTES
484 * exported by ordinal
486 void WINAPI SHFree(LPVOID pv)
488 IMalloc * ppv;
490 TRACE("%p\n",pv);
491 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
492 IMalloc_Free(ShellTaskAllocator, pv);
495 /*************************************************************************
496 * SHGetDesktopFolder [SHELL32.@]
498 DWORD WINAPI SHGetDesktopFolder(IShellFolder **psf)
500 HRESULT hres = S_OK;
501 TRACE("\n");
503 if(!psf) return E_INVALIDARG;
504 *psf = NULL;
505 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder,(LPVOID*)psf);
507 TRACE("-- %p->(%p)\n",psf, *psf);
508 return hres;
510 /**************************************************************************
511 * Default ClassFactory Implementation
513 * SHCreateDefClassObject
515 * NOTES
516 * helper function for dll's without a own classfactory
517 * a generic classfactory is returned
518 * when the CreateInstance of the cf is called the callback is executed
521 typedef struct
523 ICOM_VFIELD(IClassFactory);
524 DWORD ref;
525 CLSID *rclsid;
526 LPFNCREATEINSTANCE lpfnCI;
527 const IID * riidInst;
528 ULONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
529 } IDefClFImpl;
531 static ICOM_VTABLE(IClassFactory) dclfvt;
533 /**************************************************************************
534 * IDefClF_fnConstructor
537 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
539 IDefClFImpl* lpclf;
541 lpclf = (IDefClFImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
542 lpclf->ref = 1;
543 lpclf->lpVtbl = &dclfvt;
544 lpclf->lpfnCI = lpfnCI;
545 lpclf->pcRefDll = pcRefDll;
547 if (pcRefDll) InterlockedIncrement(pcRefDll);
548 lpclf->riidInst = riidInst;
550 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
551 return (LPCLASSFACTORY)lpclf;
553 /**************************************************************************
554 * IDefClF_fnQueryInterface
556 static HRESULT WINAPI IDefClF_fnQueryInterface(
557 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
559 ICOM_THIS(IDefClFImpl,iface);
561 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
563 *ppvObj = NULL;
565 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
566 *ppvObj = This;
567 InterlockedIncrement(&This->ref);
568 return S_OK;
571 TRACE("-- E_NOINTERFACE\n");
572 return E_NOINTERFACE;
574 /******************************************************************************
575 * IDefClF_fnAddRef
577 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
579 ICOM_THIS(IDefClFImpl,iface);
580 TRACE("(%p)->(count=%lu)\n",This,This->ref);
582 return InterlockedIncrement(&This->ref);
584 /******************************************************************************
585 * IDefClF_fnRelease
587 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
589 ICOM_THIS(IDefClFImpl,iface);
590 TRACE("(%p)->(count=%lu)\n",This,This->ref);
592 if (!InterlockedDecrement(&This->ref))
594 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
596 TRACE("-- destroying IClassFactory(%p)\n",This);
597 HeapFree(GetProcessHeap(),0,This);
598 return 0;
600 return This->ref;
602 /******************************************************************************
603 * IDefClF_fnCreateInstance
605 static HRESULT WINAPI IDefClF_fnCreateInstance(
606 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
608 ICOM_THIS(IDefClFImpl,iface);
610 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
612 *ppvObject = NULL;
614 if ( This->riidInst==NULL ||
615 IsEqualCLSID(riid, This->riidInst) ||
616 IsEqualCLSID(riid, &IID_IUnknown) )
618 return This->lpfnCI(pUnkOuter, riid, ppvObject);
621 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
622 return E_NOINTERFACE;
624 /******************************************************************************
625 * IDefClF_fnLockServer
627 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
629 ICOM_THIS(IDefClFImpl,iface);
630 TRACE("%p->(0x%x), not implemented\n",This, fLock);
631 return E_NOTIMPL;
634 static ICOM_VTABLE(IClassFactory) dclfvt =
636 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
637 IDefClF_fnQueryInterface,
638 IDefClF_fnAddRef,
639 IDefClF_fnRelease,
640 IDefClF_fnCreateInstance,
641 IDefClF_fnLockServer
644 /******************************************************************************
645 * SHCreateDefClassObject [SHELL32.70]
647 HRESULT WINAPI SHCreateDefClassObject(
648 REFIID riid,
649 LPVOID* ppv,
650 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
651 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
652 REFIID riidInst) /* [in] optional interface to the instance */
654 IClassFactory * pcf;
656 TRACE("%s %p %p %p %s\n",
657 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
659 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
660 if (! (pcf = IDefClF_fnConstructor(lpfnCI, pcRefDll, riidInst))) return E_OUTOFMEMORY;
661 *ppv = pcf;
662 return NOERROR;
665 /*************************************************************************
666 * DragAcceptFiles [SHELL32.54]
668 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
670 LONG exstyle;
672 if( !IsWindow(hWnd) ) return;
673 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
674 if (b)
675 exstyle |= WS_EX_ACCEPTFILES;
676 else
677 exstyle &= ~WS_EX_ACCEPTFILES;
678 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
681 /*************************************************************************
682 * DragFinish [SHELL32.80]
684 void WINAPI DragFinish(HDROP h)
686 TRACE("\n");
687 GlobalFree((HGLOBAL)h);
690 /*************************************************************************
691 * DragQueryPoint [SHELL32.135]
693 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
695 DROPFILES *lpDropFileStruct;
696 BOOL bRet;
698 TRACE("\n");
700 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
702 *p = lpDropFileStruct->pt;
703 bRet = lpDropFileStruct->fNC;
705 GlobalUnlock(hDrop);
706 return bRet;
709 /*************************************************************************
710 * DragQueryFile [SHELL32.81]
711 * DragQueryFileA [SHELL32.82]
713 UINT WINAPI DragQueryFileA(
714 HDROP hDrop,
715 UINT lFile,
716 LPSTR lpszFile,
717 UINT lLength)
719 LPSTR lpDrop;
720 UINT i = 0;
721 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
723 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
725 if(!lpDropFileStruct) goto end;
727 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
729 if(lpDropFileStruct->fWide == TRUE) {
730 LPWSTR lpszFileW = NULL;
732 if(lpszFile) {
733 lpszFileW = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
734 if(lpszFileW == NULL) {
735 goto end;
738 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
740 if(lpszFileW) {
741 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
742 HeapFree(GetProcessHeap(), 0, lpszFileW);
744 goto end;
747 while (i++ < lFile)
749 while (*lpDrop++); /* skip filename */
750 if (!*lpDrop)
752 i = (lFile == 0xFFFFFFFF) ? i : 0;
753 goto end;
757 i = strlen(lpDrop);
758 i++;
759 if (!lpszFile ) goto end; /* needed buffer size */
760 i = (lLength > i) ? i : lLength;
761 lstrcpynA (lpszFile, lpDrop, i);
762 end:
763 GlobalUnlock(hDrop);
764 return i;
767 /*************************************************************************
768 * DragQueryFileW [SHELL32.133]
770 UINT WINAPI DragQueryFileW(
771 HDROP hDrop,
772 UINT lFile,
773 LPWSTR lpszwFile,
774 UINT lLength)
776 LPWSTR lpwDrop;
777 UINT i = 0;
778 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
780 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
782 if(!lpDropFileStruct) goto end;
784 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
786 if(lpDropFileStruct->fWide == FALSE) {
787 LPSTR lpszFileA = NULL;
789 if(lpszwFile) {
790 lpszFileA = (LPSTR) HeapAlloc(GetProcessHeap(), 0, lLength);
791 if(lpszFileA == NULL) {
792 goto end;
795 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
797 if(lpszFileA) {
798 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
799 HeapFree(GetProcessHeap(), 0, lpszFileA);
801 goto end;
804 i = 0;
805 while (i++ < lFile)
807 while (*lpwDrop++); /* skip filename */
808 if (!*lpwDrop)
810 i = (lFile == 0xFFFFFFFF) ? i : 0;
811 goto end;
815 i = strlenW(lpwDrop);
816 i++;
817 if ( !lpszwFile) goto end; /* needed buffer size */
819 i = (lLength > i) ? i : lLength;
820 lstrcpynW (lpszwFile, lpwDrop, i);
821 end:
822 GlobalUnlock(hDrop);
823 return i;