Make RDW_ValidateParent() modify the update region of all parents, not
[wine/multimedia.git] / dlls / shell32 / shellole.c
blobc0aa4817bcd18db76d2111cc03dd7d197fe4e3c1
1 /*
2 * handling of SHELL32.DLL OLE-Objects
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
7 */
9 #include <stdlib.h>
10 #include <string.h>
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"
20 #include "shlguid.h"
21 #include "winversion.h"
22 #include "winreg.h"
23 #include "winerror.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(
32 IShellFolder * psf,
33 LPITEMIDLIST pidl);
34 extern HRESULT IFSFolder_Constructor(
35 IUnknown * pUnkOuter,
36 REFIID riid,
37 LPVOID * ppv);
39 /*************************************************************************
40 * SHCoCreateInstance [SHELL32.102]
42 * NOTES
43 * exported by ordinal
45 LRESULT WINAPI SHCoCreateInstance(
46 LPSTR aclsid,
47 REFCLSID clsid,
48 IUnknown * unknownouter,
49 REFIID refiid,
50 LPVOID *ppv)
52 DWORD hres;
53 IID iid;
54 CLSID * myclsid = (CLSID*)clsid;
56 if (!clsid)
58 if (!aclsid) return REGDB_E_CLASSNOTREG;
59 SHCLSIDFromStringA(aclsid, &iid);
60 myclsid = &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);
70 else
72 hres = CoCreateInstance(myclsid, unknownouter, CLSCTX_INPROC_SERVER, refiid, ppv);
75 if(hres!=S_OK)
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);
83 return hres;
86 /*************************************************************************
87 * SHELL32_DllGetClassObject [SHELL32.128]
89 HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
90 { HRESULT hres = E_OUTOFMEMORY;
91 LPCLASSFACTORY lpclf;
93 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
95 *ppv = NULL;
97 if(IsEqualCLSID(rclsid, &CLSID_ShellDesktop)||
98 IsEqualCLSID(rclsid, &CLSID_ShellLink))
100 lpclf = IClassFactory_Constructor( rclsid );
102 if(lpclf)
104 hres = IClassFactory_QueryInterface(lpclf,iid, ppv);
105 IClassFactory_Release(lpclf);
108 else
110 WARN("-- CLSID not found\n");
111 hres = CLASS_E_CLASSNOTAVAILABLE;
113 TRACE("-- pointer to class factory: %p\n",*ppv);
114 return hres;
117 /*************************************************************************
118 * SHCLSIDFromString [SHELL32.147]
120 * NOTES
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)
163 HRESULT hres = S_OK;
164 LPCLASSFACTORY lpclf;
165 TRACE("%p->(%p)\n",psf,*psf);
167 *psf=NULL;
169 if (!pdesktopfolder)
171 lpclf = IClassFactory_Constructor(&CLSID_ShellDesktop);
172 if(lpclf)
174 hres = IClassFactory_CreateInstance(lpclf,NULL,(REFIID)&IID_IShellFolder, (void*)&pdesktopfolder);
175 IClassFactory_Release(lpclf);
179 if (pdesktopfolder)
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);
187 return hres;
190 /**************************************************************************
191 * IClassFactory Implementation
194 typedef struct
196 /* IUnknown fields */
197 ICOM_VFIELD(IClassFactory);
198 DWORD ref;
199 CLSID *rclsid;
200 } IClassFactoryImpl;
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));
213 lpclf->ref = 1;
214 ICOM_VTBL(lpclf) = &clfvt;
215 lpclf->rclsid = (CLSID*)rclsid;
217 TRACE("(%p)->()\n",lpclf);
218 shell32_ObjCount++;
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));
230 *ppvObj = NULL;
232 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
233 { *ppvObj = This;
235 else if(IsEqualIID(riid, &IID_IClassFactory)) /*IClassFactory*/
236 { *ppvObj = (IClassFactory*)This;
239 if(*ppvObj)
240 { IUnknown_AddRef((LPUNKNOWN)*ppvObj);
241 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
242 return S_OK;
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);
255 shell32_ObjCount++;
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);
266 shell32_ObjCount--;
267 if (!--(This->ref))
268 { TRACE("-- destroying IClassFactory(%p)\n",This);
269 HeapFree(GetProcessHeap(),0,This);
270 return 0;
272 return This->ref;
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;
282 HRESULT hres;
284 TRACE("%p->(%p,\n\tIID:\t%s,%p)\n",This,pUnknown,debugstr_guid(riid),ppObject);
286 *ppObject = NULL;
288 if(pUnknown)
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);
301 else
303 ERR("unknown IID requested\n\tIID:\t%s\n",debugstr_guid(riid));
304 return(E_NOINTERFACE);
307 if (!pObj)
309 return(E_OUTOFMEMORY);
312 hres = IUnknown_QueryInterface(pObj,riid, ppObject);
313 IUnknown_Release(pObj);
315 TRACE("-- Object created: (%p)->%p\n",This,*ppObject);
317 return hres;
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);
326 return E_NOTIMPL;
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
344 * NOTES
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);
351 typedef struct
353 ICOM_VFIELD(IClassFactory);
354 DWORD ref;
355 CLSID *rclsid;
356 LPFNCREATEINSTANCE lpfnCI;
357 const IID * riidInst;
358 UINT * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
359 } IDefClFImpl;
361 static ICOM_VTABLE(IClassFactory) dclfvt;
363 /**************************************************************************
364 * IDefClF_fnConstructor
367 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, UINT * pcRefDll, REFIID riidInst)
369 IDefClFImpl* lpclf;
371 lpclf = (IDefClFImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
372 lpclf->ref = 1;
373 ICOM_VTBL(lpclf) = &dclfvt;
374 lpclf->lpfnCI = lpfnCI;
375 lpclf->pcRefDll = pcRefDll;
377 if (pcRefDll)
378 (*pcRefDll)++;
380 lpclf->riidInst = riidInst;
382 TRACE("(%p)\n\tIID:\t%s\n",lpclf, debugstr_guid(riidInst));
383 shell32_ObjCount++;
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));
396 *ppvObj = NULL;
398 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
399 { *ppvObj = This;
401 else if(IsEqualIID(riid, &IID_IClassFactory)) /*IClassFactory*/
402 { *ppvObj = (IClassFactory*)This;
405 if(*ppvObj)
406 { IUnknown_AddRef((LPUNKNOWN)*ppvObj);
407 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
408 return S_OK;
410 TRACE("-- Interface: %s E_NOINTERFACE\n", debugstr_guid(riid));
411 return E_NOINTERFACE;
413 /******************************************************************************
414 * IDefClF_fnAddRef
416 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
418 ICOM_THIS(IDefClFImpl,iface);
419 TRACE("(%p)->(count=%lu)\n",This,This->ref);
421 shell32_ObjCount++;
423 return ++(This->ref);
425 /******************************************************************************
426 * IDefClF_fnRelease
428 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
430 ICOM_THIS(IDefClFImpl,iface);
431 TRACE("(%p)->(count=%lu)\n",This,This->ref);
433 shell32_ObjCount--;
435 if (!--(This->ref))
437 if (This->pcRefDll)
438 (*This->pcRefDll)--;
440 TRACE("-- destroying IClassFactory(%p)\n",This);
441 HeapFree(GetProcessHeap(),0,This);
442 return 0;
444 return This->ref;
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);
456 *ppvObject = NULL;
458 if(pUnkOuter)
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);
478 return E_NOTIMPL;
481 static ICOM_VTABLE(IClassFactory) dclfvt =
483 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
484 IDefClF_fnQueryInterface,
485 IDefClF_fnAddRef,
486 IDefClF_fnRelease,
487 IDefClF_fnCreateInstance,
488 IDefClF_fnLockServer
491 /******************************************************************************
492 * SHCreateDefClassObject [SHELL32.70]
494 HRESULT WINAPI SHCreateDefClassObject(
495 REFIID riid,
496 LPVOID* ppv,
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);
507 if (pcf)
509 *ppv = pcf;
510 return NOERROR;
512 return E_OUTOFMEMORY;
514 return E_NOINTERFACE;