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
)
125 TRACE("(%p(%s) %p)\n", clsid
, clsid
, id
);
126 return CLSIDFromString16(clsid
, id
);
128 DWORD WINAPI
SHCLSIDFromStringW (LPWSTR clsid
, CLSID
*id
)
130 TRACE("(%p(%s) %p)\n", clsid
, debugstr_w(clsid
), id
);
131 return CLSIDFromString(clsid
, id
);
133 DWORD WINAPI
SHCLSIDFromStringAW (LPVOID clsid
, CLSID
*id
)
135 if (VERSION_OsIsUnicode())
136 return SHCLSIDFromStringW (clsid
, id
);
137 return SHCLSIDFromStringA (clsid
, id
);
140 /*************************************************************************
141 * SHGetMalloc [SHELL32.220]
142 * returns the interface to shell malloc.
144 * [SDK header win95/shlobj.h:
145 * equivalent to: #define SHGetMalloc(ppmem) CoGetMalloc(MEMCTX_TASK, ppmem)
147 * What we are currently doing is not very wrong, since we always use the same
148 * heap (ProcessHeap).
150 DWORD WINAPI
SHGetMalloc(LPMALLOC
*lpmal
)
152 TRACE("(%p)\n", lpmal
);
153 return CoGetMalloc(0,lpmal
);
156 /*************************************************************************
157 * SHGetDesktopFolder [SHELL32.216]
159 LPSHELLFOLDER pdesktopfolder
=NULL
;
161 DWORD WINAPI
SHGetDesktopFolder(IShellFolder
**psf
)
164 LPCLASSFACTORY lpclf
;
165 TRACE("%p->(%p)\n",psf
,*psf
);
171 lpclf
= IClassFactory_Constructor(&CLSID_ShellDesktop
);
174 hres
= IClassFactory_CreateInstance(lpclf
,NULL
,(REFIID
)&IID_IShellFolder
, (void*)&pdesktopfolder
);
175 IClassFactory_Release(lpclf
);
181 /* even if we create the folder, add a ref so the application canĀ“t destroy the folder*/
182 IShellFolder_AddRef(pdesktopfolder
);
183 *psf
= pdesktopfolder
;
186 TRACE("-- %p->(%p)\n",psf
, *psf
);
190 /**************************************************************************
191 * IClassFactory Implementation
196 /* IUnknown fields */
197 ICOM_VFIELD(IClassFactory
);
202 static ICOM_VTABLE(IClassFactory
) clfvt
;
204 /**************************************************************************
205 * IClassFactory_Constructor
208 LPCLASSFACTORY
IClassFactory_Constructor(REFCLSID rclsid
)
210 IClassFactoryImpl
* lpclf
;
212 lpclf
= (IClassFactoryImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IClassFactoryImpl
));
214 ICOM_VTBL(lpclf
) = &clfvt
;
215 lpclf
->rclsid
= (CLSID
*)rclsid
;
217 TRACE("(%p)->()\n",lpclf
);
219 return (LPCLASSFACTORY
)lpclf
;
221 /**************************************************************************
222 * IClassFactory_QueryInterface
224 static HRESULT WINAPI
IClassFactory_fnQueryInterface(
225 LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppvObj
)
227 ICOM_THIS(IClassFactoryImpl
,iface
);
228 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
232 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
235 else if(IsEqualIID(riid
, &IID_IClassFactory
)) /*IClassFactory*/
236 { *ppvObj
= (IClassFactory
*)This
;
240 { IUnknown_AddRef((LPUNKNOWN
)*ppvObj
);
241 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
244 TRACE("-- Interface: %s E_NOINTERFACE\n", debugstr_guid(riid
));
245 return E_NOINTERFACE
;
247 /******************************************************************************
248 * IClassFactory_AddRef
250 static ULONG WINAPI
IClassFactory_fnAddRef(LPCLASSFACTORY iface
)
252 ICOM_THIS(IClassFactoryImpl
,iface
);
253 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
256 return ++(This
->ref
);
258 /******************************************************************************
259 * IClassFactory_Release
261 static ULONG WINAPI
IClassFactory_fnRelease(LPCLASSFACTORY iface
)
263 ICOM_THIS(IClassFactoryImpl
,iface
);
264 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
268 { TRACE("-- destroying IClassFactory(%p)\n",This
);
269 HeapFree(GetProcessHeap(),0,This
);
274 /******************************************************************************
275 * IClassFactory_CreateInstance
277 static HRESULT WINAPI
IClassFactory_fnCreateInstance(
278 LPCLASSFACTORY iface
, LPUNKNOWN pUnknown
, REFIID riid
, LPVOID
*ppObject
)
280 ICOM_THIS(IClassFactoryImpl
,iface
);
281 IUnknown
*pObj
= NULL
;
284 TRACE("%p->(%p,\n\tIID:\t%s,%p)\n",This
,pUnknown
,debugstr_guid(riid
),ppObject
);
290 return(CLASS_E_NOAGGREGATION
);
293 if (IsEqualCLSID(This
->rclsid
, &CLSID_ShellDesktop
))
295 pObj
= (IUnknown
*)ISF_Desktop_Constructor();
297 else if (IsEqualCLSID(This
->rclsid
, &CLSID_ShellLink
))
299 pObj
= (IUnknown
*)IShellLink_Constructor(FALSE
);
303 ERR("unknown IID requested\n\tIID:\t%s\n",debugstr_guid(riid
));
304 return(E_NOINTERFACE
);
309 return(E_OUTOFMEMORY
);
312 hres
= IUnknown_QueryInterface(pObj
,riid
, ppObject
);
313 IUnknown_Release(pObj
);
315 TRACE("-- Object created: (%p)->%p\n",This
,*ppObject
);
319 /******************************************************************************
320 * IClassFactory_LockServer
322 static HRESULT WINAPI
IClassFactory_fnLockServer(LPCLASSFACTORY iface
, BOOL fLock
)
324 ICOM_THIS(IClassFactoryImpl
,iface
);
325 TRACE("%p->(0x%x), not implemented\n",This
, fLock
);
329 static ICOM_VTABLE(IClassFactory
) clfvt
=
331 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
332 IClassFactory_fnQueryInterface
,
333 IClassFactory_fnAddRef
,
334 IClassFactory_fnRelease
,
335 IClassFactory_fnCreateInstance
,
336 IClassFactory_fnLockServer
339 /**************************************************************************
340 * Default ClassFactory Implementation
342 * SHCreateDefClassObject
345 * helper function for dll's without a own classfactory
346 * a generic classfactory is returned
347 * when the CreateInstance of the cf is called the callback is executed
349 typedef HRESULT (CALLBACK
* LPFNCREATEINSTANCE
)(IUnknown
* pUnkOuter
, REFIID riid
, LPVOID
* ppvObject
);
353 ICOM_VFIELD(IClassFactory
);
356 LPFNCREATEINSTANCE lpfnCI
;
357 const IID
* riidInst
;
358 UINT
* pcRefDll
; /* pointer to refcounter in external dll (ugrrr...) */
361 static ICOM_VTABLE(IClassFactory
) dclfvt
;
363 /**************************************************************************
364 * IDefClF_fnConstructor
367 IClassFactory
* IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI
, UINT
* pcRefDll
, REFIID riidInst
)
371 lpclf
= (IDefClFImpl
*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl
));
373 ICOM_VTBL(lpclf
) = &dclfvt
;
374 lpclf
->lpfnCI
= lpfnCI
;
375 lpclf
->pcRefDll
= pcRefDll
;
380 lpclf
->riidInst
= riidInst
;
382 TRACE("(%p)\n\tIID:\t%s\n",lpclf
, debugstr_guid(riidInst
));
384 return (LPCLASSFACTORY
)lpclf
;
386 /**************************************************************************
387 * IDefClF_fnQueryInterface
389 static HRESULT WINAPI
IDefClF_fnQueryInterface(
390 LPCLASSFACTORY iface
, REFIID riid
, LPVOID
*ppvObj
)
392 ICOM_THIS(IDefClFImpl
,iface
);
394 TRACE("(%p)->(\n\tIID:\t%s)\n",This
,debugstr_guid(riid
));
398 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
401 else if(IsEqualIID(riid
, &IID_IClassFactory
)) /*IClassFactory*/
402 { *ppvObj
= (IClassFactory
*)This
;
406 { IUnknown_AddRef((LPUNKNOWN
)*ppvObj
);
407 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
410 TRACE("-- Interface: %s E_NOINTERFACE\n", debugstr_guid(riid
));
411 return E_NOINTERFACE
;
413 /******************************************************************************
416 static ULONG WINAPI
IDefClF_fnAddRef(LPCLASSFACTORY iface
)
418 ICOM_THIS(IDefClFImpl
,iface
);
419 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
423 return ++(This
->ref
);
425 /******************************************************************************
428 static ULONG WINAPI
IDefClF_fnRelease(LPCLASSFACTORY iface
)
430 ICOM_THIS(IDefClFImpl
,iface
);
431 TRACE("(%p)->(count=%lu)\n",This
,This
->ref
);
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 UINT
*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
;