po: Updated Polish translation.
[wine.git] / dlls / shell32 / shellole.c
blobd3d972b96d1bc44cede330051a42f84d58f812a1
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_AutoComplete, IAutoComplete_Constructor},
71 {&CLSID_ControlPanel, IControlPanel_Constructor},
72 {&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
73 {&CLSID_FolderShortcut, FolderShortcut_Constructor},
74 {&CLSID_MyComputer, ISF_MyComputer_Constructor},
75 {&CLSID_MyDocuments, MyDocuments_Constructor},
76 {&CLSID_NetworkPlaces, ISF_NetworkPlaces_Constructor},
77 {&CLSID_Printers, Printers_Constructor},
78 {&CLSID_QueryAssociations, QueryAssociations_Constructor},
79 {&CLSID_RecycleBin, RecycleBin_Constructor},
80 {&CLSID_ShellDesktop, ISF_Desktop_Constructor},
81 {&CLSID_ShellFSFolder, IFSFolder_Constructor},
82 {&CLSID_ShellItem, IShellItem_Constructor},
83 {&CLSID_ShellLink, IShellLink_Constructor},
84 {&CLSID_UnixDosFolder, UnixDosFolder_Constructor},
85 {&CLSID_UnixFolder, UnixFolder_Constructor},
86 {&CLSID_ExplorerBrowser,ExplorerBrowser_Constructor},
87 {&CLSID_KnownFolderManager, KnownFolderManager_Constructor},
88 {&CLSID_Shell, IShellDispatch_Constructor},
89 {&CLSID_DestinationList, CustomDestinationList_Constructor},
90 {&CLSID_ShellImageDataFactory, ShellImageDataFactory_Constructor},
91 {NULL, NULL}
94 /*************************************************************************
95 * SHCoCreateInstance [SHELL32.102]
97 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
98 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
99 * SHLoadOLE for details.
101 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
102 * shell32.dll the function will load the object manually without the help of ole32
104 * NOTES
105 * exported by ordinal
107 * SEE ALSO
108 * CoCreateInstance, SHLoadOLE
110 HRESULT WINAPI SHCoCreateInstance(
111 LPCWSTR aclsid,
112 const CLSID *clsid,
113 LPUNKNOWN pUnkOuter,
114 REFIID refiid,
115 LPVOID *ppv)
117 DWORD hres;
118 IID iid;
119 const CLSID * myclsid = clsid;
120 WCHAR sKeyName[MAX_PATH];
121 static const WCHAR sCLSID[] = {'C','L','S','I','D','\\','\0'};
122 WCHAR sClassID[60];
123 static const WCHAR sInProcServer32[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
124 static const WCHAR sLoadWithoutCOM[] = {'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
125 WCHAR sDllPath[MAX_PATH];
126 HKEY hKey = 0;
127 DWORD dwSize;
128 IClassFactory * pcf = NULL;
130 if(!ppv) return E_POINTER;
131 *ppv=NULL;
133 /* if the clsid is a string, convert it */
134 if (!clsid)
136 if (!aclsid) return REGDB_E_CLASSNOTREG;
137 SHCLSIDFromStringW(aclsid, &iid);
138 myclsid = &iid;
141 TRACE("(%p,%s,unk:%p,%s,%p)\n",
142 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
144 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
146 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
147 IClassFactory_Release(pcf);
148 goto end;
151 /* we look up the dll path in the registry */
152 SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
153 lstrcpyW(sKeyName, sCLSID);
154 lstrcatW(sKeyName, sClassID);
155 lstrcatW(sKeyName, sInProcServer32);
157 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
158 return E_ACCESSDENIED;
160 /* if a special registry key is set, we load a shell extension without help of OLE32 */
161 if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
163 /* load an external dll without ole32 */
164 HANDLE hLibrary;
165 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
166 DllGetClassObjectFunc DllGetClassObject;
168 dwSize = sizeof(sDllPath);
169 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
171 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
172 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
173 hres = E_ACCESSDENIED;
174 goto end;
175 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
176 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
177 FreeLibrary( hLibrary );
178 hres = E_ACCESSDENIED;
179 goto end;
180 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
181 TRACE("GetClassObject failed 0x%08x\n", hres);
182 goto end;
185 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
186 IClassFactory_Release(pcf);
187 } else {
189 /* load an external dll in the usual way */
190 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
193 end:
194 if (hKey) RegCloseKey(hKey);
195 if(hres!=S_OK)
197 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
198 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
199 ERR("class not found in registry\n");
202 TRACE("-- instance: %p\n",*ppv);
203 return hres;
206 /*************************************************************************
207 * DllGetClassObject [SHELL32.@]
208 * SHDllGetClassObject [SHELL32.128]
210 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
212 IClassFactory * pcf = NULL;
213 HRESULT hres;
214 int i;
216 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
218 if (!ppv) return E_INVALIDARG;
219 *ppv = NULL;
221 /* search our internal interface table */
222 for(i=0;InterfaceTable[i].clsid;i++) {
223 if(IsEqualIID(InterfaceTable[i].clsid, rclsid)) {
224 TRACE("index[%u]\n", i);
225 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
226 break;
230 if (!pcf) {
231 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
232 return CLASS_E_CLASSNOTAVAILABLE;
235 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
236 IClassFactory_Release(pcf);
238 TRACE("-- pointer to class factory: %p\n",*ppv);
239 return hres;
242 /*************************************************************************
243 * SHCLSIDFromString [SHELL32.147]
245 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
246 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
248 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
250 * NOTES
251 * exported by ordinal
253 * SEE ALSO
254 * CLSIDFromString, SHLoadOLE
256 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
258 WCHAR buffer[40];
259 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
260 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
261 return CO_E_CLASSSTRING;
262 return CLSIDFromString( buffer, id );
264 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
266 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
267 return CLSIDFromString(clsid, id);
269 DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
271 if (SHELL_OsIsUnicode())
272 return SHCLSIDFromStringW (clsid, id);
273 return SHCLSIDFromStringA (clsid, id);
276 /*************************************************************************
277 * SHGetMalloc [SHELL32.@]
279 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
280 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
281 * see SHLoadOLE for details.
283 * PARAMS
284 * lpmal [O] Destination for IMalloc interface.
286 * RETURNS
287 * Success: S_OK. lpmal contains the shells IMalloc interface.
288 * Failure. An HRESULT error code.
290 * SEE ALSO
291 * CoGetMalloc, SHLoadOLE
293 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
295 TRACE("(%p)\n", lpmal);
296 return CoGetMalloc(MEMCTX_TASK, lpmal);
299 /*************************************************************************
300 * SHAlloc [SHELL32.196]
302 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
303 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
304 * see SHLoadOLE for details.
306 * NOTES
307 * exported by ordinal
309 * SEE ALSO
310 * CoTaskMemAlloc, SHLoadOLE
312 LPVOID WINAPI SHAlloc(DWORD len)
314 LPVOID ret;
316 ret = CoTaskMemAlloc(len);
317 TRACE("%u bytes at %p\n",len, ret);
318 return ret;
321 /*************************************************************************
322 * SHFree [SHELL32.195]
324 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
325 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
326 * see SHLoadOLE for details.
328 * NOTES
329 * exported by ordinal
331 * SEE ALSO
332 * CoTaskMemFree, SHLoadOLE
334 void WINAPI SHFree(LPVOID pv)
336 TRACE("%p\n",pv);
337 CoTaskMemFree(pv);
340 /*************************************************************************
341 * SHGetDesktopFolder [SHELL32.@]
343 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
345 HRESULT hres;
347 TRACE("(%p)\n", psf);
349 if(!psf) return E_INVALIDARG;
351 *psf = NULL;
352 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
354 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
355 return hres;
357 /**************************************************************************
358 * Default ClassFactory Implementation
360 * SHCreateDefClassObject
362 * NOTES
363 * Helper function for dlls without their own classfactory.
364 * A generic classfactory is returned.
365 * When the CreateInstance of the cf is called the callback is executed.
368 typedef struct
370 IClassFactory IClassFactory_iface;
371 LONG ref;
372 CLSID *rclsid;
373 LPFNCREATEINSTANCE lpfnCI;
374 const IID * riidInst;
375 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
376 } IDefClFImpl;
378 static inline IDefClFImpl *impl_from_IClassFactory(IClassFactory *iface)
380 return CONTAINING_RECORD(iface, IDefClFImpl, IClassFactory_iface);
383 static const IClassFactoryVtbl dclfvt;
385 /**************************************************************************
386 * IDefClF_fnConstructor
389 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
391 IDefClFImpl* lpclf;
393 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
394 lpclf->ref = 1;
395 lpclf->IClassFactory_iface.lpVtbl = &dclfvt;
396 lpclf->lpfnCI = lpfnCI;
397 lpclf->pcRefDll = pcRefDll;
399 if (pcRefDll) InterlockedIncrement(pcRefDll);
400 lpclf->riidInst = riidInst;
402 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
403 return (LPCLASSFACTORY)lpclf;
405 /**************************************************************************
406 * IDefClF_fnQueryInterface
408 static HRESULT WINAPI IDefClF_fnQueryInterface(
409 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
411 IDefClFImpl *This = impl_from_IClassFactory(iface);
413 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
415 *ppvObj = NULL;
417 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
418 *ppvObj = This;
419 InterlockedIncrement(&This->ref);
420 return S_OK;
423 TRACE("-- E_NOINTERFACE\n");
424 return E_NOINTERFACE;
426 /******************************************************************************
427 * IDefClF_fnAddRef
429 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
431 IDefClFImpl *This = impl_from_IClassFactory(iface);
432 ULONG refCount = InterlockedIncrement(&This->ref);
434 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
436 return refCount;
438 /******************************************************************************
439 * IDefClF_fnRelease
441 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
443 IDefClFImpl *This = impl_from_IClassFactory(iface);
444 ULONG refCount = InterlockedDecrement(&This->ref);
446 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
448 if (!refCount)
450 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
452 TRACE("-- destroying IClassFactory(%p)\n",This);
453 HeapFree(GetProcessHeap(),0,This);
454 return 0;
456 return refCount;
458 /******************************************************************************
459 * IDefClF_fnCreateInstance
461 static HRESULT WINAPI IDefClF_fnCreateInstance(
462 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
464 IDefClFImpl *This = impl_from_IClassFactory(iface);
466 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
468 *ppvObject = NULL;
470 if ( This->riidInst==NULL ||
471 IsEqualCLSID(riid, This->riidInst) ||
472 IsEqualCLSID(riid, &IID_IUnknown) )
474 return This->lpfnCI(pUnkOuter, riid, ppvObject);
477 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
478 return E_NOINTERFACE;
480 /******************************************************************************
481 * IDefClF_fnLockServer
483 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
485 IDefClFImpl *This = impl_from_IClassFactory(iface);
486 TRACE("%p->(0x%x), not implemented\n",This, fLock);
487 return E_NOTIMPL;
490 static const IClassFactoryVtbl dclfvt =
492 IDefClF_fnQueryInterface,
493 IDefClF_fnAddRef,
494 IDefClF_fnRelease,
495 IDefClF_fnCreateInstance,
496 IDefClF_fnLockServer
499 /******************************************************************************
500 * SHCreateDefClassObject [SHELL32.70]
502 HRESULT WINAPI SHCreateDefClassObject(
503 REFIID riid,
504 LPVOID* ppv,
505 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
506 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
507 REFIID riidInst) /* [in] optional interface to the instance */
509 IClassFactory * pcf;
511 TRACE("%s %p %p %p %s\n",
512 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
514 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
515 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
516 *ppv = pcf;
517 return S_OK;
520 /*************************************************************************
521 * DragAcceptFiles [SHELL32.@]
523 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
525 LONG exstyle;
527 if( !IsWindow(hWnd) ) return;
528 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
529 if (b)
530 exstyle |= WS_EX_ACCEPTFILES;
531 else
532 exstyle &= ~WS_EX_ACCEPTFILES;
533 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
536 /*************************************************************************
537 * DragFinish [SHELL32.@]
539 void WINAPI DragFinish(HDROP h)
541 TRACE("\n");
542 GlobalFree(h);
545 /*************************************************************************
546 * DragQueryPoint [SHELL32.@]
548 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
550 DROPFILES *lpDropFileStruct;
551 BOOL bRet;
553 TRACE("\n");
555 lpDropFileStruct = GlobalLock(hDrop);
557 *p = lpDropFileStruct->pt;
558 bRet = lpDropFileStruct->fNC;
560 GlobalUnlock(hDrop);
561 return bRet;
564 /*************************************************************************
565 * DragQueryFileA [SHELL32.@]
566 * DragQueryFile [SHELL32.@]
568 UINT WINAPI DragQueryFileA(
569 HDROP hDrop,
570 UINT lFile,
571 LPSTR lpszFile,
572 UINT lLength)
574 LPSTR lpDrop;
575 UINT i = 0;
576 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
578 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
580 if(!lpDropFileStruct) goto end;
582 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
584 if(lpDropFileStruct->fWide) {
585 LPWSTR lpszFileW = NULL;
587 if(lpszFile && lFile != 0xFFFFFFFF) {
588 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
589 if(lpszFileW == NULL) {
590 goto end;
593 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
595 if(lpszFileW) {
596 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
597 HeapFree(GetProcessHeap(), 0, lpszFileW);
599 goto end;
602 while (i++ < lFile)
604 while (*lpDrop++); /* skip filename */
605 if (!*lpDrop)
607 i = (lFile == 0xFFFFFFFF) ? i : 0;
608 goto end;
612 i = strlen(lpDrop);
613 if (!lpszFile ) goto end; /* needed buffer size */
614 lstrcpynA (lpszFile, lpDrop, lLength);
615 end:
616 GlobalUnlock(hDrop);
617 return i;
620 /*************************************************************************
621 * DragQueryFileW [SHELL32.@]
623 UINT WINAPI DragQueryFileW(
624 HDROP hDrop,
625 UINT lFile,
626 LPWSTR lpszwFile,
627 UINT lLength)
629 LPWSTR lpwDrop;
630 UINT i = 0;
631 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
633 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
635 if(!lpDropFileStruct) goto end;
637 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
639 if(lpDropFileStruct->fWide == FALSE) {
640 LPSTR lpszFileA = NULL;
642 if(lpszwFile && lFile != 0xFFFFFFFF) {
643 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
644 if(lpszFileA == NULL) {
645 goto end;
648 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
650 if(lpszFileA) {
651 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
652 HeapFree(GetProcessHeap(), 0, lpszFileA);
654 goto end;
657 i = 0;
658 while (i++ < lFile)
660 while (*lpwDrop++); /* skip filename */
661 if (!*lpwDrop)
663 i = (lFile == 0xFFFFFFFF) ? i : 0;
664 goto end;
668 i = strlenW(lpwDrop);
669 if ( !lpszwFile) goto end; /* needed buffer size */
670 lstrcpynW (lpszwFile, lpwDrop, lLength);
671 end:
672 GlobalUnlock(hDrop);
673 return i;
676 /*************************************************************************
677 * SHPropStgCreate [SHELL32.685]
679 HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
680 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
681 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
683 PROPSPEC prop;
684 PROPVARIANT ret;
685 HRESULT hres;
687 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
688 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
690 hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
692 switch(dwDisposition) {
693 case CREATE_ALWAYS:
694 if(SUCCEEDED(hres)) {
695 IPropertyStorage_Release(*ppstg);
696 hres = IPropertySetStorage_Delete(psstg, fmtid);
697 if(FAILED(hres))
698 return hres;
699 hres = E_FAIL;
702 case OPEN_ALWAYS:
703 case CREATE_NEW:
704 if(FAILED(hres))
705 hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
706 grfFlags, grfMode, ppstg);
708 case OPEN_EXISTING:
709 if(FAILED(hres))
710 return hres;
712 if(puCodePage) {
713 prop.ulKind = PRSPEC_PROPID;
714 prop.u.propid = PID_CODEPAGE;
715 hres = IPropertyStorage_ReadMultiple(*ppstg, 1, &prop, &ret);
716 if(FAILED(hres) || ret.vt!=VT_I2)
717 *puCodePage = 0;
718 else
719 *puCodePage = ret.u.iVal;
723 return S_OK;
726 /*************************************************************************
727 * SHPropStgReadMultiple [SHELL32.688]
729 HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
730 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
732 STATPROPSETSTG stat;
733 HRESULT hres;
735 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
737 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
738 hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
739 if(FAILED(hres))
740 return hres;
742 if(!uCodePage) {
743 PROPSPEC prop;
744 PROPVARIANT ret;
746 prop.ulKind = PRSPEC_PROPID;
747 prop.u.propid = PID_CODEPAGE;
748 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
749 if(FAILED(hres) || ret.vt!=VT_I2)
750 return S_OK;
752 uCodePage = ret.u.iVal;
755 hres = IPropertyStorage_Stat(pps, &stat);
756 if(FAILED(hres))
757 return S_OK;
759 /* TODO: do something with codepage and stat */
760 return S_OK;
763 /*************************************************************************
764 * SHPropStgWriteMultiple [SHELL32.689]
766 HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
767 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
769 STATPROPSETSTG stat;
770 UINT codepage;
771 HRESULT hres;
773 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
775 hres = IPropertyStorage_Stat(pps, &stat);
776 if(FAILED(hres))
777 return hres;
779 if(uCodePage && *uCodePage)
780 codepage = *uCodePage;
781 else {
782 PROPSPEC prop;
783 PROPVARIANT ret;
785 prop.ulKind = PRSPEC_PROPID;
786 prop.u.propid = PID_CODEPAGE;
787 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
788 if(FAILED(hres))
789 return hres;
790 if(ret.vt!=VT_I2 || !ret.u.iVal)
791 return E_FAIL;
793 codepage = ret.u.iVal;
794 if(uCodePage)
795 *uCodePage = codepage;
798 /* TODO: do something with codepage and stat */
800 hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
801 return hres;
804 /*************************************************************************
805 * SHCreateQueryCancelAutoPlayMoniker [SHELL32.@]
807 HRESULT WINAPI SHCreateQueryCancelAutoPlayMoniker(IMoniker **moniker)
809 TRACE("%p\n", moniker);
811 if (!moniker) return E_INVALIDARG;
812 return CreateClassMoniker(&CLSID_QueryCancelAutoPlay, moniker);
815 static HRESULT gpstatus_to_hresult(GpStatus status)
817 switch (status)
819 case Ok:
820 return S_OK;
821 case InvalidParameter:
822 return E_INVALIDARG;
823 case OutOfMemory:
824 return E_OUTOFMEMORY;
825 case NotImplemented:
826 return E_NOTIMPL;
827 default:
828 return E_FAIL;
832 /* IShellImageData */
833 typedef struct
835 IShellImageData IShellImageData_iface;
836 LONG ref;
838 WCHAR *path;
839 GpImage *image;
840 } ShellImageData;
842 static inline ShellImageData *impl_from_IShellImageData(IShellImageData *iface)
844 return CONTAINING_RECORD(iface, ShellImageData, IShellImageData_iface);
847 static HRESULT WINAPI ShellImageData_QueryInterface(IShellImageData *iface, REFIID riid, void **obj)
849 ShellImageData *This = impl_from_IShellImageData(iface);
851 TRACE("%p, %s, %p\n", This, debugstr_guid(riid), obj);
853 if (IsEqualIID(riid, &IID_IShellImageData) || IsEqualIID(riid, &IID_IUnknown))
855 *obj = &This->IShellImageData_iface;
856 IShellImageData_AddRef(iface);
857 return S_OK;
860 *obj = NULL;
861 return E_NOINTERFACE;
864 static ULONG WINAPI ShellImageData_AddRef(IShellImageData *iface)
866 ShellImageData *This = impl_from_IShellImageData(iface);
867 ULONG ref = InterlockedIncrement(&This->ref);
869 TRACE("%p, %u\n", This, ref);
871 return ref;
874 static ULONG WINAPI ShellImageData_Release(IShellImageData *iface)
876 ShellImageData *This = impl_from_IShellImageData(iface);
877 ULONG ref = InterlockedDecrement(&This->ref);
879 TRACE("%p, %u\n", This, ref);
881 if (!ref)
883 GdipDisposeImage(This->image);
884 HeapFree(GetProcessHeap(), 0, This->path);
885 SHFree(This);
888 return ref;
891 static HRESULT WINAPI ShellImageData_Decode(IShellImageData *iface, DWORD flags, ULONG cx_desired, ULONG cy_desired)
893 ShellImageData *This = impl_from_IShellImageData(iface);
894 GpImage *image;
895 HRESULT hr;
897 TRACE("%p, %#x, %u, %u\n", This, flags, cx_desired, cy_desired);
899 if (This->image)
900 return S_FALSE;
902 if (flags & SHIMGDEC_LOADFULL)
903 FIXME("LOADFULL flag ignored\n");
905 hr = gpstatus_to_hresult(GdipLoadImageFromFile(This->path, &image));
906 if (FAILED(hr))
907 return hr;
909 if (flags & SHIMGDEC_THUMBNAIL)
911 hr = gpstatus_to_hresult(GdipGetImageThumbnail(image, cx_desired, cy_desired, &This->image, NULL, NULL));
912 GdipDisposeImage(image);
914 else
915 This->image = image;
917 return hr;
920 static HRESULT WINAPI ShellImageData_Draw(IShellImageData *iface, HDC hdc, RECT *dest, RECT *src)
922 ShellImageData *This = impl_from_IShellImageData(iface);
923 GpGraphics *graphics;
924 HRESULT hr;
926 TRACE("%p, %p, %s, %s\n", This, hdc, wine_dbgstr_rect(dest), wine_dbgstr_rect(src));
928 if (!This->image)
929 return E_FAIL;
931 if (!dest)
932 return E_INVALIDARG;
934 if (!src)
935 return S_OK;
937 hr = gpstatus_to_hresult(GdipCreateFromHDC(hdc, &graphics));
938 if (FAILED(hr))
939 return hr;
941 hr = gpstatus_to_hresult(GdipDrawImageRectRectI(graphics, This->image, dest->left, dest->top, dest->right - dest->left,
942 dest->bottom - dest->top, src->left, src->top, src->right - src->left, src->bottom - src->top,
943 UnitPixel, NULL, NULL, NULL));
944 GdipDeleteGraphics(graphics);
946 return hr;
949 static HRESULT WINAPI ShellImageData_NextFrame(IShellImageData *iface)
951 ShellImageData *This = impl_from_IShellImageData(iface);
953 FIXME("%p: stub\n", This);
955 return E_NOTIMPL;
958 static HRESULT WINAPI ShellImageData_NextPage(IShellImageData *iface)
960 ShellImageData *This = impl_from_IShellImageData(iface);
962 FIXME("%p: stub\n", This);
964 return E_NOTIMPL;
967 static HRESULT WINAPI ShellImageData_PrevPage(IShellImageData *iface)
969 ShellImageData *This = impl_from_IShellImageData(iface);
971 FIXME("%p: stub\n", This);
973 return E_NOTIMPL;
976 static HRESULT WINAPI ShellImageData_IsTransparent(IShellImageData *iface)
978 ShellImageData *This = impl_from_IShellImageData(iface);
980 FIXME("%p: stub\n", This);
982 return E_NOTIMPL;
985 static HRESULT WINAPI ShellImageData_IsAnimated(IShellImageData *iface)
987 ShellImageData *This = impl_from_IShellImageData(iface);
989 FIXME("%p: stub\n", This);
991 return E_NOTIMPL;
994 static HRESULT WINAPI ShellImageData_IsVector(IShellImageData *iface)
996 ShellImageData *This = impl_from_IShellImageData(iface);
998 FIXME("%p: stub\n", This);
1000 return E_NOTIMPL;
1003 static HRESULT WINAPI ShellImageData_IsMultipage(IShellImageData *iface)
1005 ShellImageData *This = impl_from_IShellImageData(iface);
1007 FIXME("%p: stub\n", This);
1009 return E_NOTIMPL;
1012 static HRESULT WINAPI ShellImageData_IsEditable(IShellImageData *iface)
1014 ShellImageData *This = impl_from_IShellImageData(iface);
1016 FIXME("%p: stub\n", This);
1018 return E_NOTIMPL;
1021 static HRESULT WINAPI ShellImageData_IsPrintable(IShellImageData *iface)
1023 ShellImageData *This = impl_from_IShellImageData(iface);
1025 FIXME("%p: stub\n", This);
1027 return E_NOTIMPL;
1030 static HRESULT WINAPI ShellImageData_IsDecoded(IShellImageData *iface)
1032 ShellImageData *This = impl_from_IShellImageData(iface);
1034 FIXME("%p: stub\n", This);
1036 return E_NOTIMPL;
1039 static HRESULT WINAPI ShellImageData_GetCurrentPage(IShellImageData *iface, ULONG *page)
1041 ShellImageData *This = impl_from_IShellImageData(iface);
1043 FIXME("%p: stub\n", This);
1045 return E_NOTIMPL;
1048 static HRESULT WINAPI ShellImageData_GetPageCount(IShellImageData *iface, ULONG *count)
1050 ShellImageData *This = impl_from_IShellImageData(iface);
1052 FIXME("%p, %p: stub\n", This, count);
1054 return E_NOTIMPL;
1057 static HRESULT WINAPI ShellImageDate_SelectPage(IShellImageData *iface, ULONG page)
1059 ShellImageData *This = impl_from_IShellImageData(iface);
1061 FIXME("%p, %u: stub\n", This, page);
1063 return E_NOTIMPL;
1066 static HRESULT WINAPI ShellImageData_GetSize(IShellImageData *iface, SIZE *size)
1068 ShellImageData *This = impl_from_IShellImageData(iface);
1069 REAL cx, cy;
1070 HRESULT hr;
1072 TRACE("%p, %p\n", This, size);
1074 if (!This->image)
1075 return E_FAIL;
1077 hr = gpstatus_to_hresult(GdipGetImageDimension(This->image, &cx, &cy));
1078 if (SUCCEEDED(hr))
1080 size->cx = cx;
1081 size->cy = cy;
1084 return hr;
1087 static HRESULT WINAPI ShellImageData_GetRawDataFormat(IShellImageData *iface, GUID *format)
1089 ShellImageData *This = impl_from_IShellImageData(iface);
1091 FIXME("%p, %p: stub\n", This, format);
1093 return E_NOTIMPL;
1096 static HRESULT WINAPI ShellImageData_GetPixelFormat(IShellImageData *iface, PixelFormat *format)
1098 ShellImageData *This = impl_from_IShellImageData(iface);
1100 FIXME("%p, %p: stub\n", This, format);
1102 return E_NOTIMPL;
1105 static HRESULT WINAPI ShellImageData_GetDelay(IShellImageData *iface, DWORD *delay)
1107 ShellImageData *This = impl_from_IShellImageData(iface);
1109 FIXME("%p, %p: stub\n", This, delay);
1111 return E_NOTIMPL;
1114 static HRESULT WINAPI ShellImageData_GetProperties(IShellImageData *iface, DWORD mode, IPropertySetStorage **props)
1116 ShellImageData *This = impl_from_IShellImageData(iface);
1118 FIXME("%p, %#x, %p: stub\n", This, mode, props);
1120 return E_NOTIMPL;
1123 static HRESULT WINAPI ShellImageData_Rotate(IShellImageData *iface, DWORD angle)
1125 ShellImageData *This = impl_from_IShellImageData(iface);
1127 FIXME("%p, %u: stub\n", This, angle);
1129 return E_NOTIMPL;
1132 static HRESULT WINAPI ShellImageData_Scale(IShellImageData *iface, ULONG cx, ULONG cy, InterpolationMode mode)
1134 ShellImageData *This = impl_from_IShellImageData(iface);
1136 FIXME("%p, %u, %u, %#x: stub\n", This, cx, cy, mode);
1138 return E_NOTIMPL;
1141 static HRESULT WINAPI ShellImageData_DiscardEdit(IShellImageData *iface)
1143 ShellImageData *This = impl_from_IShellImageData(iface);
1145 FIXME("%p: stub\n", This);
1147 return E_NOTIMPL;
1150 static HRESULT WINAPI ShellImageDate_SetEncoderParams(IShellImageData *iface, IPropertyBag *params)
1152 ShellImageData *This = impl_from_IShellImageData(iface);
1154 FIXME("%p, %p: stub\n", This, params);
1156 return E_NOTIMPL;
1159 static HRESULT WINAPI ShellImageData_DisplayName(IShellImageData *iface, LPWSTR name, UINT count)
1161 ShellImageData *This = impl_from_IShellImageData(iface);
1163 FIXME("%p, %p, %u: stub\n", This, name, count);
1165 return E_NOTIMPL;
1168 static HRESULT WINAPI ShellImageData_GetResolution(IShellImageData *iface, ULONG *res_x, ULONG *res_y)
1170 ShellImageData *This = impl_from_IShellImageData(iface);
1172 FIXME("%p, %p, %p: stub\n", This, res_x, res_y);
1174 return E_NOTIMPL;
1177 static HRESULT WINAPI ShellImageData_GetEncoderParams(IShellImageData *iface, GUID *format, EncoderParameters **params)
1179 ShellImageData *This = impl_from_IShellImageData(iface);
1181 FIXME("%p, %p, %p: stub\n", This, format, params);
1183 return E_NOTIMPL;
1186 static HRESULT WINAPI ShellImageData_RegisterAbort(IShellImageData *iface, IShellImageDataAbort *abort,
1187 IShellImageDataAbort **prev)
1189 ShellImageData *This = impl_from_IShellImageData(iface);
1191 FIXME("%p, %p, %p: stub\n", This, abort, prev);
1193 return E_NOTIMPL;
1196 static HRESULT WINAPI ShellImageData_CloneFrame(IShellImageData *iface, Image **frame)
1198 ShellImageData *This = impl_from_IShellImageData(iface);
1200 FIXME("%p, %p: stub\n", This, frame);
1202 return E_NOTIMPL;
1205 static HRESULT WINAPI ShellImageData_ReplaceFrame(IShellImageData *iface, Image *frame)
1207 ShellImageData *This = impl_from_IShellImageData(iface);
1209 FIXME("%p, %p: stub\n", This, frame);
1211 return E_NOTIMPL;
1214 static const IShellImageDataVtbl ShellImageDataVtbl =
1216 ShellImageData_QueryInterface,
1217 ShellImageData_AddRef,
1218 ShellImageData_Release,
1219 ShellImageData_Decode,
1220 ShellImageData_Draw,
1221 ShellImageData_NextFrame,
1222 ShellImageData_NextPage,
1223 ShellImageData_PrevPage,
1224 ShellImageData_IsTransparent,
1225 ShellImageData_IsAnimated,
1226 ShellImageData_IsVector,
1227 ShellImageData_IsMultipage,
1228 ShellImageData_IsEditable,
1229 ShellImageData_IsPrintable,
1230 ShellImageData_IsDecoded,
1231 ShellImageData_GetCurrentPage,
1232 ShellImageData_GetPageCount,
1233 ShellImageDate_SelectPage,
1234 ShellImageData_GetSize,
1235 ShellImageData_GetRawDataFormat,
1236 ShellImageData_GetPixelFormat,
1237 ShellImageData_GetDelay,
1238 ShellImageData_GetProperties,
1239 ShellImageData_Rotate,
1240 ShellImageData_Scale,
1241 ShellImageData_DiscardEdit,
1242 ShellImageDate_SetEncoderParams,
1243 ShellImageData_DisplayName,
1244 ShellImageData_GetResolution,
1245 ShellImageData_GetEncoderParams,
1246 ShellImageData_RegisterAbort,
1247 ShellImageData_CloneFrame,
1248 ShellImageData_ReplaceFrame,
1251 static HRESULT create_shellimagedata_from_path(const WCHAR *path, IShellImageData **data)
1253 ShellImageData *This;
1255 This = SHAlloc(sizeof(*This));
1257 This->IShellImageData_iface.lpVtbl = &ShellImageDataVtbl;
1258 This->ref = 1;
1260 This->path = strdupW(path);
1261 This->image = NULL;
1263 *data = &This->IShellImageData_iface;
1264 return S_OK;
1267 /* IShellImageDataFactory */
1268 static HRESULT WINAPI ShellImageDataFactory_QueryInterface(IShellImageDataFactory *iface, REFIID riid, void **obj)
1270 TRACE("(%p, %s, %p)\n", iface, debugstr_guid(riid), obj);
1272 if (IsEqualIID(&IID_IShellImageDataFactory, riid) || IsEqualIID(&IID_IUnknown, riid))
1274 *obj = iface;
1276 else
1278 FIXME("not implemented for %s\n", debugstr_guid(riid));
1279 *obj = NULL;
1280 return E_NOINTERFACE;
1283 IUnknown_AddRef((IUnknown*)*obj);
1284 return S_OK;
1287 static ULONG WINAPI ShellImageDataFactory_AddRef(IShellImageDataFactory *iface)
1289 TRACE("(%p)\n", iface);
1291 return 2;
1294 static ULONG WINAPI ShellImageDataFactory_Release(IShellImageDataFactory *iface)
1296 TRACE("(%p)\n", iface);
1298 return 1;
1301 static HRESULT WINAPI ShellImageDataFactory_CreateIShellImageData(IShellImageDataFactory *iface, IShellImageData **data)
1303 FIXME("%p, %p: stub\n", iface, data);
1305 return E_NOTIMPL;
1308 static HRESULT WINAPI ShellImageDataFactory_CreateImageFromFile(IShellImageDataFactory *iface, const WCHAR *path,
1309 IShellImageData **data)
1311 TRACE("%p, %s, %p\n", iface, debugstr_w(path), data);
1313 return create_shellimagedata_from_path(path, data);
1316 static HRESULT WINAPI ShellImageDataFactory_CreateImageFromStream(IShellImageDataFactory *iface, IStream *stream,
1317 IShellImageData **data)
1319 FIXME("%p, %p, %p: stub\n", iface, stream, data);
1321 return E_NOTIMPL;
1324 static HRESULT WINAPI ShellImageDataFactory_GetDataFormatFromPath(IShellImageDataFactory *iface, const WCHAR *path,
1325 GUID *format)
1327 FIXME("%p, %s, %p: stub\n", iface, debugstr_w(path), format);
1329 return E_NOTIMPL;
1332 static const IShellImageDataFactoryVtbl ShellImageDataFactoryVtbl =
1334 ShellImageDataFactory_QueryInterface,
1335 ShellImageDataFactory_AddRef,
1336 ShellImageDataFactory_Release,
1337 ShellImageDataFactory_CreateIShellImageData,
1338 ShellImageDataFactory_CreateImageFromFile,
1339 ShellImageDataFactory_CreateImageFromStream,
1340 ShellImageDataFactory_GetDataFormatFromPath,
1343 static IShellImageDataFactory ShellImageDataFactory = { &ShellImageDataFactoryVtbl };
1345 HRESULT WINAPI ShellImageDataFactory_Constructor(IUnknown *outer, REFIID riid, void **obj)
1347 TRACE("%p %s %p\n", outer, debugstr_guid(riid), obj);
1349 if (outer)
1350 return CLASS_E_NOAGGREGATION;
1352 return IShellImageDataFactory_QueryInterface(&ShellImageDataFactory, riid, obj);