winetest: Fix handle leak.
[wine.git] / dlls / shell32 / shellole.c
blob49491a0fbc89b22f432020155a058219dba3a47a
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 "winreg.h"
40 #include "winerror.h"
42 #include "undocshell.h"
43 #include "wine/unicode.h"
44 #include "shell32_main.h"
46 #include "wine/debug.h"
47 #include "shlwapi.h"
48 #include "debughlp.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(shell);
52 extern INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax); /* shlwapi.24 */
54 /**************************************************************************
55 * Default ClassFactory types
57 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
58 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
60 /* this table contains all CLSIDs of shell32 objects */
61 static const struct {
62 REFIID riid;
63 LPFNCREATEINSTANCE lpfnCI;
64 } InterfaceTable[] = {
66 {&CLSID_AutoComplete, IAutoComplete_Constructor},
67 {&CLSID_ControlPanel, IControlPanel_Constructor},
68 {&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
69 {&CLSID_FolderShortcut, FolderShortcut_Constructor},
70 {&CLSID_MyComputer, ISF_MyComputer_Constructor},
71 {&CLSID_MyDocuments, MyDocuments_Constructor},
72 {&CLSID_NetworkPlaces, ISF_NetworkPlaces_Constructor},
73 {&CLSID_Printers, Printers_Constructor},
74 {&CLSID_QueryAssociations, QueryAssociations_Constructor},
75 {&CLSID_RecycleBin, RecycleBin_Constructor},
76 {&CLSID_ShellDesktop, ISF_Desktop_Constructor},
77 {&CLSID_ShellFSFolder, IFSFolder_Constructor},
78 {&CLSID_ShellItem, IShellItem_Constructor},
79 {&CLSID_ShellLink, IShellLink_Constructor},
80 {&CLSID_UnixDosFolder, UnixDosFolder_Constructor},
81 {&CLSID_UnixFolder, UnixFolder_Constructor},
82 {&CLSID_ExplorerBrowser,ExplorerBrowser_Constructor},
83 {&CLSID_KnownFolderManager, KnownFolderManager_Constructor},
84 {&CLSID_Shell, IShellDispatch_Constructor},
85 {NULL, NULL}
88 /*************************************************************************
89 * SHCoCreateInstance [SHELL32.102]
91 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
92 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
93 * SHLoadOLE for details.
95 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
96 * shell32.dll the function will load the object manually without the help of ole32
98 * NOTES
99 * exported by ordinal
101 * SEE ALSO
102 * CoCreateInstace, SHLoadOLE
104 HRESULT WINAPI SHCoCreateInstance(
105 LPCWSTR aclsid,
106 const CLSID *clsid,
107 LPUNKNOWN pUnkOuter,
108 REFIID refiid,
109 LPVOID *ppv)
111 DWORD hres;
112 IID iid;
113 const CLSID * myclsid = clsid;
114 WCHAR sKeyName[MAX_PATH];
115 static const WCHAR sCLSID[] = {'C','L','S','I','D','\\','\0'};
116 WCHAR sClassID[60];
117 static const WCHAR sInProcServer32[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
118 static const WCHAR sLoadWithoutCOM[] = {'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
119 WCHAR sDllPath[MAX_PATH];
120 HKEY hKey = 0;
121 DWORD dwSize;
122 IClassFactory * pcf = NULL;
124 if(!ppv) return E_POINTER;
125 *ppv=NULL;
127 /* if the clsid is a string, convert it */
128 if (!clsid)
130 if (!aclsid) return REGDB_E_CLASSNOTREG;
131 SHCLSIDFromStringW(aclsid, &iid);
132 myclsid = &iid;
135 TRACE("(%p,%s,unk:%p,%s,%p)\n",
136 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
138 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
140 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
141 IClassFactory_Release(pcf);
142 goto end;
145 /* we look up the dll path in the registry */
146 SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
147 lstrcpyW(sKeyName, sCLSID);
148 lstrcatW(sKeyName, sClassID);
149 lstrcatW(sKeyName, sInProcServer32);
151 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
152 return E_ACCESSDENIED;
154 /* if a special registry key is set, we load a shell extension without help of OLE32 */
155 if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
157 /* load an external dll without ole32 */
158 HANDLE hLibrary;
159 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
160 DllGetClassObjectFunc DllGetClassObject;
162 dwSize = sizeof(sDllPath);
163 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
165 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
166 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
167 hres = E_ACCESSDENIED;
168 goto end;
169 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
170 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
171 FreeLibrary( hLibrary );
172 hres = E_ACCESSDENIED;
173 goto end;
174 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
175 TRACE("GetClassObject failed 0x%08x\n", hres);
176 goto end;
179 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
180 IClassFactory_Release(pcf);
181 } else {
183 /* load an external dll in the usual way */
184 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
187 end:
188 if (hKey) RegCloseKey(hKey);
189 if(hres!=S_OK)
191 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
192 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
193 ERR("class not found in registry\n");
196 TRACE("-- instance: %p\n",*ppv);
197 return hres;
200 /*************************************************************************
201 * DllGetClassObject [SHELL32.@]
202 * SHDllGetClassObject [SHELL32.128]
204 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
206 HRESULT hres = E_OUTOFMEMORY;
207 IClassFactory * pcf = NULL;
208 int i;
210 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
212 if (!ppv) return E_INVALIDARG;
213 *ppv = NULL;
215 /* search our internal interface table */
216 for(i=0;InterfaceTable[i].riid;i++) {
217 if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
218 TRACE("index[%u]\n", i);
219 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
223 if (!pcf) {
224 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
225 return CLASS_E_CLASSNOTAVAILABLE;
228 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
229 IClassFactory_Release(pcf);
231 TRACE("-- pointer to class factory: %p\n",*ppv);
232 return hres;
235 /*************************************************************************
236 * SHCLSIDFromString [SHELL32.147]
238 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
239 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
241 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
243 * NOTES
244 * exported by ordinal
246 * SEE ALSO
247 * CLSIDFromString, SHLoadOLE
249 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
251 WCHAR buffer[40];
252 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
253 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
254 return CO_E_CLASSSTRING;
255 return CLSIDFromString( buffer, id );
257 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
259 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
260 return CLSIDFromString(clsid, id);
262 DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
264 if (SHELL_OsIsUnicode())
265 return SHCLSIDFromStringW (clsid, id);
266 return SHCLSIDFromStringA (clsid, id);
269 /*************************************************************************
270 * SHGetMalloc [SHELL32.@]
272 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
273 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
274 * see SHLoadOLE for details.
276 * PARAMS
277 * lpmal [O] Destination for IMalloc interface.
279 * RETURNS
280 * Success: S_OK. lpmal contains the shells IMalloc interface.
281 * Failure. An HRESULT error code.
283 * SEE ALSO
284 * CoGetMalloc, SHLoadOLE
286 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
288 TRACE("(%p)\n", lpmal);
289 return CoGetMalloc(MEMCTX_TASK, lpmal);
292 /*************************************************************************
293 * SHAlloc [SHELL32.196]
295 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
296 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
297 * see SHLoadOLE for details.
299 * NOTES
300 * exported by ordinal
302 * SEE ALSO
303 * CoTaskMemAlloc, SHLoadOLE
305 LPVOID WINAPI SHAlloc(DWORD len)
307 LPVOID ret;
309 ret = CoTaskMemAlloc(len);
310 TRACE("%u bytes at %p\n",len, ret);
311 return ret;
314 /*************************************************************************
315 * SHFree [SHELL32.195]
317 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
318 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
319 * see SHLoadOLE for details.
321 * NOTES
322 * exported by ordinal
324 * SEE ALSO
325 * CoTaskMemFree, SHLoadOLE
327 void WINAPI SHFree(LPVOID pv)
329 TRACE("%p\n",pv);
330 CoTaskMemFree(pv);
333 /*************************************************************************
334 * SHGetDesktopFolder [SHELL32.@]
336 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
338 HRESULT hres;
340 TRACE("(%p)\n", psf);
342 if(!psf) return E_INVALIDARG;
344 *psf = NULL;
345 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
347 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
348 return hres;
350 /**************************************************************************
351 * Default ClassFactory Implementation
353 * SHCreateDefClassObject
355 * NOTES
356 * Helper function for dlls without their own classfactory.
357 * A generic classfactory is returned.
358 * When the CreateInstance of the cf is called the callback is executed.
361 typedef struct
363 IClassFactory IClassFactory_iface;
364 LONG ref;
365 CLSID *rclsid;
366 LPFNCREATEINSTANCE lpfnCI;
367 const IID * riidInst;
368 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
369 } IDefClFImpl;
371 static inline IDefClFImpl *impl_from_IClassFactory(IClassFactory *iface)
373 return CONTAINING_RECORD(iface, IDefClFImpl, IClassFactory_iface);
376 static const IClassFactoryVtbl dclfvt;
378 /**************************************************************************
379 * IDefClF_fnConstructor
382 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
384 IDefClFImpl* lpclf;
386 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
387 lpclf->ref = 1;
388 lpclf->IClassFactory_iface.lpVtbl = &dclfvt;
389 lpclf->lpfnCI = lpfnCI;
390 lpclf->pcRefDll = pcRefDll;
392 if (pcRefDll) InterlockedIncrement(pcRefDll);
393 lpclf->riidInst = riidInst;
395 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
396 return (LPCLASSFACTORY)lpclf;
398 /**************************************************************************
399 * IDefClF_fnQueryInterface
401 static HRESULT WINAPI IDefClF_fnQueryInterface(
402 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
404 IDefClFImpl *This = impl_from_IClassFactory(iface);
406 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
408 *ppvObj = NULL;
410 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
411 *ppvObj = This;
412 InterlockedIncrement(&This->ref);
413 return S_OK;
416 TRACE("-- E_NOINTERFACE\n");
417 return E_NOINTERFACE;
419 /******************************************************************************
420 * IDefClF_fnAddRef
422 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
424 IDefClFImpl *This = impl_from_IClassFactory(iface);
425 ULONG refCount = InterlockedIncrement(&This->ref);
427 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
429 return refCount;
431 /******************************************************************************
432 * IDefClF_fnRelease
434 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
436 IDefClFImpl *This = impl_from_IClassFactory(iface);
437 ULONG refCount = InterlockedDecrement(&This->ref);
439 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
441 if (!refCount)
443 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
445 TRACE("-- destroying IClassFactory(%p)\n",This);
446 HeapFree(GetProcessHeap(),0,This);
447 return 0;
449 return refCount;
451 /******************************************************************************
452 * IDefClF_fnCreateInstance
454 static HRESULT WINAPI IDefClF_fnCreateInstance(
455 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
457 IDefClFImpl *This = impl_from_IClassFactory(iface);
459 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
461 *ppvObject = NULL;
463 if ( This->riidInst==NULL ||
464 IsEqualCLSID(riid, This->riidInst) ||
465 IsEqualCLSID(riid, &IID_IUnknown) )
467 return This->lpfnCI(pUnkOuter, riid, ppvObject);
470 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
471 return E_NOINTERFACE;
473 /******************************************************************************
474 * IDefClF_fnLockServer
476 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
478 IDefClFImpl *This = impl_from_IClassFactory(iface);
479 TRACE("%p->(0x%x), not implemented\n",This, fLock);
480 return E_NOTIMPL;
483 static const IClassFactoryVtbl dclfvt =
485 IDefClF_fnQueryInterface,
486 IDefClF_fnAddRef,
487 IDefClF_fnRelease,
488 IDefClF_fnCreateInstance,
489 IDefClF_fnLockServer
492 /******************************************************************************
493 * SHCreateDefClassObject [SHELL32.70]
495 HRESULT WINAPI SHCreateDefClassObject(
496 REFIID riid,
497 LPVOID* ppv,
498 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
499 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
500 REFIID riidInst) /* [in] optional interface to the instance */
502 IClassFactory * pcf;
504 TRACE("%s %p %p %p %s\n",
505 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
507 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
508 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
509 *ppv = pcf;
510 return NOERROR;
513 /*************************************************************************
514 * DragAcceptFiles [SHELL32.@]
516 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
518 LONG exstyle;
520 if( !IsWindow(hWnd) ) return;
521 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
522 if (b)
523 exstyle |= WS_EX_ACCEPTFILES;
524 else
525 exstyle &= ~WS_EX_ACCEPTFILES;
526 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
529 /*************************************************************************
530 * DragFinish [SHELL32.@]
532 void WINAPI DragFinish(HDROP h)
534 TRACE("\n");
535 GlobalFree(h);
538 /*************************************************************************
539 * DragQueryPoint [SHELL32.@]
541 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
543 DROPFILES *lpDropFileStruct;
544 BOOL bRet;
546 TRACE("\n");
548 lpDropFileStruct = GlobalLock(hDrop);
550 *p = lpDropFileStruct->pt;
551 bRet = lpDropFileStruct->fNC;
553 GlobalUnlock(hDrop);
554 return bRet;
557 /*************************************************************************
558 * DragQueryFileA [SHELL32.@]
559 * DragQueryFile [SHELL32.@]
561 UINT WINAPI DragQueryFileA(
562 HDROP hDrop,
563 UINT lFile,
564 LPSTR lpszFile,
565 UINT lLength)
567 LPSTR lpDrop;
568 UINT i = 0;
569 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
571 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
573 if(!lpDropFileStruct) goto end;
575 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
577 if(lpDropFileStruct->fWide) {
578 LPWSTR lpszFileW = NULL;
580 if(lpszFile) {
581 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
582 if(lpszFileW == NULL) {
583 goto end;
586 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
588 if(lpszFileW) {
589 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
590 HeapFree(GetProcessHeap(), 0, lpszFileW);
592 goto end;
595 while (i++ < lFile)
597 while (*lpDrop++); /* skip filename */
598 if (!*lpDrop)
600 i = (lFile == 0xFFFFFFFF) ? i : 0;
601 goto end;
605 i = strlen(lpDrop);
606 if (!lpszFile ) goto end; /* needed buffer size */
607 lstrcpynA (lpszFile, lpDrop, lLength);
608 end:
609 GlobalUnlock(hDrop);
610 return i;
613 /*************************************************************************
614 * DragQueryFileW [SHELL32.@]
616 UINT WINAPI DragQueryFileW(
617 HDROP hDrop,
618 UINT lFile,
619 LPWSTR lpszwFile,
620 UINT lLength)
622 LPWSTR lpwDrop;
623 UINT i = 0;
624 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
626 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
628 if(!lpDropFileStruct) goto end;
630 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
632 if(lpDropFileStruct->fWide == FALSE) {
633 LPSTR lpszFileA = NULL;
635 if(lpszwFile) {
636 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
637 if(lpszFileA == NULL) {
638 goto end;
641 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
643 if(lpszFileA) {
644 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
645 HeapFree(GetProcessHeap(), 0, lpszFileA);
647 goto end;
650 i = 0;
651 while (i++ < lFile)
653 while (*lpwDrop++); /* skip filename */
654 if (!*lpwDrop)
656 i = (lFile == 0xFFFFFFFF) ? i : 0;
657 goto end;
661 i = strlenW(lpwDrop);
662 if ( !lpszwFile) goto end; /* needed buffer size */
663 lstrcpynW (lpszwFile, lpwDrop, lLength);
664 end:
665 GlobalUnlock(hDrop);
666 return i;
669 /*************************************************************************
670 * SHPropStgCreate [SHELL32.685]
672 HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
673 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
674 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
676 PROPSPEC prop;
677 PROPVARIANT ret;
678 HRESULT hres;
680 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
681 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
683 hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
685 switch(dwDisposition) {
686 case CREATE_ALWAYS:
687 if(SUCCEEDED(hres)) {
688 IPropertyStorage_Release(*ppstg);
689 hres = IPropertySetStorage_Delete(psstg, fmtid);
690 if(FAILED(hres))
691 return hres;
692 hres = E_FAIL;
695 case OPEN_ALWAYS:
696 case CREATE_NEW:
697 if(FAILED(hres))
698 hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
699 grfFlags, grfMode, ppstg);
701 case OPEN_EXISTING:
702 if(FAILED(hres))
703 return hres;
705 if(puCodePage) {
706 prop.ulKind = PRSPEC_PROPID;
707 prop.u.propid = PID_CODEPAGE;
708 hres = IPropertyStorage_ReadMultiple(*ppstg, 1, &prop, &ret);
709 if(FAILED(hres) || ret.vt!=VT_I2)
710 *puCodePage = 0;
711 else
712 *puCodePage = ret.u.iVal;
716 return S_OK;
719 /*************************************************************************
720 * SHPropStgReadMultiple [SHELL32.688]
722 HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
723 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
725 STATPROPSETSTG stat;
726 HRESULT hres;
728 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
730 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
731 hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
732 if(FAILED(hres))
733 return hres;
735 if(!uCodePage) {
736 PROPSPEC prop;
737 PROPVARIANT ret;
739 prop.ulKind = PRSPEC_PROPID;
740 prop.u.propid = PID_CODEPAGE;
741 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
742 if(FAILED(hres) || ret.vt!=VT_I2)
743 return S_OK;
745 uCodePage = ret.u.iVal;
748 hres = IPropertyStorage_Stat(pps, &stat);
749 if(FAILED(hres))
750 return S_OK;
752 /* TODO: do something with codepage and stat */
753 return S_OK;
756 /*************************************************************************
757 * SHPropStgWriteMultiple [SHELL32.689]
759 HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
760 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
762 STATPROPSETSTG stat;
763 UINT codepage;
764 HRESULT hres;
766 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
768 hres = IPropertyStorage_Stat(pps, &stat);
769 if(FAILED(hres))
770 return hres;
772 if(uCodePage && *uCodePage)
773 codepage = *uCodePage;
774 else {
775 PROPSPEC prop;
776 PROPVARIANT ret;
778 prop.ulKind = PRSPEC_PROPID;
779 prop.u.propid = PID_CODEPAGE;
780 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
781 if(FAILED(hres))
782 return hres;
783 if(ret.vt!=VT_I2 || !ret.u.iVal)
784 return E_FAIL;
786 codepage = ret.u.iVal;
787 if(uCodePage)
788 *uCodePage = codepage;
791 /* TODO: do something with codepage and stat */
793 hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
794 return hres;