2 * handling of SHELL32.DLL OLE-Objects
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
12 #include "wine/obj_base.h"
13 #include "wine/obj_shelllink.h"
14 #include "wine/obj_shellfolder.h"
15 #include "wine/obj_shellbrowser.h"
16 #include "wine/obj_contextmenu.h"
17 #include "wine/obj_shellextinit.h"
18 #include "wine/obj_extracticon.h"
21 #include "winversion.h"
24 #include "debugtools.h"
26 #include "shell32_main.h"
28 DEFAULT_DEBUG_CHANNEL(shell
)
30 DWORD WINAPI
SHCLSIDFromStringA (LPSTR clsid
, CLSID
*id
);
31 extern IShellFolder
* IShellFolder_Constructor(
34 extern HRESULT
IFSFolder_Constructor(
39 /*************************************************************************
40 * SHCoCreateInstance [SHELL32.102]
45 LRESULT WINAPI
SHCoCreateInstance(
48 IUnknown
* unknownouter
,
54 CLSID
* myclsid
= (CLSID
*)clsid
;
58 if (!aclsid
) return REGDB_E_CLASSNOTREG
;
59 SHCLSIDFromStringA(aclsid
, &iid
);
63 TRACE("(%p,\n\tCLSID:\t%s, unk:%p\n\tIID:\t%s,%p)\n",
64 aclsid
,debugstr_guid(myclsid
),unknownouter
,debugstr_guid(refiid
),ppv
);
66 if IsEqualCLSID(myclsid
, &CLSID_ShellFSFolder
)
68 hres
= IFSFolder_Constructor(unknownouter
, refiid
, ppv
);
72 hres
= CoCreateInstance(myclsid
, unknownouter
, CLSCTX_INPROC_SERVER
, refiid
, ppv
);
77 ERR("failed (0x%08lx) to create \n\tCLSID:\t%s\n\tIID:\t%s\n",
78 hres
, debugstr_guid(myclsid
), debugstr_guid(refiid
));
79 ERR("class not found in registry\n");
82 TRACE("-- instance: %p\n",*ppv
);
86 /*************************************************************************
87 * SHELL32_DllGetClassObject [SHELL32.128]
89 HRESULT WINAPI
SHELL32_DllGetClassObject(REFCLSID rclsid
, REFIID iid
,LPVOID
*ppv
)
90 { HRESULT hres
= E_OUTOFMEMORY
;
93 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid
),debugstr_guid(iid
));
97 if(IsEqualCLSID(rclsid
, &CLSID_ShellDesktop
)||
98 IsEqualCLSID(rclsid
, &CLSID_ShellLink
))
100 lpclf
= IClassFactory_Constructor( rclsid
);
104 hres
= IClassFactory_QueryInterface(lpclf
,iid
, ppv
);
105 IClassFactory_Release(lpclf
);
110 WARN("-- CLSID not found\n");
111 hres
= CLASS_E_CLASSNOTAVAILABLE
;
113 TRACE("-- pointer to class factory: %p\n",*ppv
);
117 /*************************************************************************
118 * SHCLSIDFromString [SHELL32.147]
121 * exported by ordinal
123 DWORD WINAPI
SHCLSIDFromStringA (LPSTR clsid
, CLSID
*id
)
126 TRACE("(%p(%s) %p)\n", clsid
, clsid
, id
);
127 if (!MultiByteToWideChar( CP_ACP
, 0, clsid
, -1, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
128 return CO_E_CLASSSTRING
;
129 return CLSIDFromString( buffer
, id
);
131 DWORD WINAPI
SHCLSIDFromStringW (LPWSTR clsid
, CLSID
*id
)
133 TRACE("(%p(%s) %p)\n", clsid
, debugstr_w(clsid
), id
);
134 return CLSIDFromString(clsid
, id
);
136 DWORD WINAPI
SHCLSIDFromStringAW (LPVOID clsid
, CLSID
*id
)
138 if (VERSION_OsIsUnicode())
139 return SHCLSIDFromStringW (clsid
, id
);
140 return SHCLSIDFromStringA (clsid
, id
);
143 /*************************************************************************
144 * SHGetMalloc [SHELL32.220]
145 * returns the interface to shell malloc.
147 * [SDK header win95/shlobj.h:
148 * equivalent to: #define SHGetMalloc(ppmem) CoGetMalloc(MEMCTX_TASK, ppmem)
150 * What we are currently doing is not very wrong, since we always use the same
151 * heap (ProcessHeap).
153 DWORD WINAPI
SHGetMalloc(LPMALLOC
*lpmal
)
155 TRACE("(%p)\n", lpmal
);
156 return CoGetMalloc(0,lpmal
);
159 /*************************************************************************
160 * SHGetDesktopFolder [SHELL32.216]
162 LPSHELLFOLDER pdesktopfolder
=NULL
;
164 DWORD WINAPI
SHGetDesktopFolder(IShellFolder
**psf
)
167 LPCLASSFACTORY lpclf
;
168 TRACE("%p->(%p)\n",psf
,*psf
);
174 lpclf
= IClassFactory_Constructor(&CLSID_ShellDesktop
);
177 hres
= IClassFactory_CreateInstance(lpclf
,NULL
,(REFIID
)&IID_IShellFolder
, (void*)&pdesktopfolder
);
178 IClassFactory_Release(lpclf
);
184 /* even if we create the folder, add a ref so the application canĀ“t destroy the folder*/
185 IShellFolder_AddRef(pdesktopfolder
);
186 *psf
= pdesktopfolder
;
189 TRACE("-- %p->(%p)\n",psf
, *psf
);
193 /**************************************************************************
194 * IClassFactory Implementation
199 /* IUnknown fields */
200 ICOM_VFIELD(IClassFactory
);
205 static ICOM_VTABLE(IClassFactory
) clfvt
;
207 /**************************************************************************
208 * IClassFactory_Constructor
211 LPCLASSFACTORY
IClassFactory_Constructor(REFCLSID rclsid
)
213 IClassFactoryImpl
* lpclf
;
215 lpclf
= (IClassFactoryImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IClassFactoryImpl
));
217 ICOM_VTBL(lpclf
) = &clfvt
;
218 lpclf
->rclsid
= (CLSID
*)rclsid
;
220 TRACE("(%p)->()\n",lpclf
);
221 InterlockedIncrement(&shell32_ObjCount
);
222 return (LPCLASSFACTORY
)lpclf
;
224 /**************************************************************************
225 * IClassFactory_QueryInterface
227 static HRESULT WINAPI
IClassFactory_fnQueryInterface(
228 LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppvObj
)
230 ICOM_THIS(IClassFactoryImpl
,iface
);
231 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
235 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
238 else if(IsEqualIID(riid
, &IID_IClassFactory
)) /*IClassFactory*/
239 { *ppvObj
= (IClassFactory
*)This
;
243 { IUnknown_AddRef((LPUNKNOWN
)*ppvObj
);
244 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
247 TRACE("-- Interface: %s E_NOINTERFACE\n", debugstr_guid(riid
));
248 return E_NOINTERFACE
;
250 /******************************************************************************
251 * IClassFactory_AddRef
253 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
)
255 ICOM_THIS(IClassFactoryImpl
,iface
);
256 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
258 InterlockedIncrement(&shell32_ObjCount
);
259 return InterlockedIncrement(&This
->ref
);
261 /******************************************************************************
262 * IClassFactory_Release
264 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
)
266 ICOM_THIS(IClassFactoryImpl
,iface
);
267 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
269 InterlockedDecrement(&shell32_ObjCount
);
270 if (!InterlockedDecrement(&This
->ref
))
272 TRACE("-- destroying IClassFactory(%p)\n",This
);
273 HeapFree(GetProcessHeap(),0,This
);
278 /******************************************************************************
279 * IClassFactory_CreateInstance
281 static HRESULT WINAPI
IClassFactory_fnCreateInstance(
282 LPCLASSFACTORY iface
, LPUNKNOWN pUnknown
, REFIID riid
, LPVOID
*ppObject
)
284 ICOM_THIS(IClassFactoryImpl
,iface
);
285 IUnknown
*pObj
= NULL
;
288 TRACE("%p->(%p,\n\tIID:\t%s,%p)\n",This
,pUnknown
,debugstr_guid(riid
),ppObject
);
294 return(CLASS_E_NOAGGREGATION
);
297 if (IsEqualCLSID(This
->rclsid
, &CLSID_ShellDesktop
))
299 pObj
= (IUnknown
*)ISF_Desktop_Constructor();
301 else if (IsEqualCLSID(This
->rclsid
, &CLSID_ShellLink
))
303 pObj
= (IUnknown
*)IShellLink_Constructor(FALSE
);
307 ERR("unknown IID requested\n\tIID:\t%s\n",debugstr_guid(riid
));
308 return(E_NOINTERFACE
);
313 return(E_OUTOFMEMORY
);
316 hres
= IUnknown_QueryInterface(pObj
,riid
, ppObject
);
317 IUnknown_Release(pObj
);
319 TRACE("-- Object created: (%p)->%p\n",This
,*ppObject
);
323 /******************************************************************************
324 * IClassFactory_LockServer
326 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
328 ICOM_THIS(IClassFactoryImpl
,iface
);
329 TRACE("%p->(0x%x), not implemented\n",This
, fLock
);
333 static ICOM_VTABLE(IClassFactory
) clfvt
=
335 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
336 IClassFactory_fnQueryInterface
,
337 IClassFactory_fnAddRef
,
338 IClassFactory_fnRelease
,
339 IClassFactory_fnCreateInstance
,
340 IClassFactory_fnLockServer
343 /**************************************************************************
344 * Default ClassFactory Implementation
346 * SHCreateDefClassObject
349 * helper function for dll's without a own classfactory
350 * a generic classfactory is returned
351 * when the CreateInstance of the cf is called the callback is executed
353 typedef HRESULT (CALLBACK
* LPFNCREATEINSTANCE
)(IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppvObject
);
357 ICOM_VFIELD(IClassFactory
);
360 LPFNCREATEINSTANCE lpfnCI
;
361 const IID
* riidInst
;
362 ULONG
* pcRefDll
; /* pointer to refcounter in external dll (ugrrr...) */
365 static ICOM_VTABLE(IClassFactory
) dclfvt
;
367 /**************************************************************************
368 * IDefClF_fnConstructor
371 IClassFactory
* IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI
, PLONG pcRefDll
, REFIID riidInst
)
375 lpclf
= (IDefClFImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl
));
377 ICOM_VTBL(lpclf
) = &dclfvt
;
378 lpclf
->lpfnCI
= lpfnCI
;
379 lpclf
->pcRefDll
= pcRefDll
;
381 if (pcRefDll
) InterlockedIncrement(pcRefDll
);
382 lpclf
->riidInst
= riidInst
;
384 TRACE("(%p)\n\tIID:\t%s\n",lpclf
, debugstr_guid(riidInst
));
385 InterlockedIncrement(&shell32_ObjCount
);
386 return (LPCLASSFACTORY
)lpclf
;
388 /**************************************************************************
389 * IDefClF_fnQueryInterface
391 static HRESULT WINAPI
IDefClF_fnQueryInterface(
392 LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppvObj
)
394 ICOM_THIS(IDefClFImpl
,iface
);
396 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
400 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
403 else if(IsEqualIID(riid
, &IID_IClassFactory
)) /*IClassFactory*/
404 { *ppvObj
= (IClassFactory
*)This
;
408 { IUnknown_AddRef((LPUNKNOWN
)*ppvObj
);
409 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
412 TRACE("-- Interface: %s E_NOINTERFACE\n", debugstr_guid(riid
));
413 return E_NOINTERFACE
;
415 /******************************************************************************
418 static ULONG WINAPI
IDefClF_fnAddRef(LPCLASSFACTORY iface
)
420 ICOM_THIS(IDefClFImpl
,iface
);
421 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
423 InterlockedIncrement(&shell32_ObjCount
);
424 return InterlockedIncrement(&This
->ref
);
426 /******************************************************************************
429 static ULONG WINAPI
IDefClF_fnRelease(LPCLASSFACTORY iface
)
431 ICOM_THIS(IDefClFImpl
,iface
);
432 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
434 InterlockedDecrement(&shell32_ObjCount
);
436 if (!InterlockedDecrement(&This
->ref
))
438 if (This
->pcRefDll
) InterlockedDecrement(This
->pcRefDll
);
440 TRACE("-- destroying IClassFactory(%p)\n",This
);
441 HeapFree(GetProcessHeap(),0,This
);
446 /******************************************************************************
447 * IDefClF_fnCreateInstance
449 static HRESULT WINAPI
IDefClF_fnCreateInstance(
450 LPCLASSFACTORY iface
, LPUNKNOWN pUnkOuter
, REFIID riid
, LPVOID
*ppvObject
)
452 ICOM_THIS(IDefClFImpl
,iface
);
454 TRACE("%p->(%p,\n\tIID:\t%s,%p)\n",This
,pUnkOuter
,debugstr_guid(riid
),ppvObject
);
459 return(CLASS_E_NOAGGREGATION
);
461 if ( This
->riidInst
==NULL
||
462 IsEqualCLSID(riid
, This
->riidInst
) ||
463 IsEqualCLSID(riid
, &IID_IUnknown
) )
465 return This
->lpfnCI(pUnkOuter
, riid
, ppvObject
);
468 ERR("unknown IID requested\n\tIID:\t%s\n",debugstr_guid(riid
));
469 return E_NOINTERFACE
;
471 /******************************************************************************
472 * IDefClF_fnLockServer
474 static HRESULT WINAPI
IDefClF_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
476 ICOM_THIS(IDefClFImpl
,iface
);
477 TRACE("%p->(0x%x), not implemented\n",This
, fLock
);
481 static ICOM_VTABLE(IClassFactory
) dclfvt
=
483 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
484 IDefClF_fnQueryInterface
,
487 IDefClF_fnCreateInstance
,
491 /******************************************************************************
492 * SHCreateDefClassObject [SHELL32.70]
494 HRESULT WINAPI
SHCreateDefClassObject(
497 LPFNCREATEINSTANCE lpfnCI
, /* create instance callback entry */
498 PLONG pcRefDll
, /* ref count of the dll */
499 REFIID riidInst
) /* optional interface to the instance */
501 TRACE("\n\tIID:\t%s %p %p %p \n\tIIDIns:\t%s\n",
502 debugstr_guid(riid
), ppv
, lpfnCI
, pcRefDll
, debugstr_guid(riidInst
));
504 if ( IsEqualCLSID(riid
, &IID_IClassFactory
) )
506 IClassFactory
* pcf
= IDefClF_fnConstructor(lpfnCI
, pcRefDll
, riidInst
);
512 return E_OUTOFMEMORY
;
514 return E_NOINTERFACE
;
517 /*************************************************************************
518 * DragAcceptFiles [SHELL32.54]
520 void WINAPI
DragAcceptFiles(HWND hWnd
, BOOL b
)
524 if( !IsWindow(hWnd
) ) return;
525 exstyle
= GetWindowLongA(hWnd
,GWL_EXSTYLE
);
527 exstyle
|= WS_EX_ACCEPTFILES
;
529 exstyle
&= ~WS_EX_ACCEPTFILES
;
530 SetWindowLongA(hWnd
,GWL_EXSTYLE
,exstyle
);
533 /*************************************************************************
534 * DragFinish [SHELL32.80]
536 void WINAPI
DragFinish(HDROP h
)
539 GlobalFree((HGLOBAL
)h
);
542 /*************************************************************************
543 * DragQueryPoint [SHELL32.135]
545 BOOL WINAPI
DragQueryPoint(HDROP hDrop
, POINT
*p
)
547 LPDROPFILESTRUCT lpDropFileStruct
;
552 lpDropFileStruct
= (LPDROPFILESTRUCT
) GlobalLock(hDrop
);
554 memcpy(p
,&lpDropFileStruct
->ptMousePos
,sizeof(POINT
));
555 bRet
= lpDropFileStruct
->fInNonClientArea
;
561 /*************************************************************************
562 * DragQueryFileA [SHELL32.81] [shell32.82]
564 UINT WINAPI
DragQueryFileA(
572 LPDROPFILESTRUCT lpDropFileStruct
= (LPDROPFILESTRUCT
) GlobalLock(hDrop
);
574 TRACE("(%08x, %x, %p, %u)\n", hDrop
,lFile
,lpszFile
,lLength
);
576 if(!lpDropFileStruct
) goto end
;
578 lpDrop
= (LPSTR
) lpDropFileStruct
+ lpDropFileStruct
->lSize
;
582 while (*lpDrop
++); /* skip filename */
585 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
590 i
= lstrlenA(lpDrop
);
592 if (!lpszFile
) goto end
; /* needed buffer size */
593 i
= (lLength
> i
) ? i
: lLength
;
594 lstrcpynA (lpszFile
, lpDrop
, i
);
600 /*************************************************************************
601 * DragQueryFileW [shell32.133]
603 UINT WINAPI
DragQueryFileW(
611 LPDROPFILESTRUCT lpDropFileStruct
= (LPDROPFILESTRUCT
) GlobalLock(hDrop
);
613 TRACE("(%08x, %x, %p, %u)\n", hDrop
,lFile
,lpszwFile
,lLength
);
615 if(!lpDropFileStruct
) goto end
;
617 lpwDrop
= (LPWSTR
) lpDropFileStruct
+ lpDropFileStruct
->lSize
;
622 while (*lpwDrop
++); /* skip filename */
625 i
= (lFile
== 0xFFFFFFFF) ? i
: 0;
630 i
= lstrlenW(lpwDrop
);
632 if ( !lpszwFile
) goto end
; /* needed buffer size */
634 i
= (lLength
> i
) ? i
: lLength
;
635 lstrcpynW (lpszwFile
, lpwDrop
, i
);