Release 20030408.
[wine/gsoc-2012-control.git] / dlls / shell32 / shellole.c
blobf1b4f059949eca87e318be2bff7f8952b903be58
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 <stdlib.h>
25 #include <string.h>
27 #include "shellapi.h"
28 #include "shlobj.h"
29 #include "shlguid.h"
30 #include "winreg.h"
31 #include "winerror.h"
33 #include "undocshell.h"
34 #include "wine/unicode.h"
35 #include "shell32_main.h"
37 #include "wine/debug.h"
38 #include "shlwapi.h"
39 #include "winuser.h"
40 #include "debughlp.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 */
58 struct {
59 REFIID riid;
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},
67 {NULL,NULL}
70 /*************************************************************************
71 * __CoCreateInstance [internal]
73 * NOTES
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);
84 return NULL;
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]
97 * NOTES
98 * exported by ordinal
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',
110 '}','\0'};
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(
122 LPCSTR aclsid,
123 REFCLSID clsid,
124 LPUNKNOWN pUnkOuter,
125 REFIID refiid,
126 LPVOID *ppv)
128 DWORD hres;
129 IID iid;
130 CLSID * myclsid = (CLSID*)clsid;
131 WCHAR sKeyName[MAX_PATH];
132 const WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
133 WCHAR sClassID[60];
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];
137 HKEY hKey;
138 DWORD dwSize;
139 BOOLEAN bLoadFromShell32 = FALSE;
140 BOOLEAN bLoadWithoutCOM = FALSE;
141 IClassFactory * pcf = NULL;
143 if(!ppv) return E_POINTER;
144 *ppv=NULL;
146 /* if the clsid is a string, convert it */
147 if (!clsid)
149 if (!aclsid) return REGDB_E_CLASSNOTREG;
150 SHCLSIDFromStringA(aclsid, &iid);
151 myclsid = &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));
173 RegCloseKey (hKey);
174 } else {
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 */
189 HANDLE hLibrary;
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;
196 goto end;
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;
201 goto end;
202 } else if (! SUCCEEDED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
203 TRACE("GetClassObject failed 0x%08lx\n", hres);
204 goto end;
207 } else {
209 /* load a external dll in the usual way */
210 hres = __CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
211 goto end;
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);
219 end:
220 if(hres!=S_OK)
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);
228 return hres;
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;
238 int i;
240 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
242 if (!ppv) return E_INVALIDARG;
243 *ppv = NULL;
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);
253 if (!pcf) {
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);
262 return hres;
265 /*************************************************************************
266 * SHCLSIDFromString [SHELL32.147]
268 * NOTES
269 * exported by ordinal
271 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
273 WCHAR buffer[40];
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 */
299 typedef struct {
300 ICOM_VFIELD(IMalloc);
301 DWORD dummy;
302 } _ShellMalloc;
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;
317 return S_OK;
319 return E_NOINTERFACE;
322 /******************************************************************************
323 * IShellMalloc_AddRefRelease [VTABLE]
325 static ULONG WINAPI IShellMalloc_fnAddRefRelease(LPMALLOC iface)
327 return 1;
330 /******************************************************************************
331 * IShellMalloc_Alloc [VTABLE]
333 static LPVOID WINAPI IShellMalloc_fnAlloc(LPMALLOC iface, DWORD cb)
335 LPVOID addr;
337 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
338 TRACE("(%p,%ld);\n",addr,cb);
339 return addr;
342 /******************************************************************************
343 * IShellMalloc_Realloc [VTABLE]
345 static LPVOID WINAPI IShellMalloc_fnRealloc(LPMALLOC iface, LPVOID pv, DWORD cb)
347 LPVOID addr;
349 if (pv) {
350 if (cb) {
351 addr = (LPVOID) LocalReAlloc((HANDLE) pv, cb, GMEM_ZEROINIT | GMEM_MOVEABLE);
352 } else {
353 LocalFree((HANDLE) pv);
354 addr = NULL;
356 } else {
357 if (cb) {
358 addr = (LPVOID) LocalAlloc(GMEM_ZEROINIT, cb);
359 } else {
360 addr = NULL;
364 TRACE("(%p->%p,%ld)\n",pv,addr,cb);
365 return addr;
368 /******************************************************************************
369 * IShellMalloc_Free [VTABLE]
371 static VOID WINAPI IShellMalloc_fnFree(LPMALLOC iface, LPVOID pv)
373 TRACE("(%p)\n",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);
384 return cb;
387 /******************************************************************************
388 * IShellMalloc_DidAlloc [VTABLE]
390 static INT WINAPI IShellMalloc_fnDidAlloc(LPMALLOC iface, LPVOID pv)
392 TRACE("(%p)\n",pv);
393 return -1;
396 /******************************************************************************
397 * IShellMalloc_HeapMinimize [VTABLE]
399 static VOID WINAPI IShellMalloc_fnHeapMinimize(LPMALLOC iface)
401 TRACE("()\n");
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,
412 IShellMalloc_fnFree,
413 IShellMalloc_fnGetSize,
414 IShellMalloc_fnDidAlloc,
415 IShellMalloc_fnHeapMinimize
418 /*************************************************************************
419 * SHGetMalloc [SHELL32.@]
421 * Return the shell IMalloc interface.
423 * PARAMS
424 * lpmal [O] Destination for IMalloc interface.
426 * RETURNS
427 * Success: S_OK. lpmal contains the shells IMalloc interface.
428 * Failure. An HRESULT error code.
430 * NOTES
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 *);
437 HMODULE hOle32;
439 TRACE("(%p)\n", lpmal);
441 if (!ShellTaskAllocator)
443 hOle32 = GetModuleHandleA("OLE32.DLL");
444 if(hOle32) {
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;
455 return S_OK;
458 /*************************************************************************
459 * SHAlloc [SHELL32.196]
461 * NOTES
462 * exported by ordinal
464 LPVOID WINAPI SHAlloc(DWORD len)
466 IMalloc * ppv;
467 LPBYTE ret;
469 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
471 ret = (LPVOID) IMalloc_Alloc(ShellTaskAllocator, len);
472 TRACE("%lu bytes at %p\n",len, ret);
473 return (LPVOID)ret;
476 /*************************************************************************
477 * SHFree [SHELL32.195]
479 * NOTES
480 * exported by ordinal
482 void WINAPI SHFree(LPVOID pv)
484 IMalloc * ppv;
486 TRACE("%p\n",pv);
487 if (!ShellTaskAllocator) SHGetMalloc(&ppv);
488 IMalloc_Free(ShellTaskAllocator, pv);
491 /*************************************************************************
492 * SHGetDesktopFolder [SHELL32.@]
494 DWORD WINAPI SHGetDesktopFolder(IShellFolder **psf)
496 HRESULT hres = S_OK;
497 TRACE("\n");
499 if(!psf) return E_INVALIDARG;
500 *psf = NULL;
501 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder,(LPVOID*)psf);
503 TRACE("-- %p->(%p)\n",psf, *psf);
504 return hres;
506 /**************************************************************************
507 * Default ClassFactory Implementation
509 * SHCreateDefClassObject
511 * NOTES
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
517 typedef struct
519 ICOM_VFIELD(IClassFactory);
520 DWORD ref;
521 CLSID *rclsid;
522 LPFNCREATEINSTANCE lpfnCI;
523 const IID * riidInst;
524 ULONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
525 } IDefClFImpl;
527 static ICOM_VTABLE(IClassFactory) dclfvt;
529 /**************************************************************************
530 * IDefClF_fnConstructor
533 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
535 IDefClFImpl* lpclf;
537 lpclf = (IDefClFImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
538 lpclf->ref = 1;
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));
559 *ppvObj = NULL;
561 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
562 *ppvObj = This;
563 InterlockedIncrement(&This->ref);
564 return S_OK;
567 TRACE("-- E_NOINTERFACE\n");
568 return E_NOINTERFACE;
570 /******************************************************************************
571 * IDefClF_fnAddRef
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 /******************************************************************************
581 * IDefClF_fnRelease
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);
594 return 0;
596 return This->ref;
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);
608 *ppvObject = NULL;
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);
627 return E_NOTIMPL;
630 static ICOM_VTABLE(IClassFactory) dclfvt =
632 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
633 IDefClF_fnQueryInterface,
634 IDefClF_fnAddRef,
635 IDefClF_fnRelease,
636 IDefClF_fnCreateInstance,
637 IDefClF_fnLockServer
640 /******************************************************************************
641 * SHCreateDefClassObject [SHELL32.70]
643 HRESULT WINAPI SHCreateDefClassObject(
644 REFIID riid,
645 LPVOID* ppv,
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 */
650 IClassFactory * pcf;
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;
657 *ppv = pcf;
658 return NOERROR;
661 /*************************************************************************
662 * DragAcceptFiles [SHELL32.54]
664 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
666 LONG exstyle;
668 if( !IsWindow(hWnd) ) return;
669 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
670 if (b)
671 exstyle |= WS_EX_ACCEPTFILES;
672 else
673 exstyle &= ~WS_EX_ACCEPTFILES;
674 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
677 /*************************************************************************
678 * DragFinish [SHELL32.80]
680 void WINAPI DragFinish(HDROP h)
682 TRACE("\n");
683 GlobalFree((HGLOBAL)h);
686 /*************************************************************************
687 * DragQueryPoint [SHELL32.135]
689 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
691 DROPFILES *lpDropFileStruct;
692 BOOL bRet;
694 TRACE("\n");
696 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
698 *p = lpDropFileStruct->pt;
699 bRet = lpDropFileStruct->fNC;
701 GlobalUnlock(hDrop);
702 return bRet;
705 /*************************************************************************
706 * DragQueryFile [SHELL32.81]
707 * DragQueryFileA [SHELL32.82]
709 UINT WINAPI DragQueryFileA(
710 HDROP hDrop,
711 UINT lFile,
712 LPSTR lpszFile,
713 UINT lLength)
715 LPSTR lpDrop;
716 UINT i = 0;
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;
728 if(lpszFile) {
729 lpszFileW = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
730 if(lpszFileW == NULL) {
731 goto end;
734 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
736 if(lpszFileW) {
737 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
738 HeapFree(GetProcessHeap(), 0, lpszFileW);
740 goto end;
743 while (i++ < lFile)
745 while (*lpDrop++); /* skip filename */
746 if (!*lpDrop)
748 i = (lFile == 0xFFFFFFFF) ? i : 0;
749 goto end;
753 i = strlen(lpDrop);
754 i++;
755 if (!lpszFile ) goto end; /* needed buffer size */
756 i = (lLength > i) ? i : lLength;
757 lstrcpynA (lpszFile, lpDrop, i);
758 end:
759 GlobalUnlock(hDrop);
760 return i;
763 /*************************************************************************
764 * DragQueryFileW [SHELL32.133]
766 UINT WINAPI DragQueryFileW(
767 HDROP hDrop,
768 UINT lFile,
769 LPWSTR lpszwFile,
770 UINT lLength)
772 LPWSTR lpwDrop;
773 UINT i = 0;
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;
785 if(lpszwFile) {
786 lpszFileA = (LPSTR) HeapAlloc(GetProcessHeap(), 0, lLength);
787 if(lpszFileA == NULL) {
788 goto end;
791 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
793 if(lpszFileA) {
794 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
795 HeapFree(GetProcessHeap(), 0, lpszFileA);
797 goto end;
800 i = 0;
801 while (i++ < lFile)
803 while (*lpwDrop++); /* skip filename */
804 if (!*lpwDrop)
806 i = (lFile == 0xFFFFFFFF) ? i : 0;
807 goto end;
811 i = strlenW(lpwDrop);
812 i++;
813 if ( !lpszwFile) goto end; /* needed buffer size */
815 i = (lLength > i) ? i : lLength;
816 lstrcpynW (lpszwFile, lpwDrop, i);
817 end:
818 GlobalUnlock(hDrop);
819 return i;