wmc: Move WineHQ URLs to https.
[wine.git] / dlls / shell32 / shellole.c
blob7b6ee924ea4561a62ea8487e9300d3e30570e0a5
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #define COBJMACROS
29 #define NONAMELESSUNION
31 #include "windef.h"
32 #include "winbase.h"
33 #include "shellapi.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "shlobj.h"
37 #include "shlguid.h"
38 #include "shldisp.h"
39 #include "gdiplus.h"
40 #include "shimgdata.h"
41 #include "winreg.h"
42 #include "winerror.h"
44 #include "undocshell.h"
45 #include "wine/unicode.h"
46 #include "shell32_main.h"
48 #include "wine/debug.h"
49 #include "shlwapi.h"
50 #include "debughlp.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(shell);
54 extern INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax); /* shlwapi.24 */
55 static HRESULT WINAPI ShellImageDataFactory_Constructor(IUnknown *outer, REFIID riid, void **obj);
57 /**************************************************************************
58 * Default ClassFactory types
60 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
61 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
63 /* this table contains all CLSIDs of shell32 objects */
64 static const struct {
65 REFIID clsid;
66 LPFNCREATEINSTANCE lpfnCI;
67 } InterfaceTable[] = {
69 {&CLSID_ApplicationAssociationRegistration, ApplicationAssociationRegistration_Constructor},
70 {&CLSID_ApplicationDestinations, ApplicationDestinations_Constructor},
71 {&CLSID_AutoComplete, IAutoComplete_Constructor},
72 {&CLSID_ControlPanel, IControlPanel_Constructor},
73 {&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
74 {&CLSID_FolderShortcut, FolderShortcut_Constructor},
75 {&CLSID_MyComputer, ISF_MyComputer_Constructor},
76 {&CLSID_MyDocuments, MyDocuments_Constructor},
77 {&CLSID_NetworkPlaces, ISF_NetworkPlaces_Constructor},
78 {&CLSID_Printers, Printers_Constructor},
79 {&CLSID_QueryAssociations, QueryAssociations_Constructor},
80 {&CLSID_RecycleBin, RecycleBin_Constructor},
81 {&CLSID_ShellDesktop, ISF_Desktop_Constructor},
82 {&CLSID_ShellFSFolder, IFSFolder_Constructor},
83 {&CLSID_ShellItem, IShellItem_Constructor},
84 {&CLSID_ShellLink, IShellLink_Constructor},
85 {&CLSID_UnixDosFolder, UnixDosFolder_Constructor},
86 {&CLSID_UnixFolder, UnixFolder_Constructor},
87 {&CLSID_ExplorerBrowser,ExplorerBrowser_Constructor},
88 {&CLSID_KnownFolderManager, KnownFolderManager_Constructor},
89 {&CLSID_Shell, IShellDispatch_Constructor},
90 {&CLSID_DestinationList, CustomDestinationList_Constructor},
91 {&CLSID_ShellImageDataFactory, ShellImageDataFactory_Constructor},
92 {NULL, NULL}
95 /*************************************************************************
96 * SHCoCreateInstance [SHELL32.102]
98 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
99 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
100 * SHLoadOLE for details.
102 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
103 * shell32.dll the function will load the object manually without the help of ole32
105 * NOTES
106 * exported by ordinal
108 * SEE ALSO
109 * CoCreateInstance, SHLoadOLE
111 HRESULT WINAPI SHCoCreateInstance(
112 LPCWSTR aclsid,
113 const CLSID *clsid,
114 LPUNKNOWN pUnkOuter,
115 REFIID refiid,
116 LPVOID *ppv)
118 DWORD hres;
119 IID iid;
120 const CLSID * myclsid = clsid;
121 WCHAR sKeyName[MAX_PATH];
122 static const WCHAR sCLSID[] = {'C','L','S','I','D','\\','\0'};
123 WCHAR sClassID[60];
124 static const WCHAR sInProcServer32[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
125 static const WCHAR sLoadWithoutCOM[] = {'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
126 WCHAR sDllPath[MAX_PATH];
127 HKEY hKey = 0;
128 DWORD dwSize;
129 IClassFactory * pcf = NULL;
131 if(!ppv) return E_POINTER;
132 *ppv=NULL;
134 /* if the clsid is a string, convert it */
135 if (!clsid)
137 if (!aclsid) return REGDB_E_CLASSNOTREG;
138 SHCLSIDFromStringW(aclsid, &iid);
139 myclsid = &iid;
142 TRACE("(%p,%s,unk:%p,%s,%p)\n",
143 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
145 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
147 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
148 IClassFactory_Release(pcf);
149 goto end;
152 /* we look up the dll path in the registry */
153 SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
154 lstrcpyW(sKeyName, sCLSID);
155 lstrcatW(sKeyName, sClassID);
156 lstrcatW(sKeyName, sInProcServer32);
158 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
159 return E_ACCESSDENIED;
161 /* if a special registry key is set, we load a shell extension without help of OLE32 */
162 if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
164 /* load an external dll without ole32 */
165 HANDLE hLibrary;
166 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
167 DllGetClassObjectFunc DllGetClassObject;
169 dwSize = sizeof(sDllPath);
170 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
172 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
173 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
174 hres = E_ACCESSDENIED;
175 goto end;
176 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
177 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
178 FreeLibrary( hLibrary );
179 hres = E_ACCESSDENIED;
180 goto end;
181 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
182 TRACE("GetClassObject failed 0x%08x\n", hres);
183 goto end;
186 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
187 IClassFactory_Release(pcf);
188 } else {
190 /* load an external dll in the usual way */
191 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
194 end:
195 if (hKey) RegCloseKey(hKey);
196 if(hres!=S_OK)
198 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
199 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
200 ERR("class not found in registry\n");
203 TRACE("-- instance: %p\n",*ppv);
204 return hres;
207 /*************************************************************************
208 * DllGetClassObject [SHELL32.@]
209 * SHDllGetClassObject [SHELL32.128]
211 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
213 IClassFactory * pcf = NULL;
214 HRESULT hres;
215 int i;
217 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
219 if (!ppv) return E_INVALIDARG;
220 *ppv = NULL;
222 /* search our internal interface table */
223 for(i=0;InterfaceTable[i].clsid;i++) {
224 if(IsEqualIID(InterfaceTable[i].clsid, rclsid)) {
225 TRACE("index[%u]\n", i);
226 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
227 break;
231 if (!pcf) {
232 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
233 return CLASS_E_CLASSNOTAVAILABLE;
236 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
237 IClassFactory_Release(pcf);
239 TRACE("-- pointer to class factory: %p\n",*ppv);
240 return hres;
243 /*************************************************************************
244 * SHCLSIDFromString [SHELL32.147]
246 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
247 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
249 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
251 * NOTES
252 * exported by ordinal
254 * SEE ALSO
255 * CLSIDFromString, SHLoadOLE
257 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
259 WCHAR buffer[40];
260 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
261 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
262 return CO_E_CLASSSTRING;
263 return CLSIDFromString( buffer, id );
265 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
267 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
268 return CLSIDFromString(clsid, id);
270 DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
272 if (SHELL_OsIsUnicode())
273 return SHCLSIDFromStringW (clsid, id);
274 return SHCLSIDFromStringA (clsid, id);
277 /*************************************************************************
278 * SHGetMalloc [SHELL32.@]
280 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
281 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
282 * see SHLoadOLE for details.
284 * PARAMS
285 * lpmal [O] Destination for IMalloc interface.
287 * RETURNS
288 * Success: S_OK. lpmal contains the shells IMalloc interface.
289 * Failure. An HRESULT error code.
291 * SEE ALSO
292 * CoGetMalloc, SHLoadOLE
294 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
296 TRACE("(%p)\n", lpmal);
297 return CoGetMalloc(MEMCTX_TASK, lpmal);
300 /*************************************************************************
301 * SHAlloc [SHELL32.196]
303 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
304 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
305 * see SHLoadOLE for details.
307 * NOTES
308 * exported by ordinal
310 * SEE ALSO
311 * CoTaskMemAlloc, SHLoadOLE
313 LPVOID WINAPI SHAlloc(DWORD len)
315 LPVOID ret;
317 ret = CoTaskMemAlloc(len);
318 TRACE("%u bytes at %p\n",len, ret);
319 return ret;
322 /*************************************************************************
323 * SHFree [SHELL32.195]
325 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
326 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
327 * see SHLoadOLE for details.
329 * NOTES
330 * exported by ordinal
332 * SEE ALSO
333 * CoTaskMemFree, SHLoadOLE
335 void WINAPI SHFree(LPVOID pv)
337 TRACE("%p\n",pv);
338 CoTaskMemFree(pv);
341 /*************************************************************************
342 * SHGetDesktopFolder [SHELL32.@]
344 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
346 HRESULT hres;
348 TRACE("(%p)\n", psf);
350 if(!psf) return E_INVALIDARG;
352 *psf = NULL;
353 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
355 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
356 return hres;
358 /**************************************************************************
359 * Default ClassFactory Implementation
361 * SHCreateDefClassObject
363 * NOTES
364 * Helper function for dlls without their own classfactory.
365 * A generic classfactory is returned.
366 * When the CreateInstance of the cf is called the callback is executed.
369 typedef struct
371 IClassFactory IClassFactory_iface;
372 LONG ref;
373 CLSID *rclsid;
374 LPFNCREATEINSTANCE lpfnCI;
375 const IID * riidInst;
376 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
377 } IDefClFImpl;
379 static inline IDefClFImpl *impl_from_IClassFactory(IClassFactory *iface)
381 return CONTAINING_RECORD(iface, IDefClFImpl, IClassFactory_iface);
384 static const IClassFactoryVtbl dclfvt;
386 /**************************************************************************
387 * IDefClF_fnConstructor
390 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
392 IDefClFImpl* lpclf;
394 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
395 lpclf->ref = 1;
396 lpclf->IClassFactory_iface.lpVtbl = &dclfvt;
397 lpclf->lpfnCI = lpfnCI;
398 lpclf->pcRefDll = pcRefDll;
400 if (pcRefDll) InterlockedIncrement(pcRefDll);
401 lpclf->riidInst = riidInst;
403 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
404 return (LPCLASSFACTORY)lpclf;
406 /**************************************************************************
407 * IDefClF_fnQueryInterface
409 static HRESULT WINAPI IDefClF_fnQueryInterface(
410 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
412 IDefClFImpl *This = impl_from_IClassFactory(iface);
414 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
416 *ppvObj = NULL;
418 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
419 *ppvObj = This;
420 InterlockedIncrement(&This->ref);
421 return S_OK;
424 TRACE("-- E_NOINTERFACE\n");
425 return E_NOINTERFACE;
427 /******************************************************************************
428 * IDefClF_fnAddRef
430 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
432 IDefClFImpl *This = impl_from_IClassFactory(iface);
433 ULONG refCount = InterlockedIncrement(&This->ref);
435 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
437 return refCount;
439 /******************************************************************************
440 * IDefClF_fnRelease
442 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
444 IDefClFImpl *This = impl_from_IClassFactory(iface);
445 ULONG refCount = InterlockedDecrement(&This->ref);
447 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
449 if (!refCount)
451 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
453 TRACE("-- destroying IClassFactory(%p)\n",This);
454 HeapFree(GetProcessHeap(),0,This);
455 return 0;
457 return refCount;
459 /******************************************************************************
460 * IDefClF_fnCreateInstance
462 static HRESULT WINAPI IDefClF_fnCreateInstance(
463 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
465 IDefClFImpl *This = impl_from_IClassFactory(iface);
467 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
469 *ppvObject = NULL;
471 if ( This->riidInst==NULL ||
472 IsEqualCLSID(riid, This->riidInst) ||
473 IsEqualCLSID(riid, &IID_IUnknown) )
475 return This->lpfnCI(pUnkOuter, riid, ppvObject);
478 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
479 return E_NOINTERFACE;
481 /******************************************************************************
482 * IDefClF_fnLockServer
484 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
486 IDefClFImpl *This = impl_from_IClassFactory(iface);
487 TRACE("%p->(0x%x), not implemented\n",This, fLock);
488 return E_NOTIMPL;
491 static const IClassFactoryVtbl dclfvt =
493 IDefClF_fnQueryInterface,
494 IDefClF_fnAddRef,
495 IDefClF_fnRelease,
496 IDefClF_fnCreateInstance,
497 IDefClF_fnLockServer
500 /******************************************************************************
501 * SHCreateDefClassObject [SHELL32.70]
503 HRESULT WINAPI SHCreateDefClassObject(
504 REFIID riid,
505 LPVOID* ppv,
506 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
507 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
508 REFIID riidInst) /* [in] optional interface to the instance */
510 IClassFactory * pcf;
512 TRACE("%s %p %p %p %s\n",
513 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
515 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
516 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
517 *ppv = pcf;
518 return S_OK;
521 /*************************************************************************
522 * DragAcceptFiles [SHELL32.@]
524 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
526 LONG exstyle;
528 if( !IsWindow(hWnd) ) return;
529 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
530 if (b)
531 exstyle |= WS_EX_ACCEPTFILES;
532 else
533 exstyle &= ~WS_EX_ACCEPTFILES;
534 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
537 /*************************************************************************
538 * DragFinish [SHELL32.@]
540 void WINAPI DragFinish(HDROP h)
542 TRACE("\n");
543 GlobalFree(h);
546 /*************************************************************************
547 * DragQueryPoint [SHELL32.@]
549 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
551 DROPFILES *lpDropFileStruct;
552 BOOL bRet;
554 TRACE("\n");
556 lpDropFileStruct = GlobalLock(hDrop);
558 *p = lpDropFileStruct->pt;
559 bRet = lpDropFileStruct->fNC;
561 GlobalUnlock(hDrop);
562 return bRet;
565 /*************************************************************************
566 * DragQueryFileA [SHELL32.@]
567 * DragQueryFile [SHELL32.@]
569 UINT WINAPI DragQueryFileA(
570 HDROP hDrop,
571 UINT lFile,
572 LPSTR lpszFile,
573 UINT lLength)
575 LPSTR lpDrop;
576 UINT i = 0;
577 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
579 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
581 if(!lpDropFileStruct) goto end;
583 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
585 if(lpDropFileStruct->fWide) {
586 LPWSTR lpszFileW = NULL;
588 if(lpszFile && lFile != 0xFFFFFFFF) {
589 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
590 if(lpszFileW == NULL) {
591 goto end;
594 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
596 if(lpszFileW) {
597 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
598 HeapFree(GetProcessHeap(), 0, lpszFileW);
600 goto end;
603 while (i++ < lFile)
605 while (*lpDrop++); /* skip filename */
606 if (!*lpDrop)
608 i = (lFile == 0xFFFFFFFF) ? i : 0;
609 goto end;
613 i = strlen(lpDrop);
614 if (!lpszFile ) goto end; /* needed buffer size */
615 lstrcpynA (lpszFile, lpDrop, lLength);
616 end:
617 GlobalUnlock(hDrop);
618 return i;
621 /*************************************************************************
622 * DragQueryFileW [SHELL32.@]
624 UINT WINAPI DragQueryFileW(
625 HDROP hDrop,
626 UINT lFile,
627 LPWSTR lpszwFile,
628 UINT lLength)
630 LPWSTR lpwDrop;
631 UINT i = 0;
632 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
634 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
636 if(!lpDropFileStruct) goto end;
638 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
640 if(lpDropFileStruct->fWide == FALSE) {
641 LPSTR lpszFileA = NULL;
643 if(lpszwFile && lFile != 0xFFFFFFFF) {
644 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
645 if(lpszFileA == NULL) {
646 goto end;
649 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
651 if(lpszFileA) {
652 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
653 HeapFree(GetProcessHeap(), 0, lpszFileA);
655 goto end;
658 i = 0;
659 while (i++ < lFile)
661 while (*lpwDrop++); /* skip filename */
662 if (!*lpwDrop)
664 i = (lFile == 0xFFFFFFFF) ? i : 0;
665 goto end;
669 i = strlenW(lpwDrop);
670 if ( !lpszwFile) goto end; /* needed buffer size */
671 lstrcpynW (lpszwFile, lpwDrop, lLength);
672 end:
673 GlobalUnlock(hDrop);
674 return i;
677 /*************************************************************************
678 * SHPropStgCreate [SHELL32.685]
680 HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
681 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
682 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
684 PROPSPEC prop;
685 PROPVARIANT ret;
686 HRESULT hres;
688 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
689 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
691 hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
693 switch(dwDisposition) {
694 case CREATE_ALWAYS:
695 if(SUCCEEDED(hres)) {
696 IPropertyStorage_Release(*ppstg);
697 hres = IPropertySetStorage_Delete(psstg, fmtid);
698 if(FAILED(hres))
699 return hres;
700 hres = E_FAIL;
703 case OPEN_ALWAYS:
704 case CREATE_NEW:
705 if(FAILED(hres))
706 hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
707 grfFlags, grfMode, ppstg);
709 case OPEN_EXISTING:
710 if(FAILED(hres))
711 return hres;
713 if(puCodePage) {
714 prop.ulKind = PRSPEC_PROPID;
715 prop.u.propid = PID_CODEPAGE;
716 hres = IPropertyStorage_ReadMultiple(*ppstg, 1, &prop, &ret);
717 if(FAILED(hres) || ret.vt!=VT_I2)
718 *puCodePage = 0;
719 else
720 *puCodePage = ret.u.iVal;
724 return S_OK;
727 /*************************************************************************
728 * SHPropStgReadMultiple [SHELL32.688]
730 HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
731 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
733 STATPROPSETSTG stat;
734 HRESULT hres;
736 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
738 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
739 hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
740 if(FAILED(hres))
741 return hres;
743 if(!uCodePage) {
744 PROPSPEC prop;
745 PROPVARIANT ret;
747 prop.ulKind = PRSPEC_PROPID;
748 prop.u.propid = PID_CODEPAGE;
749 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
750 if(FAILED(hres) || ret.vt!=VT_I2)
751 return S_OK;
753 uCodePage = ret.u.iVal;
756 hres = IPropertyStorage_Stat(pps, &stat);
757 if(FAILED(hres))
758 return S_OK;
760 /* TODO: do something with codepage and stat */
761 return S_OK;
764 /*************************************************************************
765 * SHPropStgWriteMultiple [SHELL32.689]
767 HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
768 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
770 STATPROPSETSTG stat;
771 UINT codepage;
772 HRESULT hres;
774 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
776 hres = IPropertyStorage_Stat(pps, &stat);
777 if(FAILED(hres))
778 return hres;
780 if(uCodePage && *uCodePage)
781 codepage = *uCodePage;
782 else {
783 PROPSPEC prop;
784 PROPVARIANT ret;
786 prop.ulKind = PRSPEC_PROPID;
787 prop.u.propid = PID_CODEPAGE;
788 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
789 if(FAILED(hres))
790 return hres;
791 if(ret.vt!=VT_I2 || !ret.u.iVal)
792 return E_FAIL;
794 codepage = ret.u.iVal;
795 if(uCodePage)
796 *uCodePage = codepage;
799 /* TODO: do something with codepage and stat */
801 hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
802 return hres;
805 /*************************************************************************
806 * SHCreateQueryCancelAutoPlayMoniker [SHELL32.@]
808 HRESULT WINAPI SHCreateQueryCancelAutoPlayMoniker(IMoniker **moniker)
810 TRACE("%p\n", moniker);
812 if (!moniker) return E_INVALIDARG;
813 return CreateClassMoniker(&CLSID_QueryCancelAutoPlay, moniker);
816 static HRESULT gpstatus_to_hresult(GpStatus status)
818 switch (status)
820 case Ok:
821 return S_OK;
822 case InvalidParameter:
823 return E_INVALIDARG;
824 case OutOfMemory:
825 return E_OUTOFMEMORY;
826 case NotImplemented:
827 return E_NOTIMPL;
828 default:
829 return E_FAIL;
833 /* IShellImageData */
834 typedef struct
836 IShellImageData IShellImageData_iface;
837 LONG ref;
839 WCHAR *path;
840 GpImage *image;
841 } ShellImageData;
843 static inline ShellImageData *impl_from_IShellImageData(IShellImageData *iface)
845 return CONTAINING_RECORD(iface, ShellImageData, IShellImageData_iface);
848 static HRESULT WINAPI ShellImageData_QueryInterface(IShellImageData *iface, REFIID riid, void **obj)
850 ShellImageData *This = impl_from_IShellImageData(iface);
852 TRACE("%p, %s, %p\n", This, debugstr_guid(riid), obj);
854 if (IsEqualIID(riid, &IID_IShellImageData) || IsEqualIID(riid, &IID_IUnknown))
856 *obj = &This->IShellImageData_iface;
857 IShellImageData_AddRef(iface);
858 return S_OK;
861 *obj = NULL;
862 return E_NOINTERFACE;
865 static ULONG WINAPI ShellImageData_AddRef(IShellImageData *iface)
867 ShellImageData *This = impl_from_IShellImageData(iface);
868 ULONG ref = InterlockedIncrement(&This->ref);
870 TRACE("%p, %u\n", This, ref);
872 return ref;
875 static ULONG WINAPI ShellImageData_Release(IShellImageData *iface)
877 ShellImageData *This = impl_from_IShellImageData(iface);
878 ULONG ref = InterlockedDecrement(&This->ref);
880 TRACE("%p, %u\n", This, ref);
882 if (!ref)
884 GdipDisposeImage(This->image);
885 HeapFree(GetProcessHeap(), 0, This->path);
886 SHFree(This);
889 return ref;
892 static HRESULT WINAPI ShellImageData_Decode(IShellImageData *iface, DWORD flags, ULONG cx_desired, ULONG cy_desired)
894 ShellImageData *This = impl_from_IShellImageData(iface);
895 GpImage *image;
896 HRESULT hr;
898 TRACE("%p, %#x, %u, %u\n", This, flags, cx_desired, cy_desired);
900 if (This->image)
901 return S_FALSE;
903 if (flags & SHIMGDEC_LOADFULL)
904 FIXME("LOADFULL flag ignored\n");
906 hr = gpstatus_to_hresult(GdipLoadImageFromFile(This->path, &image));
907 if (FAILED(hr))
908 return hr;
910 if (flags & SHIMGDEC_THUMBNAIL)
912 hr = gpstatus_to_hresult(GdipGetImageThumbnail(image, cx_desired, cy_desired, &This->image, NULL, NULL));
913 GdipDisposeImage(image);
915 else
916 This->image = image;
918 return hr;
921 static HRESULT WINAPI ShellImageData_Draw(IShellImageData *iface, HDC hdc, RECT *dest, RECT *src)
923 ShellImageData *This = impl_from_IShellImageData(iface);
924 GpGraphics *graphics;
925 HRESULT hr;
927 TRACE("%p, %p, %s, %s\n", This, hdc, wine_dbgstr_rect(dest), wine_dbgstr_rect(src));
929 if (!This->image)
930 return E_FAIL;
932 if (!dest)
933 return E_INVALIDARG;
935 if (!src)
936 return S_OK;
938 hr = gpstatus_to_hresult(GdipCreateFromHDC(hdc, &graphics));
939 if (FAILED(hr))
940 return hr;
942 hr = gpstatus_to_hresult(GdipDrawImageRectRectI(graphics, This->image, dest->left, dest->top, dest->right - dest->left,
943 dest->bottom - dest->top, src->left, src->top, src->right - src->left, src->bottom - src->top,
944 UnitPixel, NULL, NULL, NULL));
945 GdipDeleteGraphics(graphics);
947 return hr;
950 static HRESULT WINAPI ShellImageData_NextFrame(IShellImageData *iface)
952 ShellImageData *This = impl_from_IShellImageData(iface);
954 FIXME("%p: stub\n", This);
956 return E_NOTIMPL;
959 static HRESULT WINAPI ShellImageData_NextPage(IShellImageData *iface)
961 ShellImageData *This = impl_from_IShellImageData(iface);
963 FIXME("%p: stub\n", This);
965 return E_NOTIMPL;
968 static HRESULT WINAPI ShellImageData_PrevPage(IShellImageData *iface)
970 ShellImageData *This = impl_from_IShellImageData(iface);
972 FIXME("%p: stub\n", This);
974 return E_NOTIMPL;
977 static HRESULT WINAPI ShellImageData_IsTransparent(IShellImageData *iface)
979 ShellImageData *This = impl_from_IShellImageData(iface);
981 FIXME("%p: stub\n", This);
983 return E_NOTIMPL;
986 static HRESULT WINAPI ShellImageData_IsAnimated(IShellImageData *iface)
988 ShellImageData *This = impl_from_IShellImageData(iface);
990 FIXME("%p: stub\n", This);
992 return E_NOTIMPL;
995 static HRESULT WINAPI ShellImageData_IsVector(IShellImageData *iface)
997 ShellImageData *This = impl_from_IShellImageData(iface);
999 FIXME("%p: stub\n", This);
1001 return E_NOTIMPL;
1004 static HRESULT WINAPI ShellImageData_IsMultipage(IShellImageData *iface)
1006 ShellImageData *This = impl_from_IShellImageData(iface);
1008 FIXME("%p: stub\n", This);
1010 return E_NOTIMPL;
1013 static HRESULT WINAPI ShellImageData_IsEditable(IShellImageData *iface)
1015 ShellImageData *This = impl_from_IShellImageData(iface);
1017 FIXME("%p: stub\n", This);
1019 return E_NOTIMPL;
1022 static HRESULT WINAPI ShellImageData_IsPrintable(IShellImageData *iface)
1024 ShellImageData *This = impl_from_IShellImageData(iface);
1026 FIXME("%p: stub\n", This);
1028 return E_NOTIMPL;
1031 static HRESULT WINAPI ShellImageData_IsDecoded(IShellImageData *iface)
1033 ShellImageData *This = impl_from_IShellImageData(iface);
1035 FIXME("%p: stub\n", This);
1037 return E_NOTIMPL;
1040 static HRESULT WINAPI ShellImageData_GetCurrentPage(IShellImageData *iface, ULONG *page)
1042 ShellImageData *This = impl_from_IShellImageData(iface);
1044 FIXME("%p: stub\n", This);
1046 return E_NOTIMPL;
1049 static HRESULT WINAPI ShellImageData_GetPageCount(IShellImageData *iface, ULONG *count)
1051 ShellImageData *This = impl_from_IShellImageData(iface);
1053 FIXME("%p, %p: stub\n", This, count);
1055 return E_NOTIMPL;
1058 static HRESULT WINAPI ShellImageDate_SelectPage(IShellImageData *iface, ULONG page)
1060 ShellImageData *This = impl_from_IShellImageData(iface);
1062 FIXME("%p, %u: stub\n", This, page);
1064 return E_NOTIMPL;
1067 static HRESULT WINAPI ShellImageData_GetSize(IShellImageData *iface, SIZE *size)
1069 ShellImageData *This = impl_from_IShellImageData(iface);
1070 REAL cx, cy;
1071 HRESULT hr;
1073 TRACE("%p, %p\n", This, size);
1075 if (!This->image)
1076 return E_FAIL;
1078 hr = gpstatus_to_hresult(GdipGetImageDimension(This->image, &cx, &cy));
1079 if (SUCCEEDED(hr))
1081 size->cx = cx;
1082 size->cy = cy;
1085 return hr;
1088 static HRESULT WINAPI ShellImageData_GetRawDataFormat(IShellImageData *iface, GUID *format)
1090 ShellImageData *This = impl_from_IShellImageData(iface);
1092 FIXME("%p, %p: stub\n", This, format);
1094 return E_NOTIMPL;
1097 static HRESULT WINAPI ShellImageData_GetPixelFormat(IShellImageData *iface, PixelFormat *format)
1099 ShellImageData *This = impl_from_IShellImageData(iface);
1101 FIXME("%p, %p: stub\n", This, format);
1103 return E_NOTIMPL;
1106 static HRESULT WINAPI ShellImageData_GetDelay(IShellImageData *iface, DWORD *delay)
1108 ShellImageData *This = impl_from_IShellImageData(iface);
1110 FIXME("%p, %p: stub\n", This, delay);
1112 return E_NOTIMPL;
1115 static HRESULT WINAPI ShellImageData_GetProperties(IShellImageData *iface, DWORD mode, IPropertySetStorage **props)
1117 ShellImageData *This = impl_from_IShellImageData(iface);
1119 FIXME("%p, %#x, %p: stub\n", This, mode, props);
1121 return E_NOTIMPL;
1124 static HRESULT WINAPI ShellImageData_Rotate(IShellImageData *iface, DWORD angle)
1126 ShellImageData *This = impl_from_IShellImageData(iface);
1128 FIXME("%p, %u: stub\n", This, angle);
1130 return E_NOTIMPL;
1133 static HRESULT WINAPI ShellImageData_Scale(IShellImageData *iface, ULONG cx, ULONG cy, InterpolationMode mode)
1135 ShellImageData *This = impl_from_IShellImageData(iface);
1137 FIXME("%p, %u, %u, %#x: stub\n", This, cx, cy, mode);
1139 return E_NOTIMPL;
1142 static HRESULT WINAPI ShellImageData_DiscardEdit(IShellImageData *iface)
1144 ShellImageData *This = impl_from_IShellImageData(iface);
1146 FIXME("%p: stub\n", This);
1148 return E_NOTIMPL;
1151 static HRESULT WINAPI ShellImageDate_SetEncoderParams(IShellImageData *iface, IPropertyBag *params)
1153 ShellImageData *This = impl_from_IShellImageData(iface);
1155 FIXME("%p, %p: stub\n", This, params);
1157 return E_NOTIMPL;
1160 static HRESULT WINAPI ShellImageData_DisplayName(IShellImageData *iface, LPWSTR name, UINT count)
1162 ShellImageData *This = impl_from_IShellImageData(iface);
1164 FIXME("%p, %p, %u: stub\n", This, name, count);
1166 return E_NOTIMPL;
1169 static HRESULT WINAPI ShellImageData_GetResolution(IShellImageData *iface, ULONG *res_x, ULONG *res_y)
1171 ShellImageData *This = impl_from_IShellImageData(iface);
1173 FIXME("%p, %p, %p: stub\n", This, res_x, res_y);
1175 return E_NOTIMPL;
1178 static HRESULT WINAPI ShellImageData_GetEncoderParams(IShellImageData *iface, GUID *format, EncoderParameters **params)
1180 ShellImageData *This = impl_from_IShellImageData(iface);
1182 FIXME("%p, %p, %p: stub\n", This, format, params);
1184 return E_NOTIMPL;
1187 static HRESULT WINAPI ShellImageData_RegisterAbort(IShellImageData *iface, IShellImageDataAbort *abort,
1188 IShellImageDataAbort **prev)
1190 ShellImageData *This = impl_from_IShellImageData(iface);
1192 FIXME("%p, %p, %p: stub\n", This, abort, prev);
1194 return E_NOTIMPL;
1197 static HRESULT WINAPI ShellImageData_CloneFrame(IShellImageData *iface, Image **frame)
1199 ShellImageData *This = impl_from_IShellImageData(iface);
1201 FIXME("%p, %p: stub\n", This, frame);
1203 return E_NOTIMPL;
1206 static HRESULT WINAPI ShellImageData_ReplaceFrame(IShellImageData *iface, Image *frame)
1208 ShellImageData *This = impl_from_IShellImageData(iface);
1210 FIXME("%p, %p: stub\n", This, frame);
1212 return E_NOTIMPL;
1215 static const IShellImageDataVtbl ShellImageDataVtbl =
1217 ShellImageData_QueryInterface,
1218 ShellImageData_AddRef,
1219 ShellImageData_Release,
1220 ShellImageData_Decode,
1221 ShellImageData_Draw,
1222 ShellImageData_NextFrame,
1223 ShellImageData_NextPage,
1224 ShellImageData_PrevPage,
1225 ShellImageData_IsTransparent,
1226 ShellImageData_IsAnimated,
1227 ShellImageData_IsVector,
1228 ShellImageData_IsMultipage,
1229 ShellImageData_IsEditable,
1230 ShellImageData_IsPrintable,
1231 ShellImageData_IsDecoded,
1232 ShellImageData_GetCurrentPage,
1233 ShellImageData_GetPageCount,
1234 ShellImageDate_SelectPage,
1235 ShellImageData_GetSize,
1236 ShellImageData_GetRawDataFormat,
1237 ShellImageData_GetPixelFormat,
1238 ShellImageData_GetDelay,
1239 ShellImageData_GetProperties,
1240 ShellImageData_Rotate,
1241 ShellImageData_Scale,
1242 ShellImageData_DiscardEdit,
1243 ShellImageDate_SetEncoderParams,
1244 ShellImageData_DisplayName,
1245 ShellImageData_GetResolution,
1246 ShellImageData_GetEncoderParams,
1247 ShellImageData_RegisterAbort,
1248 ShellImageData_CloneFrame,
1249 ShellImageData_ReplaceFrame,
1252 static HRESULT create_shellimagedata_from_path(const WCHAR *path, IShellImageData **data)
1254 ShellImageData *This;
1256 This = SHAlloc(sizeof(*This));
1258 This->IShellImageData_iface.lpVtbl = &ShellImageDataVtbl;
1259 This->ref = 1;
1261 This->path = strdupW(path);
1262 This->image = NULL;
1264 *data = &This->IShellImageData_iface;
1265 return S_OK;
1268 /* IShellImageDataFactory */
1269 static HRESULT WINAPI ShellImageDataFactory_QueryInterface(IShellImageDataFactory *iface, REFIID riid, void **obj)
1271 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), obj);
1273 if (IsEqualIID(&IID_IShellImageDataFactory, riid) || IsEqualIID(&IID_IUnknown, riid))
1275 *obj = iface;
1277 else
1279 FIXME("not implemented for %s\n", debugstr_guid(riid));
1280 *obj = NULL;
1281 return E_NOINTERFACE;
1284 IUnknown_AddRef((IUnknown*)*obj);
1285 return S_OK;
1288 static ULONG WINAPI ShellImageDataFactory_AddRef(IShellImageDataFactory *iface)
1290 TRACE("(%p)\n", iface);
1292 return 2;
1295 static ULONG WINAPI ShellImageDataFactory_Release(IShellImageDataFactory *iface)
1297 TRACE("(%p)\n", iface);
1299 return 1;
1302 static HRESULT WINAPI ShellImageDataFactory_CreateIShellImageData(IShellImageDataFactory *iface, IShellImageData **data)
1304 FIXME("%p, %p: stub\n", iface, data);
1306 return E_NOTIMPL;
1309 static HRESULT WINAPI ShellImageDataFactory_CreateImageFromFile(IShellImageDataFactory *iface, const WCHAR *path,
1310 IShellImageData **data)
1312 TRACE("%p, %s, %p\n", iface, debugstr_w(path), data);
1314 return create_shellimagedata_from_path(path, data);
1317 static HRESULT WINAPI ShellImageDataFactory_CreateImageFromStream(IShellImageDataFactory *iface, IStream *stream,
1318 IShellImageData **data)
1320 FIXME("%p, %p, %p: stub\n", iface, stream, data);
1322 return E_NOTIMPL;
1325 static HRESULT WINAPI ShellImageDataFactory_GetDataFormatFromPath(IShellImageDataFactory *iface, const WCHAR *path,
1326 GUID *format)
1328 FIXME("%p, %s, %p: stub\n", iface, debugstr_w(path), format);
1330 return E_NOTIMPL;
1333 static const IShellImageDataFactoryVtbl ShellImageDataFactoryVtbl =
1335 ShellImageDataFactory_QueryInterface,
1336 ShellImageDataFactory_AddRef,
1337 ShellImageDataFactory_Release,
1338 ShellImageDataFactory_CreateIShellImageData,
1339 ShellImageDataFactory_CreateImageFromFile,
1340 ShellImageDataFactory_CreateImageFromStream,
1341 ShellImageDataFactory_GetDataFormatFromPath,
1344 static IShellImageDataFactory ShellImageDataFactory = { &ShellImageDataFactoryVtbl };
1346 HRESULT WINAPI ShellImageDataFactory_Constructor(IUnknown *outer, REFIID riid, void **obj)
1348 TRACE("%p %s %p\n", outer, debugstr_guid(riid), obj);
1350 if (outer)
1351 return CLASS_E_NOAGGREGATION;
1353 return IShellImageDataFactory_QueryInterface(&ShellImageDataFactory, riid, obj);