2 * handling of SHELL32.DLL OLE-Objects
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
16 #include "wine/unicode.h"
18 #include "debugtools.h"
20 #include "shell32_main.h"
22 DEFAULT_DEBUG_CHANNEL(shell);
24 DWORD WINAPI SHCLSIDFromStringA (LPSTR clsid, CLSID *id);
25 extern IShellFolder * IShellFolder_Constructor(
28 extern HRESULT IFSFolder_Constructor(
33 /*************************************************************************
34 * SHCoCreateInstance [SHELL32.102]
39 LRESULT WINAPI SHCoCreateInstance(
42 IUnknown * unknownouter,
48 CLSID * myclsid = (CLSID*)clsid;
52 if (!aclsid) return REGDB_E_CLASSNOTREG;
53 SHCLSIDFromStringA(aclsid, &iid);
57 TRACE("(%p,\n\tCLSID:\t%s, unk:%p\n\tIID:\t%s,%p)\n",
58 aclsid,debugstr_guid(myclsid),unknownouter,debugstr_guid(refiid),ppv);
60 if IsEqualCLSID(myclsid, &CLSID_ShellFSFolder)
62 hres = IFSFolder_Constructor(unknownouter, refiid, ppv);
66 hres = CoCreateInstance(myclsid, unknownouter, CLSCTX_INPROC_SERVER, refiid, ppv);
71 ERR("failed (0x%08lx) to create \n\tCLSID:\t%s\n\tIID:\t%s\n",
72 hres, debugstr_guid(myclsid), debugstr_guid(refiid));
73 ERR("class not found in registry\n");
76 TRACE("-- instance: %p\n",*ppv);
80 /*************************************************************************
81 * SHELL32_DllGetClassObject [SHELL32.128]
83 HRESULT WINAPI SHELL32_DllGetClassObject(REFCLSID rclsid, REFIID iid,LPVOID *ppv)
84 { HRESULT hres = E_OUTOFMEMORY;
87 TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",debugstr_guid(rclsid),debugstr_guid(iid));
91 if(IsEqualCLSID(rclsid, &CLSID_ShellDesktop)||
92 IsEqualCLSID(rclsid, &CLSID_ShellLink))
94 lpclf = IClassFactory_Constructor( rclsid );
98 hres = IClassFactory_QueryInterface(lpclf,iid, ppv);
99 IClassFactory_Release(lpclf);
104 WARN("-- CLSID not found\n");
105 hres = CLASS_E_CLASSNOTAVAILABLE;
107 TRACE("-- pointer to class factory: %p\n",*ppv);
111 /*************************************************************************
112 * SHCLSIDFromString [SHELL32.147]
115 * exported by ordinal
117 DWORD WINAPI SHCLSIDFromStringA (LPSTR clsid, CLSID *id)
120 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
121 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
122 return CO_E_CLASSSTRING;
123 return CLSIDFromString( buffer, id );
125 DWORD WINAPI SHCLSIDFromStringW (LPWSTR clsid, CLSID *id)
127 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
128 return CLSIDFromString(clsid, id);
130 DWORD WINAPI SHCLSIDFromStringAW (LPVOID clsid, CLSID *id)
132 if (SHELL_OsIsUnicode())
133 return SHCLSIDFromStringW (clsid, id);
134 return SHCLSIDFromStringA (clsid, id);
137 /*************************************************************************
138 * SHGetMalloc [SHELL32.@]
139 * returns the interface to shell malloc.
141 * [SDK header win95/shlobj.h:
142 * equivalent to: #define SHGetMalloc(ppmem) CoGetMalloc(MEMCTX_TASK, ppmem)
144 * What we are currently doing is not very wrong, since we always use the same
145 * heap (ProcessHeap).
147 DWORD WINAPI SHGetMalloc(LPMALLOC *lpmal)
149 TRACE("(%p)\n", lpmal);
150 return CoGetMalloc(MEMCTX_TASK, lpmal);
153 /*************************************************************************
154 * SHGetDesktopFolder [SHELL32.@]
156 LPSHELLFOLDER pdesktopfolder=NULL;
158 DWORD WINAPI SHGetDesktopFolder(IShellFolder **psf)
161 LPCLASSFACTORY lpclf;
162 TRACE("%p->(%p)\n",psf,*psf);
168 lpclf = IClassFactory_Constructor(&CLSID_ShellDesktop);
171 hres = IClassFactory_CreateInstance(lpclf,NULL,(REFIID)&IID_IShellFolder, (void*)&pdesktopfolder);
172 IClassFactory_Release(lpclf);
178 /* even if we create the folder, add a ref so the application canĀ“t destroy the folder*/
179 IShellFolder_AddRef(pdesktopfolder);
180 *psf = pdesktopfolder;
183 TRACE("-- %p->(%p)\n",psf, *psf);
187 /**************************************************************************
188 * IClassFactory Implementation
193 /* IUnknown fields */
194 ICOM_VFIELD(IClassFactory);
199 static ICOM_VTABLE(IClassFactory) clfvt;
201 /**************************************************************************
202 * IClassFactory_Constructor
205 LPCLASSFACTORY IClassFactory_Constructor(REFCLSID rclsid)
207 IClassFactoryImpl* lpclf;
209 lpclf= (IClassFactoryImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IClassFactoryImpl));
211 ICOM_VTBL(lpclf) = &clfvt;
212 lpclf->rclsid = (CLSID*)rclsid;
214 TRACE("(%p)->()\n",lpclf);
215 InterlockedIncrement(&shell32_ObjCount);
216 return (LPCLASSFACTORY)lpclf;
218 /**************************************************************************
219 * IClassFactory_QueryInterface
221 static HRESULT WINAPI IClassFactory_fnQueryInterface(
222 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
224 ICOM_THIS(IClassFactoryImpl,iface);
225 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
229 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
232 else if(IsEqualIID(riid, &IID_IClassFactory)) /*IClassFactory*/
233 { *ppvObj = (IClassFactory*)This;
237 { IUnknown_AddRef((LPUNKNOWN)*ppvObj);
238 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
241 TRACE("-- Interface: %s E_NOINTERFACE\n", debugstr_guid(riid));
242 return E_NOINTERFACE;
244 /******************************************************************************
245 * IClassFactory_AddRef
247 static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
249 ICOM_THIS(IClassFactoryImpl,iface);
250 TRACE("(%p)->(count=%lu)\n",This,This->ref);
252 InterlockedIncrement(&shell32_ObjCount);
253 return InterlockedIncrement(&This->ref);
255 /******************************************************************************
256 * IClassFactory_Release
258 static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
260 ICOM_THIS(IClassFactoryImpl,iface);
261 TRACE("(%p)->(count=%lu)\n",This,This->ref);
263 InterlockedDecrement(&shell32_ObjCount);
264 if (!InterlockedDecrement(&This->ref))
266 TRACE("-- destroying IClassFactory(%p)\n",This);
267 HeapFree(GetProcessHeap(),0,This);
272 /******************************************************************************
273 * IClassFactory_CreateInstance
275 static HRESULT WINAPI IClassFactory_fnCreateInstance(
276 LPCLASSFACTORY iface, LPUNKNOWN pUnknown, REFIID riid, LPVOID *ppObject)
278 ICOM_THIS(IClassFactoryImpl,iface);
279 IUnknown *pObj = NULL;
282 TRACE("%p->(%p,\n\tIID:\t%s,%p)\n",This,pUnknown,debugstr_guid(riid),ppObject);
288 return(CLASS_E_NOAGGREGATION);
291 if (IsEqualCLSID(This->rclsid, &CLSID_ShellDesktop))
293 pObj = (IUnknown *)ISF_Desktop_Constructor();
295 else if (IsEqualCLSID(This->rclsid, &CLSID_ShellLink))
297 pObj = (IUnknown *)IShellLink_Constructor(FALSE);
301 ERR("unknown IID requested\n\tIID:\t%s\n",debugstr_guid(riid));
302 return(E_NOINTERFACE);
307 return(E_OUTOFMEMORY);
310 hres = IUnknown_QueryInterface(pObj,riid, ppObject);
311 IUnknown_Release(pObj);
313 TRACE("-- Object created: (%p)->%p\n",This,*ppObject);
317 /******************************************************************************
318 * IClassFactory_LockServer
320 static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
322 ICOM_THIS(IClassFactoryImpl,iface);
323 TRACE("%p->(0x%x), not implemented\n",This, fLock);
327 static ICOM_VTABLE(IClassFactory) clfvt =
329 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
330 IClassFactory_fnQueryInterface,
331 IClassFactory_fnAddRef,
332 IClassFactory_fnRelease,
333 IClassFactory_fnCreateInstance,
334 IClassFactory_fnLockServer
337 /**************************************************************************
338 * Default ClassFactory Implementation
340 * SHCreateDefClassObject
343 * helper function for dll's without a own classfactory
344 * a generic classfactory is returned
345 * when the CreateInstance of the cf is called the callback is executed
347 typedef HRESULT CALLBACK (*LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
351 ICOM_VFIELD(IClassFactory);
354 LPFNCREATEINSTANCE lpfnCI;
355 const IID * riidInst;
356 ULONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
359 static ICOM_VTABLE(IClassFactory) dclfvt;
361 /**************************************************************************
362 * IDefClF_fnConstructor
365 IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
369 lpclf = (IDefClFImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
371 ICOM_VTBL(lpclf) = &dclfvt;
372 lpclf->lpfnCI = lpfnCI;
373 lpclf->pcRefDll = pcRefDll;
375 if (pcRefDll) InterlockedIncrement(pcRefDll);
376 lpclf->riidInst = riidInst;
378 TRACE("(%p)\n\tIID:\t%s\n",lpclf, debugstr_guid(riidInst));
379 InterlockedIncrement(&shell32_ObjCount);
380 return (LPCLASSFACTORY)lpclf;
382 /**************************************************************************
383 * IDefClF_fnQueryInterface
385 static HRESULT WINAPI IDefClF_fnQueryInterface(
386 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
388 ICOM_THIS(IDefClFImpl,iface);
390 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
394 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
397 else if(IsEqualIID(riid, &IID_IClassFactory)) /*IClassFactory*/
398 { *ppvObj = (IClassFactory*)This;
402 { IUnknown_AddRef((LPUNKNOWN)*ppvObj);
403 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
406 TRACE("-- Interface: %s E_NOINTERFACE\n", debugstr_guid(riid));
407 return E_NOINTERFACE;
409 /******************************************************************************
412 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
414 ICOM_THIS(IDefClFImpl,iface);
415 TRACE("(%p)->(count=%lu)\n",This,This->ref);
417 InterlockedIncrement(&shell32_ObjCount);
418 return InterlockedIncrement(&This->ref);
420 /******************************************************************************
423 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
425 ICOM_THIS(IDefClFImpl,iface);
426 TRACE("(%p)->(count=%lu)\n",This,This->ref);
428 InterlockedDecrement(&shell32_ObjCount);
430 if (!InterlockedDecrement(&This->ref))
432 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
434 TRACE("-- destroying IClassFactory(%p)\n",This);
435 HeapFree(GetProcessHeap(),0,This);
440 /******************************************************************************
441 * IDefClF_fnCreateInstance
443 static HRESULT WINAPI IDefClF_fnCreateInstance(
444 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
446 ICOM_THIS(IDefClFImpl,iface);
448 TRACE("%p->(%p,\n\tIID:\t%s,%p)\n",This,pUnkOuter,debugstr_guid(riid),ppvObject);
453 return(CLASS_E_NOAGGREGATION);
455 if ( This->riidInst==NULL ||
456 IsEqualCLSID(riid, This->riidInst) ||
457 IsEqualCLSID(riid, &IID_IUnknown) )
459 return This->lpfnCI(pUnkOuter, riid, ppvObject);
462 ERR("unknown IID requested\n\tIID:\t%s\n",debugstr_guid(riid));
463 return E_NOINTERFACE;
465 /******************************************************************************
466 * IDefClF_fnLockServer
468 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
470 ICOM_THIS(IDefClFImpl,iface);
471 TRACE("%p->(0x%x), not implemented\n",This, fLock);
475 static ICOM_VTABLE(IClassFactory) dclfvt =
477 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
478 IDefClF_fnQueryInterface,
481 IDefClF_fnCreateInstance,
485 /******************************************************************************
486 * SHCreateDefClassObject [SHELL32.70]
488 HRESULT WINAPI SHCreateDefClassObject(
491 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
492 PLONG pcRefDll, /* [in/out] ref count of the dll */
493 REFIID riidInst) /* [in] optional interface to the instance */
495 TRACE("\n\tIID:\t%s %p %p %p \n\tIIDIns:\t%s\n",
496 debugstr_guid(riid), ppv, lpfnCI, pcRefDll, debugstr_guid(riidInst));
498 if ( IsEqualCLSID(riid, &IID_IClassFactory) )
500 IClassFactory * pcf = IDefClF_fnConstructor(lpfnCI, pcRefDll, riidInst);
506 return E_OUTOFMEMORY;
508 return E_NOINTERFACE;
511 /*************************************************************************
512 * DragAcceptFiles [SHELL32.54]
514 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
518 if( !IsWindow(hWnd) ) return;
519 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
521 exstyle |= WS_EX_ACCEPTFILES;
523 exstyle &= ~WS_EX_ACCEPTFILES;
524 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
527 /*************************************************************************
528 * DragFinish [SHELL32.80]
530 void WINAPI DragFinish(HDROP h)
533 GlobalFree((HGLOBAL)h);
536 /*************************************************************************
537 * DragQueryPoint [SHELL32.135]
539 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
541 DROPFILES *lpDropFileStruct;
546 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
548 *p = lpDropFileStruct->pt;
549 bRet = lpDropFileStruct->fNC;
555 /*************************************************************************
556 * DragQueryFileA [SHELL32.82] [shell32.82]
558 UINT WINAPI DragQueryFileA(
566 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
568 TRACE("(%08x, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
570 if(!lpDropFileStruct) goto end;
572 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
576 while (*lpDrop++); /* skip filename */
579 i = (lFile == 0xFFFFFFFF) ? i : 0;
586 if (!lpszFile ) goto end; /* needed buffer size */
587 i = (lLength > i) ? i : lLength;
588 lstrcpynA (lpszFile, lpDrop, i);
594 /*************************************************************************
595 * DragQueryFileW [shell32.133]
597 UINT WINAPI DragQueryFileW(
605 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
607 TRACE("(%08x, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
609 if(!lpDropFileStruct) goto end;
611 lpwDrop = (LPWSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
616 while (*lpwDrop++); /* skip filename */
619 i = (lFile == 0xFFFFFFFF) ? i : 0;
624 i = strlenW(lpwDrop);
626 if ( !lpszwFile) goto end; /* needed buffer size */
628 i = (lLength > i) ? i : lLength;
629 lstrcpynW (lpszwFile, lpwDrop, i);