winedbg: Don't dereference possibly NULL thread pointer.
[wine/zf.git] / dlls / shell32 / shellole.c
blob3c88642512e17e6ec6d451e0c098899e5b5ad375
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 {&CLSID_FileOperation, IFileOperation_Constructor},
93 {NULL, NULL}
96 /*************************************************************************
97 * SHCoCreateInstance [SHELL32.102]
99 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
100 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
101 * SHLoadOLE for details.
103 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
104 * shell32.dll the function will load the object manually without the help of ole32
106 * NOTES
107 * exported by ordinal
109 * SEE ALSO
110 * CoCreateInstance, SHLoadOLE
112 HRESULT WINAPI SHCoCreateInstance(
113 LPCWSTR aclsid,
114 const CLSID *clsid,
115 LPUNKNOWN pUnkOuter,
116 REFIID refiid,
117 LPVOID *ppv)
119 DWORD hres;
120 IID iid;
121 const CLSID * myclsid = clsid;
122 WCHAR sKeyName[MAX_PATH];
123 static const WCHAR sCLSID[] = {'C','L','S','I','D','\\','\0'};
124 WCHAR sClassID[60];
125 static const WCHAR sInProcServer32[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
126 static const WCHAR sLoadWithoutCOM[] = {'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
127 WCHAR sDllPath[MAX_PATH];
128 HKEY hKey = 0;
129 DWORD dwSize;
130 IClassFactory * pcf = NULL;
132 if(!ppv) return E_POINTER;
133 *ppv=NULL;
135 /* if the clsid is a string, convert it */
136 if (!clsid)
138 if (!aclsid) return REGDB_E_CLASSNOTREG;
139 SHCLSIDFromStringW(aclsid, &iid);
140 myclsid = &iid;
143 TRACE("(%p,%s,unk:%p,%s,%p)\n",
144 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
146 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
148 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
149 IClassFactory_Release(pcf);
150 goto end;
153 /* we look up the dll path in the registry */
154 SHStringFromGUIDW(myclsid, sClassID, ARRAY_SIZE(sClassID));
155 lstrcpyW(sKeyName, sCLSID);
156 lstrcatW(sKeyName, sClassID);
157 lstrcatW(sKeyName, sInProcServer32);
159 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
160 return E_ACCESSDENIED;
162 /* if a special registry key is set, we load a shell extension without help of OLE32 */
163 if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
165 /* load an external dll without ole32 */
166 HANDLE hLibrary;
167 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
168 DllGetClassObjectFunc DllGetClassObject;
170 dwSize = sizeof(sDllPath);
171 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
173 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
174 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
175 hres = E_ACCESSDENIED;
176 goto end;
177 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
178 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
179 FreeLibrary( hLibrary );
180 hres = E_ACCESSDENIED;
181 goto end;
182 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
183 TRACE("GetClassObject failed 0x%08x\n", hres);
184 goto end;
187 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
188 IClassFactory_Release(pcf);
189 } else {
191 /* load an external dll in the usual way */
192 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
195 end:
196 if (hKey) RegCloseKey(hKey);
197 if(hres!=S_OK)
199 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
200 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
201 ERR("class not found in registry\n");
204 TRACE("-- instance: %p\n",*ppv);
205 return hres;
208 /*************************************************************************
209 * DllGetClassObject [SHELL32.@]
210 * SHDllGetClassObject [SHELL32.128]
212 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
214 IClassFactory * pcf = NULL;
215 HRESULT hres;
216 int i;
218 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
220 if (!ppv) return E_INVALIDARG;
221 *ppv = NULL;
223 /* search our internal interface table */
224 for(i=0;InterfaceTable[i].clsid;i++) {
225 if(IsEqualIID(InterfaceTable[i].clsid, rclsid)) {
226 TRACE("index[%u]\n", i);
227 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
228 break;
232 if (!pcf) {
233 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
234 return CLASS_E_CLASSNOTAVAILABLE;
237 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
238 IClassFactory_Release(pcf);
240 TRACE("-- pointer to class factory: %p\n",*ppv);
241 return hres;
244 /*************************************************************************
245 * SHCLSIDFromString [SHELL32.147]
247 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
248 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
250 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
252 * NOTES
253 * exported by ordinal
255 * SEE ALSO
256 * CLSIDFromString, SHLoadOLE
258 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
260 WCHAR buffer[40];
261 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
262 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, ARRAY_SIZE(buffer) ))
263 return CO_E_CLASSSTRING;
264 return CLSIDFromString( buffer, id );
266 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
268 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
269 return CLSIDFromString(clsid, id);
271 DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
273 if (SHELL_OsIsUnicode())
274 return SHCLSIDFromStringW (clsid, id);
275 return SHCLSIDFromStringA (clsid, id);
278 /*************************************************************************
279 * SHGetMalloc [SHELL32.@]
281 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
282 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
283 * see SHLoadOLE for details.
285 * PARAMS
286 * lpmal [O] Destination for IMalloc interface.
288 * RETURNS
289 * Success: S_OK. lpmal contains the shells IMalloc interface.
290 * Failure. An HRESULT error code.
292 * SEE ALSO
293 * CoGetMalloc, SHLoadOLE
295 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
297 TRACE("(%p)\n", lpmal);
298 return CoGetMalloc(MEMCTX_TASK, lpmal);
301 /*************************************************************************
302 * SHAlloc [SHELL32.196]
304 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
305 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
306 * see SHLoadOLE for details.
308 * NOTES
309 * exported by ordinal
311 * SEE ALSO
312 * CoTaskMemAlloc, SHLoadOLE
314 LPVOID WINAPI SHAlloc(DWORD len)
316 LPVOID ret;
318 ret = CoTaskMemAlloc(len);
319 TRACE("%u bytes at %p\n",len, ret);
320 return ret;
323 /*************************************************************************
324 * SHFree [SHELL32.195]
326 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
327 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
328 * see SHLoadOLE for details.
330 * NOTES
331 * exported by ordinal
333 * SEE ALSO
334 * CoTaskMemFree, SHLoadOLE
336 void WINAPI SHFree(LPVOID pv)
338 TRACE("%p\n",pv);
339 CoTaskMemFree(pv);
342 /*************************************************************************
343 * SHGetDesktopFolder [SHELL32.@]
345 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
347 HRESULT hres;
349 TRACE("(%p)\n", psf);
351 if(!psf) return E_INVALIDARG;
353 *psf = NULL;
354 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
356 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
357 return hres;
359 /**************************************************************************
360 * Default ClassFactory Implementation
362 * SHCreateDefClassObject
364 * NOTES
365 * Helper function for dlls without their own classfactory.
366 * A generic classfactory is returned.
367 * When the CreateInstance of the cf is called the callback is executed.
370 typedef struct
372 IClassFactory IClassFactory_iface;
373 LONG ref;
374 CLSID *rclsid;
375 LPFNCREATEINSTANCE lpfnCI;
376 const IID * riidInst;
377 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
378 } IDefClFImpl;
380 static inline IDefClFImpl *impl_from_IClassFactory(IClassFactory *iface)
382 return CONTAINING_RECORD(iface, IDefClFImpl, IClassFactory_iface);
385 static const IClassFactoryVtbl dclfvt;
387 /**************************************************************************
388 * IDefClF_fnConstructor
391 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
393 IDefClFImpl* lpclf;
395 lpclf = heap_alloc(sizeof(*lpclf));
396 lpclf->ref = 1;
397 lpclf->IClassFactory_iface.lpVtbl = &dclfvt;
398 lpclf->lpfnCI = lpfnCI;
399 lpclf->pcRefDll = pcRefDll;
401 if (pcRefDll) InterlockedIncrement(pcRefDll);
402 lpclf->riidInst = riidInst;
404 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
405 return &lpclf->IClassFactory_iface;
407 /**************************************************************************
408 * IDefClF_fnQueryInterface
410 static HRESULT WINAPI IDefClF_fnQueryInterface(
411 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
413 IDefClFImpl *This = impl_from_IClassFactory(iface);
415 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
417 *ppvObj = NULL;
419 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
420 *ppvObj = This;
421 InterlockedIncrement(&This->ref);
422 return S_OK;
425 TRACE("-- E_NOINTERFACE\n");
426 return E_NOINTERFACE;
428 /******************************************************************************
429 * IDefClF_fnAddRef
431 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
433 IDefClFImpl *This = impl_from_IClassFactory(iface);
434 ULONG refCount = InterlockedIncrement(&This->ref);
436 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
438 return refCount;
440 /******************************************************************************
441 * IDefClF_fnRelease
443 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
445 IDefClFImpl *This = impl_from_IClassFactory(iface);
446 ULONG refCount = InterlockedDecrement(&This->ref);
448 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
450 if (!refCount)
452 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
454 TRACE("-- destroying IClassFactory(%p)\n",This);
455 heap_free(This);
458 return refCount;
460 /******************************************************************************
461 * IDefClF_fnCreateInstance
463 static HRESULT WINAPI IDefClF_fnCreateInstance(
464 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
466 IDefClFImpl *This = impl_from_IClassFactory(iface);
468 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
470 *ppvObject = NULL;
472 if ( This->riidInst==NULL ||
473 IsEqualCLSID(riid, This->riidInst) ||
474 IsEqualCLSID(riid, &IID_IUnknown) )
476 return This->lpfnCI(pUnkOuter, riid, ppvObject);
479 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
480 return E_NOINTERFACE;
482 /******************************************************************************
483 * IDefClF_fnLockServer
485 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
487 IDefClFImpl *This = impl_from_IClassFactory(iface);
488 TRACE("%p->(0x%x), not implemented\n",This, fLock);
489 return E_NOTIMPL;
492 static const IClassFactoryVtbl dclfvt =
494 IDefClF_fnQueryInterface,
495 IDefClF_fnAddRef,
496 IDefClF_fnRelease,
497 IDefClF_fnCreateInstance,
498 IDefClF_fnLockServer
501 /******************************************************************************
502 * SHCreateDefClassObject [SHELL32.70]
504 HRESULT WINAPI SHCreateDefClassObject(
505 REFIID riid,
506 LPVOID* ppv,
507 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
508 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
509 REFIID riidInst) /* [in] optional interface to the instance */
511 IClassFactory * pcf;
513 TRACE("%s %p %p %p %s\n",
514 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
516 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
517 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
518 *ppv = pcf;
519 return S_OK;
522 /*************************************************************************
523 * DragAcceptFiles [SHELL32.@]
525 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
527 LONG exstyle;
529 if( !IsWindow(hWnd) ) return;
530 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
531 if (b)
532 exstyle |= WS_EX_ACCEPTFILES;
533 else
534 exstyle &= ~WS_EX_ACCEPTFILES;
535 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
538 /*************************************************************************
539 * DragFinish [SHELL32.@]
541 void WINAPI DragFinish(HDROP h)
543 TRACE("\n");
544 GlobalFree(h);
547 /*************************************************************************
548 * DragQueryPoint [SHELL32.@]
550 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
552 DROPFILES *lpDropFileStruct;
553 BOOL bRet;
555 TRACE("\n");
557 lpDropFileStruct = GlobalLock(hDrop);
559 *p = lpDropFileStruct->pt;
560 bRet = !lpDropFileStruct->fNC;
562 GlobalUnlock(hDrop);
563 return bRet;
566 /*************************************************************************
567 * DragQueryFileA [SHELL32.@]
568 * DragQueryFile [SHELL32.@]
570 UINT WINAPI DragQueryFileA(
571 HDROP hDrop,
572 UINT lFile,
573 LPSTR lpszFile,
574 UINT lLength)
576 LPSTR lpDrop;
577 UINT i = 0;
578 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
580 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
582 if(!lpDropFileStruct) goto end;
584 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
586 if(lpDropFileStruct->fWide) {
587 LPWSTR lpszFileW = NULL;
589 if(lpszFile && lFile != 0xFFFFFFFF) {
590 lpszFileW = heap_alloc(lLength*sizeof(WCHAR));
591 if(lpszFileW == NULL) {
592 goto end;
595 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
597 if(lpszFileW) {
598 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
599 heap_free(lpszFileW);
601 goto end;
604 while (i++ < lFile)
606 while (*lpDrop++); /* skip filename */
607 if (!*lpDrop)
609 i = (lFile == 0xFFFFFFFF) ? i : 0;
610 goto end;
614 i = strlen(lpDrop);
615 if (!lpszFile ) goto end; /* needed buffer size */
616 lstrcpynA (lpszFile, lpDrop, lLength);
617 end:
618 GlobalUnlock(hDrop);
619 return i;
622 /*************************************************************************
623 * DragQueryFileW [SHELL32.@]
625 UINT WINAPI DragQueryFileW(
626 HDROP hDrop,
627 UINT lFile,
628 LPWSTR lpszwFile,
629 UINT lLength)
631 LPWSTR lpwDrop;
632 UINT i = 0;
633 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
635 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
637 if(!lpDropFileStruct) goto end;
639 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
641 if(lpDropFileStruct->fWide == FALSE) {
642 LPSTR lpszFileA = NULL;
644 if(lpszwFile && lFile != 0xFFFFFFFF) {
645 lpszFileA = heap_alloc(lLength);
646 if(lpszFileA == NULL) {
647 goto end;
650 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
652 if(lpszFileA) {
653 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
654 heap_free(lpszFileA);
656 goto end;
659 i = 0;
660 while (i++ < lFile)
662 while (*lpwDrop++); /* skip filename */
663 if (!*lpwDrop)
665 i = (lFile == 0xFFFFFFFF) ? i : 0;
666 goto end;
670 i = strlenW(lpwDrop);
671 if ( !lpszwFile) goto end; /* needed buffer size */
672 lstrcpynW (lpszwFile, lpwDrop, lLength);
673 end:
674 GlobalUnlock(hDrop);
675 return i;
678 /*************************************************************************
679 * SHPropStgCreate [SHELL32.685]
681 HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
682 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
683 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
685 PROPSPEC prop;
686 PROPVARIANT ret;
687 HRESULT hres;
689 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
690 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
692 hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
694 switch(dwDisposition) {
695 case CREATE_ALWAYS:
696 if(SUCCEEDED(hres)) {
697 IPropertyStorage_Release(*ppstg);
698 hres = IPropertySetStorage_Delete(psstg, fmtid);
699 if(FAILED(hres))
700 return hres;
701 hres = E_FAIL;
704 case OPEN_ALWAYS:
705 case CREATE_NEW:
706 if(FAILED(hres))
707 hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
708 grfFlags, grfMode, ppstg);
710 case OPEN_EXISTING:
711 if(FAILED(hres))
712 return hres;
714 if(puCodePage) {
715 prop.ulKind = PRSPEC_PROPID;
716 prop.u.propid = PID_CODEPAGE;
717 hres = IPropertyStorage_ReadMultiple(*ppstg, 1, &prop, &ret);
718 if(FAILED(hres) || ret.vt!=VT_I2)
719 *puCodePage = 0;
720 else
721 *puCodePage = ret.u.iVal;
725 return S_OK;
728 /*************************************************************************
729 * SHPropStgReadMultiple [SHELL32.688]
731 HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
732 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
734 STATPROPSETSTG stat;
735 HRESULT hres;
737 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
739 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
740 hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
741 if(FAILED(hres))
742 return hres;
744 if(!uCodePage) {
745 PROPSPEC prop;
746 PROPVARIANT ret;
748 prop.ulKind = PRSPEC_PROPID;
749 prop.u.propid = PID_CODEPAGE;
750 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
751 if(FAILED(hres) || ret.vt!=VT_I2)
752 return S_OK;
754 uCodePage = ret.u.iVal;
757 hres = IPropertyStorage_Stat(pps, &stat);
758 if(FAILED(hres))
759 return S_OK;
761 /* TODO: do something with codepage and stat */
762 return S_OK;
765 /*************************************************************************
766 * SHPropStgWriteMultiple [SHELL32.689]
768 HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
769 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
771 STATPROPSETSTG stat;
772 UINT codepage;
773 HRESULT hres;
775 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
777 hres = IPropertyStorage_Stat(pps, &stat);
778 if(FAILED(hres))
779 return hres;
781 if(uCodePage && *uCodePage)
782 codepage = *uCodePage;
783 else {
784 PROPSPEC prop;
785 PROPVARIANT ret;
787 prop.ulKind = PRSPEC_PROPID;
788 prop.u.propid = PID_CODEPAGE;
789 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
790 if(FAILED(hres))
791 return hres;
792 if(ret.vt!=VT_I2 || !ret.u.iVal)
793 return E_FAIL;
795 codepage = ret.u.iVal;
796 if(uCodePage)
797 *uCodePage = codepage;
800 /* TODO: do something with codepage and stat */
802 hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
803 return hres;
806 /*************************************************************************
807 * SHCreateQueryCancelAutoPlayMoniker [SHELL32.@]
809 HRESULT WINAPI SHCreateQueryCancelAutoPlayMoniker(IMoniker **moniker)
811 TRACE("%p\n", moniker);
813 if (!moniker) return E_INVALIDARG;
814 return CreateClassMoniker(&CLSID_QueryCancelAutoPlay, moniker);
817 static HRESULT gpstatus_to_hresult(GpStatus status)
819 switch (status)
821 case Ok:
822 return S_OK;
823 case InvalidParameter:
824 return E_INVALIDARG;
825 case OutOfMemory:
826 return E_OUTOFMEMORY;
827 case NotImplemented:
828 return E_NOTIMPL;
829 default:
830 return E_FAIL;
834 /* IShellImageData */
835 typedef struct
837 IShellImageData IShellImageData_iface;
838 LONG ref;
840 WCHAR *path;
841 GpImage *image;
842 } ShellImageData;
844 static inline ShellImageData *impl_from_IShellImageData(IShellImageData *iface)
846 return CONTAINING_RECORD(iface, ShellImageData, IShellImageData_iface);
849 static HRESULT WINAPI ShellImageData_QueryInterface(IShellImageData *iface, REFIID riid, void **obj)
851 ShellImageData *This = impl_from_IShellImageData(iface);
853 TRACE("%p, %s, %p\n", This, debugstr_guid(riid), obj);
855 if (IsEqualIID(riid, &IID_IShellImageData) || IsEqualIID(riid, &IID_IUnknown))
857 *obj = &This->IShellImageData_iface;
858 IShellImageData_AddRef(iface);
859 return S_OK;
862 *obj = NULL;
863 return E_NOINTERFACE;
866 static ULONG WINAPI ShellImageData_AddRef(IShellImageData *iface)
868 ShellImageData *This = impl_from_IShellImageData(iface);
869 ULONG ref = InterlockedIncrement(&This->ref);
871 TRACE("%p, %u\n", This, ref);
873 return ref;
876 static ULONG WINAPI ShellImageData_Release(IShellImageData *iface)
878 ShellImageData *This = impl_from_IShellImageData(iface);
879 ULONG ref = InterlockedDecrement(&This->ref);
881 TRACE("%p, %u\n", This, ref);
883 if (!ref)
885 GdipDisposeImage(This->image);
886 heap_free(This->path);
887 SHFree(This);
890 return ref;
893 static HRESULT WINAPI ShellImageData_Decode(IShellImageData *iface, DWORD flags, ULONG cx_desired, ULONG cy_desired)
895 ShellImageData *This = impl_from_IShellImageData(iface);
896 GpImage *image;
897 HRESULT hr;
899 TRACE("%p, %#x, %u, %u\n", This, flags, cx_desired, cy_desired);
901 if (This->image)
902 return S_FALSE;
904 if (flags & SHIMGDEC_LOADFULL)
905 FIXME("LOADFULL flag ignored\n");
907 hr = gpstatus_to_hresult(GdipLoadImageFromFile(This->path, &image));
908 if (FAILED(hr))
909 return hr;
911 if (flags & SHIMGDEC_THUMBNAIL)
913 hr = gpstatus_to_hresult(GdipGetImageThumbnail(image, cx_desired, cy_desired, &This->image, NULL, NULL));
914 GdipDisposeImage(image);
916 else
917 This->image = image;
919 return hr;
922 static HRESULT WINAPI ShellImageData_Draw(IShellImageData *iface, HDC hdc, RECT *dest, RECT *src)
924 ShellImageData *This = impl_from_IShellImageData(iface);
925 GpGraphics *graphics;
926 HRESULT hr;
928 TRACE("%p, %p, %s, %s\n", This, hdc, wine_dbgstr_rect(dest), wine_dbgstr_rect(src));
930 if (!This->image)
931 return E_FAIL;
933 if (!dest)
934 return E_INVALIDARG;
936 if (!src)
937 return S_OK;
939 hr = gpstatus_to_hresult(GdipCreateFromHDC(hdc, &graphics));
940 if (FAILED(hr))
941 return hr;
943 hr = gpstatus_to_hresult(GdipDrawImageRectRectI(graphics, This->image, dest->left, dest->top, dest->right - dest->left,
944 dest->bottom - dest->top, src->left, src->top, src->right - src->left, src->bottom - src->top,
945 UnitPixel, NULL, NULL, NULL));
946 GdipDeleteGraphics(graphics);
948 return hr;
951 static HRESULT WINAPI ShellImageData_NextFrame(IShellImageData *iface)
953 ShellImageData *This = impl_from_IShellImageData(iface);
955 FIXME("%p: stub\n", This);
957 return E_NOTIMPL;
960 static HRESULT WINAPI ShellImageData_NextPage(IShellImageData *iface)
962 ShellImageData *This = impl_from_IShellImageData(iface);
964 FIXME("%p: stub\n", This);
966 return E_NOTIMPL;
969 static HRESULT WINAPI ShellImageData_PrevPage(IShellImageData *iface)
971 ShellImageData *This = impl_from_IShellImageData(iface);
973 FIXME("%p: stub\n", This);
975 return E_NOTIMPL;
978 static HRESULT WINAPI ShellImageData_IsTransparent(IShellImageData *iface)
980 ShellImageData *This = impl_from_IShellImageData(iface);
982 FIXME("%p: stub\n", This);
984 return E_NOTIMPL;
987 static HRESULT WINAPI ShellImageData_IsAnimated(IShellImageData *iface)
989 ShellImageData *This = impl_from_IShellImageData(iface);
991 FIXME("%p: stub\n", This);
993 return E_NOTIMPL;
996 static HRESULT WINAPI ShellImageData_IsVector(IShellImageData *iface)
998 ShellImageData *This = impl_from_IShellImageData(iface);
1000 FIXME("%p: stub\n", This);
1002 return E_NOTIMPL;
1005 static HRESULT WINAPI ShellImageData_IsMultipage(IShellImageData *iface)
1007 ShellImageData *This = impl_from_IShellImageData(iface);
1009 FIXME("%p: stub\n", This);
1011 return E_NOTIMPL;
1014 static HRESULT WINAPI ShellImageData_IsEditable(IShellImageData *iface)
1016 ShellImageData *This = impl_from_IShellImageData(iface);
1018 FIXME("%p: stub\n", This);
1020 return E_NOTIMPL;
1023 static HRESULT WINAPI ShellImageData_IsPrintable(IShellImageData *iface)
1025 ShellImageData *This = impl_from_IShellImageData(iface);
1027 FIXME("%p: stub\n", This);
1029 return E_NOTIMPL;
1032 static HRESULT WINAPI ShellImageData_IsDecoded(IShellImageData *iface)
1034 ShellImageData *This = impl_from_IShellImageData(iface);
1036 FIXME("%p: stub\n", This);
1038 return E_NOTIMPL;
1041 static HRESULT WINAPI ShellImageData_GetCurrentPage(IShellImageData *iface, ULONG *page)
1043 ShellImageData *This = impl_from_IShellImageData(iface);
1045 FIXME("%p: stub\n", This);
1047 return E_NOTIMPL;
1050 static HRESULT WINAPI ShellImageData_GetPageCount(IShellImageData *iface, ULONG *count)
1052 ShellImageData *This = impl_from_IShellImageData(iface);
1054 FIXME("%p, %p: stub\n", This, count);
1056 return E_NOTIMPL;
1059 static HRESULT WINAPI ShellImageDate_SelectPage(IShellImageData *iface, ULONG page)
1061 ShellImageData *This = impl_from_IShellImageData(iface);
1063 FIXME("%p, %u: stub\n", This, page);
1065 return E_NOTIMPL;
1068 static HRESULT WINAPI ShellImageData_GetSize(IShellImageData *iface, SIZE *size)
1070 ShellImageData *This = impl_from_IShellImageData(iface);
1071 REAL cx, cy;
1072 HRESULT hr;
1074 TRACE("%p, %p\n", This, size);
1076 if (!This->image)
1077 return E_FAIL;
1079 hr = gpstatus_to_hresult(GdipGetImageDimension(This->image, &cx, &cy));
1080 if (SUCCEEDED(hr))
1082 size->cx = cx;
1083 size->cy = cy;
1086 return hr;
1089 static HRESULT WINAPI ShellImageData_GetRawDataFormat(IShellImageData *iface, GUID *format)
1091 ShellImageData *This = impl_from_IShellImageData(iface);
1093 FIXME("%p, %p: stub\n", This, format);
1095 return E_NOTIMPL;
1098 static HRESULT WINAPI ShellImageData_GetPixelFormat(IShellImageData *iface, PixelFormat *format)
1100 ShellImageData *This = impl_from_IShellImageData(iface);
1102 FIXME("%p, %p: stub\n", This, format);
1104 return E_NOTIMPL;
1107 static HRESULT WINAPI ShellImageData_GetDelay(IShellImageData *iface, DWORD *delay)
1109 ShellImageData *This = impl_from_IShellImageData(iface);
1111 FIXME("%p, %p: stub\n", This, delay);
1113 return E_NOTIMPL;
1116 static HRESULT WINAPI ShellImageData_GetProperties(IShellImageData *iface, DWORD mode, IPropertySetStorage **props)
1118 ShellImageData *This = impl_from_IShellImageData(iface);
1120 FIXME("%p, %#x, %p: stub\n", This, mode, props);
1122 return E_NOTIMPL;
1125 static HRESULT WINAPI ShellImageData_Rotate(IShellImageData *iface, DWORD angle)
1127 ShellImageData *This = impl_from_IShellImageData(iface);
1129 FIXME("%p, %u: stub\n", This, angle);
1131 return E_NOTIMPL;
1134 static HRESULT WINAPI ShellImageData_Scale(IShellImageData *iface, ULONG cx, ULONG cy, InterpolationMode mode)
1136 ShellImageData *This = impl_from_IShellImageData(iface);
1138 FIXME("%p, %u, %u, %#x: stub\n", This, cx, cy, mode);
1140 return E_NOTIMPL;
1143 static HRESULT WINAPI ShellImageData_DiscardEdit(IShellImageData *iface)
1145 ShellImageData *This = impl_from_IShellImageData(iface);
1147 FIXME("%p: stub\n", This);
1149 return E_NOTIMPL;
1152 static HRESULT WINAPI ShellImageDate_SetEncoderParams(IShellImageData *iface, IPropertyBag *params)
1154 ShellImageData *This = impl_from_IShellImageData(iface);
1156 FIXME("%p, %p: stub\n", This, params);
1158 return E_NOTIMPL;
1161 static HRESULT WINAPI ShellImageData_DisplayName(IShellImageData *iface, LPWSTR name, UINT count)
1163 ShellImageData *This = impl_from_IShellImageData(iface);
1165 FIXME("%p, %p, %u: stub\n", This, name, count);
1167 return E_NOTIMPL;
1170 static HRESULT WINAPI ShellImageData_GetResolution(IShellImageData *iface, ULONG *res_x, ULONG *res_y)
1172 ShellImageData *This = impl_from_IShellImageData(iface);
1174 FIXME("%p, %p, %p: stub\n", This, res_x, res_y);
1176 return E_NOTIMPL;
1179 static HRESULT WINAPI ShellImageData_GetEncoderParams(IShellImageData *iface, GUID *format, EncoderParameters **params)
1181 ShellImageData *This = impl_from_IShellImageData(iface);
1183 FIXME("%p, %p, %p: stub\n", This, format, params);
1185 return E_NOTIMPL;
1188 static HRESULT WINAPI ShellImageData_RegisterAbort(IShellImageData *iface, IShellImageDataAbort *abort,
1189 IShellImageDataAbort **prev)
1191 ShellImageData *This = impl_from_IShellImageData(iface);
1193 FIXME("%p, %p, %p: stub\n", This, abort, prev);
1195 return E_NOTIMPL;
1198 static HRESULT WINAPI ShellImageData_CloneFrame(IShellImageData *iface, Image **frame)
1200 ShellImageData *This = impl_from_IShellImageData(iface);
1202 FIXME("%p, %p: stub\n", This, frame);
1204 return E_NOTIMPL;
1207 static HRESULT WINAPI ShellImageData_ReplaceFrame(IShellImageData *iface, Image *frame)
1209 ShellImageData *This = impl_from_IShellImageData(iface);
1211 FIXME("%p, %p: stub\n", This, frame);
1213 return E_NOTIMPL;
1216 static const IShellImageDataVtbl ShellImageDataVtbl =
1218 ShellImageData_QueryInterface,
1219 ShellImageData_AddRef,
1220 ShellImageData_Release,
1221 ShellImageData_Decode,
1222 ShellImageData_Draw,
1223 ShellImageData_NextFrame,
1224 ShellImageData_NextPage,
1225 ShellImageData_PrevPage,
1226 ShellImageData_IsTransparent,
1227 ShellImageData_IsAnimated,
1228 ShellImageData_IsVector,
1229 ShellImageData_IsMultipage,
1230 ShellImageData_IsEditable,
1231 ShellImageData_IsPrintable,
1232 ShellImageData_IsDecoded,
1233 ShellImageData_GetCurrentPage,
1234 ShellImageData_GetPageCount,
1235 ShellImageDate_SelectPage,
1236 ShellImageData_GetSize,
1237 ShellImageData_GetRawDataFormat,
1238 ShellImageData_GetPixelFormat,
1239 ShellImageData_GetDelay,
1240 ShellImageData_GetProperties,
1241 ShellImageData_Rotate,
1242 ShellImageData_Scale,
1243 ShellImageData_DiscardEdit,
1244 ShellImageDate_SetEncoderParams,
1245 ShellImageData_DisplayName,
1246 ShellImageData_GetResolution,
1247 ShellImageData_GetEncoderParams,
1248 ShellImageData_RegisterAbort,
1249 ShellImageData_CloneFrame,
1250 ShellImageData_ReplaceFrame,
1253 static HRESULT create_shellimagedata_from_path(const WCHAR *path, IShellImageData **data)
1255 ShellImageData *This;
1257 This = SHAlloc(sizeof(*This));
1259 This->IShellImageData_iface.lpVtbl = &ShellImageDataVtbl;
1260 This->ref = 1;
1262 This->path = strdupW(path);
1263 This->image = NULL;
1265 *data = &This->IShellImageData_iface;
1266 return S_OK;
1269 /* IShellImageDataFactory */
1270 static HRESULT WINAPI ShellImageDataFactory_QueryInterface(IShellImageDataFactory *iface, REFIID riid, void **obj)
1272 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), obj);
1274 if (IsEqualIID(&IID_IShellImageDataFactory, riid) || IsEqualIID(&IID_IUnknown, riid))
1276 *obj = iface;
1278 else
1280 FIXME("not implemented for %s\n", debugstr_guid(riid));
1281 *obj = NULL;
1282 return E_NOINTERFACE;
1285 IUnknown_AddRef((IUnknown*)*obj);
1286 return S_OK;
1289 static ULONG WINAPI ShellImageDataFactory_AddRef(IShellImageDataFactory *iface)
1291 TRACE("(%p)\n", iface);
1293 return 2;
1296 static ULONG WINAPI ShellImageDataFactory_Release(IShellImageDataFactory *iface)
1298 TRACE("(%p)\n", iface);
1300 return 1;
1303 static HRESULT WINAPI ShellImageDataFactory_CreateIShellImageData(IShellImageDataFactory *iface, IShellImageData **data)
1305 FIXME("%p, %p: stub\n", iface, data);
1307 return E_NOTIMPL;
1310 static HRESULT WINAPI ShellImageDataFactory_CreateImageFromFile(IShellImageDataFactory *iface, const WCHAR *path,
1311 IShellImageData **data)
1313 TRACE("%p, %s, %p\n", iface, debugstr_w(path), data);
1315 return create_shellimagedata_from_path(path, data);
1318 static HRESULT WINAPI ShellImageDataFactory_CreateImageFromStream(IShellImageDataFactory *iface, IStream *stream,
1319 IShellImageData **data)
1321 FIXME("%p, %p, %p: stub\n", iface, stream, data);
1323 return E_NOTIMPL;
1326 static HRESULT WINAPI ShellImageDataFactory_GetDataFormatFromPath(IShellImageDataFactory *iface, const WCHAR *path,
1327 GUID *format)
1329 FIXME("%p, %s, %p: stub\n", iface, debugstr_w(path), format);
1331 return E_NOTIMPL;
1334 static const IShellImageDataFactoryVtbl ShellImageDataFactoryVtbl =
1336 ShellImageDataFactory_QueryInterface,
1337 ShellImageDataFactory_AddRef,
1338 ShellImageDataFactory_Release,
1339 ShellImageDataFactory_CreateIShellImageData,
1340 ShellImageDataFactory_CreateImageFromFile,
1341 ShellImageDataFactory_CreateImageFromStream,
1342 ShellImageDataFactory_GetDataFormatFromPath,
1345 static IShellImageDataFactory ShellImageDataFactory = { &ShellImageDataFactoryVtbl };
1347 HRESULT WINAPI ShellImageDataFactory_Constructor(IUnknown *outer, REFIID riid, void **obj)
1349 TRACE("%p %s %p\n", outer, debugstr_guid(riid), obj);
1351 if (outer)
1352 return CLASS_E_NOAGGREGATION;
1354 return IShellImageDataFactory_QueryInterface(&ShellImageDataFactory, riid, obj);