msvcp90: Make a couple more numpunct_*_use_facet() functions static.
[wine/multimedia.git] / dlls / shell32 / shellole.c
blobb3f847c53f657eac9e5202dd3d63dda89dafa3df
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_ApplicationAssociationRegistration, ApplicationAssociationRegistration_Constructor},
67 {&CLSID_AutoComplete, IAutoComplete_Constructor},
68 {&CLSID_ControlPanel, IControlPanel_Constructor},
69 {&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
70 {&CLSID_FolderShortcut, FolderShortcut_Constructor},
71 {&CLSID_MyComputer, ISF_MyComputer_Constructor},
72 {&CLSID_MyDocuments, MyDocuments_Constructor},
73 {&CLSID_NetworkPlaces, ISF_NetworkPlaces_Constructor},
74 {&CLSID_Printers, Printers_Constructor},
75 {&CLSID_QueryAssociations, QueryAssociations_Constructor},
76 {&CLSID_RecycleBin, RecycleBin_Constructor},
77 {&CLSID_ShellDesktop, ISF_Desktop_Constructor},
78 {&CLSID_ShellFSFolder, IFSFolder_Constructor},
79 {&CLSID_ShellItem, IShellItem_Constructor},
80 {&CLSID_ShellLink, IShellLink_Constructor},
81 {&CLSID_UnixDosFolder, UnixDosFolder_Constructor},
82 {&CLSID_UnixFolder, UnixFolder_Constructor},
83 {&CLSID_ExplorerBrowser,ExplorerBrowser_Constructor},
84 {&CLSID_KnownFolderManager, KnownFolderManager_Constructor},
85 {&CLSID_Shell, IShellDispatch_Constructor},
86 {NULL, NULL}
89 /*************************************************************************
90 * SHCoCreateInstance [SHELL32.102]
92 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
93 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
94 * SHLoadOLE for details.
96 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
97 * shell32.dll the function will load the object manually without the help of ole32
99 * NOTES
100 * exported by ordinal
102 * SEE ALSO
103 * CoCreateInstace, SHLoadOLE
105 HRESULT WINAPI SHCoCreateInstance(
106 LPCWSTR aclsid,
107 const CLSID *clsid,
108 LPUNKNOWN pUnkOuter,
109 REFIID refiid,
110 LPVOID *ppv)
112 DWORD hres;
113 IID iid;
114 const CLSID * myclsid = clsid;
115 WCHAR sKeyName[MAX_PATH];
116 static const WCHAR sCLSID[] = {'C','L','S','I','D','\\','\0'};
117 WCHAR sClassID[60];
118 static const WCHAR sInProcServer32[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
119 static const WCHAR sLoadWithoutCOM[] = {'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
120 WCHAR sDllPath[MAX_PATH];
121 HKEY hKey = 0;
122 DWORD dwSize;
123 IClassFactory * pcf = NULL;
125 if(!ppv) return E_POINTER;
126 *ppv=NULL;
128 /* if the clsid is a string, convert it */
129 if (!clsid)
131 if (!aclsid) return REGDB_E_CLASSNOTREG;
132 SHCLSIDFromStringW(aclsid, &iid);
133 myclsid = &iid;
136 TRACE("(%p,%s,unk:%p,%s,%p)\n",
137 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
139 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
141 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
142 IClassFactory_Release(pcf);
143 goto end;
146 /* we look up the dll path in the registry */
147 SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
148 lstrcpyW(sKeyName, sCLSID);
149 lstrcatW(sKeyName, sClassID);
150 lstrcatW(sKeyName, sInProcServer32);
152 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
153 return E_ACCESSDENIED;
155 /* if a special registry key is set, we load a shell extension without help of OLE32 */
156 if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
158 /* load an external dll without ole32 */
159 HANDLE hLibrary;
160 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
161 DllGetClassObjectFunc DllGetClassObject;
163 dwSize = sizeof(sDllPath);
164 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
166 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
167 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
168 hres = E_ACCESSDENIED;
169 goto end;
170 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
171 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
172 FreeLibrary( hLibrary );
173 hres = E_ACCESSDENIED;
174 goto end;
175 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
176 TRACE("GetClassObject failed 0x%08x\n", hres);
177 goto end;
180 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
181 IClassFactory_Release(pcf);
182 } else {
184 /* load an external dll in the usual way */
185 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
188 end:
189 if (hKey) RegCloseKey(hKey);
190 if(hres!=S_OK)
192 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
193 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
194 ERR("class not found in registry\n");
197 TRACE("-- instance: %p\n",*ppv);
198 return hres;
201 /*************************************************************************
202 * DllGetClassObject [SHELL32.@]
203 * SHDllGetClassObject [SHELL32.128]
205 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
207 HRESULT hres = E_OUTOFMEMORY;
208 IClassFactory * pcf = NULL;
209 int i;
211 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
213 if (!ppv) return E_INVALIDARG;
214 *ppv = NULL;
216 /* search our internal interface table */
217 for(i=0;InterfaceTable[i].riid;i++) {
218 if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
219 TRACE("index[%u]\n", i);
220 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
224 if (!pcf) {
225 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
226 return CLASS_E_CLASSNOTAVAILABLE;
229 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
230 IClassFactory_Release(pcf);
232 TRACE("-- pointer to class factory: %p\n",*ppv);
233 return hres;
236 /*************************************************************************
237 * SHCLSIDFromString [SHELL32.147]
239 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
240 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
242 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
244 * NOTES
245 * exported by ordinal
247 * SEE ALSO
248 * CLSIDFromString, SHLoadOLE
250 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
252 WCHAR buffer[40];
253 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
254 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
255 return CO_E_CLASSSTRING;
256 return CLSIDFromString( buffer, id );
258 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
260 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
261 return CLSIDFromString(clsid, id);
263 DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
265 if (SHELL_OsIsUnicode())
266 return SHCLSIDFromStringW (clsid, id);
267 return SHCLSIDFromStringA (clsid, id);
270 /*************************************************************************
271 * SHGetMalloc [SHELL32.@]
273 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
274 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
275 * see SHLoadOLE for details.
277 * PARAMS
278 * lpmal [O] Destination for IMalloc interface.
280 * RETURNS
281 * Success: S_OK. lpmal contains the shells IMalloc interface.
282 * Failure. An HRESULT error code.
284 * SEE ALSO
285 * CoGetMalloc, SHLoadOLE
287 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
289 TRACE("(%p)\n", lpmal);
290 return CoGetMalloc(MEMCTX_TASK, lpmal);
293 /*************************************************************************
294 * SHAlloc [SHELL32.196]
296 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
297 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
298 * see SHLoadOLE for details.
300 * NOTES
301 * exported by ordinal
303 * SEE ALSO
304 * CoTaskMemAlloc, SHLoadOLE
306 LPVOID WINAPI SHAlloc(DWORD len)
308 LPVOID ret;
310 ret = CoTaskMemAlloc(len);
311 TRACE("%u bytes at %p\n",len, ret);
312 return ret;
315 /*************************************************************************
316 * SHFree [SHELL32.195]
318 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
319 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
320 * see SHLoadOLE for details.
322 * NOTES
323 * exported by ordinal
325 * SEE ALSO
326 * CoTaskMemFree, SHLoadOLE
328 void WINAPI SHFree(LPVOID pv)
330 TRACE("%p\n",pv);
331 CoTaskMemFree(pv);
334 /*************************************************************************
335 * SHGetDesktopFolder [SHELL32.@]
337 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
339 HRESULT hres;
341 TRACE("(%p)\n", psf);
343 if(!psf) return E_INVALIDARG;
345 *psf = NULL;
346 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
348 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
349 return hres;
351 /**************************************************************************
352 * Default ClassFactory Implementation
354 * SHCreateDefClassObject
356 * NOTES
357 * Helper function for dlls without their own classfactory.
358 * A generic classfactory is returned.
359 * When the CreateInstance of the cf is called the callback is executed.
362 typedef struct
364 IClassFactory IClassFactory_iface;
365 LONG ref;
366 CLSID *rclsid;
367 LPFNCREATEINSTANCE lpfnCI;
368 const IID * riidInst;
369 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
370 } IDefClFImpl;
372 static inline IDefClFImpl *impl_from_IClassFactory(IClassFactory *iface)
374 return CONTAINING_RECORD(iface, IDefClFImpl, IClassFactory_iface);
377 static const IClassFactoryVtbl dclfvt;
379 /**************************************************************************
380 * IDefClF_fnConstructor
383 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
385 IDefClFImpl* lpclf;
387 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
388 lpclf->ref = 1;
389 lpclf->IClassFactory_iface.lpVtbl = &dclfvt;
390 lpclf->lpfnCI = lpfnCI;
391 lpclf->pcRefDll = pcRefDll;
393 if (pcRefDll) InterlockedIncrement(pcRefDll);
394 lpclf->riidInst = riidInst;
396 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
397 return (LPCLASSFACTORY)lpclf;
399 /**************************************************************************
400 * IDefClF_fnQueryInterface
402 static HRESULT WINAPI IDefClF_fnQueryInterface(
403 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
405 IDefClFImpl *This = impl_from_IClassFactory(iface);
407 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
409 *ppvObj = NULL;
411 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
412 *ppvObj = This;
413 InterlockedIncrement(&This->ref);
414 return S_OK;
417 TRACE("-- E_NOINTERFACE\n");
418 return E_NOINTERFACE;
420 /******************************************************************************
421 * IDefClF_fnAddRef
423 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
425 IDefClFImpl *This = impl_from_IClassFactory(iface);
426 ULONG refCount = InterlockedIncrement(&This->ref);
428 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
430 return refCount;
432 /******************************************************************************
433 * IDefClF_fnRelease
435 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
437 IDefClFImpl *This = impl_from_IClassFactory(iface);
438 ULONG refCount = InterlockedDecrement(&This->ref);
440 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
442 if (!refCount)
444 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
446 TRACE("-- destroying IClassFactory(%p)\n",This);
447 HeapFree(GetProcessHeap(),0,This);
448 return 0;
450 return refCount;
452 /******************************************************************************
453 * IDefClF_fnCreateInstance
455 static HRESULT WINAPI IDefClF_fnCreateInstance(
456 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
458 IDefClFImpl *This = impl_from_IClassFactory(iface);
460 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
462 *ppvObject = NULL;
464 if ( This->riidInst==NULL ||
465 IsEqualCLSID(riid, This->riidInst) ||
466 IsEqualCLSID(riid, &IID_IUnknown) )
468 return This->lpfnCI(pUnkOuter, riid, ppvObject);
471 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
472 return E_NOINTERFACE;
474 /******************************************************************************
475 * IDefClF_fnLockServer
477 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
479 IDefClFImpl *This = impl_from_IClassFactory(iface);
480 TRACE("%p->(0x%x), not implemented\n",This, fLock);
481 return E_NOTIMPL;
484 static const IClassFactoryVtbl dclfvt =
486 IDefClF_fnQueryInterface,
487 IDefClF_fnAddRef,
488 IDefClF_fnRelease,
489 IDefClF_fnCreateInstance,
490 IDefClF_fnLockServer
493 /******************************************************************************
494 * SHCreateDefClassObject [SHELL32.70]
496 HRESULT WINAPI SHCreateDefClassObject(
497 REFIID riid,
498 LPVOID* ppv,
499 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
500 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
501 REFIID riidInst) /* [in] optional interface to the instance */
503 IClassFactory * pcf;
505 TRACE("%s %p %p %p %s\n",
506 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
508 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
509 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
510 *ppv = pcf;
511 return S_OK;
514 /*************************************************************************
515 * DragAcceptFiles [SHELL32.@]
517 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
519 LONG exstyle;
521 if( !IsWindow(hWnd) ) return;
522 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
523 if (b)
524 exstyle |= WS_EX_ACCEPTFILES;
525 else
526 exstyle &= ~WS_EX_ACCEPTFILES;
527 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
530 /*************************************************************************
531 * DragFinish [SHELL32.@]
533 void WINAPI DragFinish(HDROP h)
535 TRACE("\n");
536 GlobalFree(h);
539 /*************************************************************************
540 * DragQueryPoint [SHELL32.@]
542 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
544 DROPFILES *lpDropFileStruct;
545 BOOL bRet;
547 TRACE("\n");
549 lpDropFileStruct = GlobalLock(hDrop);
551 *p = lpDropFileStruct->pt;
552 bRet = lpDropFileStruct->fNC;
554 GlobalUnlock(hDrop);
555 return bRet;
558 /*************************************************************************
559 * DragQueryFileA [SHELL32.@]
560 * DragQueryFile [SHELL32.@]
562 UINT WINAPI DragQueryFileA(
563 HDROP hDrop,
564 UINT lFile,
565 LPSTR lpszFile,
566 UINT lLength)
568 LPSTR lpDrop;
569 UINT i = 0;
570 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
572 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
574 if(!lpDropFileStruct) goto end;
576 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
578 if(lpDropFileStruct->fWide) {
579 LPWSTR lpszFileW = NULL;
581 if(lpszFile) {
582 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
583 if(lpszFileW == NULL) {
584 goto end;
587 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
589 if(lpszFileW) {
590 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
591 HeapFree(GetProcessHeap(), 0, lpszFileW);
593 goto end;
596 while (i++ < lFile)
598 while (*lpDrop++); /* skip filename */
599 if (!*lpDrop)
601 i = (lFile == 0xFFFFFFFF) ? i : 0;
602 goto end;
606 i = strlen(lpDrop);
607 if (!lpszFile ) goto end; /* needed buffer size */
608 lstrcpynA (lpszFile, lpDrop, lLength);
609 end:
610 GlobalUnlock(hDrop);
611 return i;
614 /*************************************************************************
615 * DragQueryFileW [SHELL32.@]
617 UINT WINAPI DragQueryFileW(
618 HDROP hDrop,
619 UINT lFile,
620 LPWSTR lpszwFile,
621 UINT lLength)
623 LPWSTR lpwDrop;
624 UINT i = 0;
625 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
627 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
629 if(!lpDropFileStruct) goto end;
631 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
633 if(lpDropFileStruct->fWide == FALSE) {
634 LPSTR lpszFileA = NULL;
636 if(lpszwFile) {
637 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
638 if(lpszFileA == NULL) {
639 goto end;
642 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
644 if(lpszFileA) {
645 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
646 HeapFree(GetProcessHeap(), 0, lpszFileA);
648 goto end;
651 i = 0;
652 while (i++ < lFile)
654 while (*lpwDrop++); /* skip filename */
655 if (!*lpwDrop)
657 i = (lFile == 0xFFFFFFFF) ? i : 0;
658 goto end;
662 i = strlenW(lpwDrop);
663 if ( !lpszwFile) goto end; /* needed buffer size */
664 lstrcpynW (lpszwFile, lpwDrop, lLength);
665 end:
666 GlobalUnlock(hDrop);
667 return i;
670 /*************************************************************************
671 * SHPropStgCreate [SHELL32.685]
673 HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
674 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
675 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
677 PROPSPEC prop;
678 PROPVARIANT ret;
679 HRESULT hres;
681 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
682 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
684 hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
686 switch(dwDisposition) {
687 case CREATE_ALWAYS:
688 if(SUCCEEDED(hres)) {
689 IPropertyStorage_Release(*ppstg);
690 hres = IPropertySetStorage_Delete(psstg, fmtid);
691 if(FAILED(hres))
692 return hres;
693 hres = E_FAIL;
696 case OPEN_ALWAYS:
697 case CREATE_NEW:
698 if(FAILED(hres))
699 hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
700 grfFlags, grfMode, ppstg);
702 case OPEN_EXISTING:
703 if(FAILED(hres))
704 return hres;
706 if(puCodePage) {
707 prop.ulKind = PRSPEC_PROPID;
708 prop.u.propid = PID_CODEPAGE;
709 hres = IPropertyStorage_ReadMultiple(*ppstg, 1, &prop, &ret);
710 if(FAILED(hres) || ret.vt!=VT_I2)
711 *puCodePage = 0;
712 else
713 *puCodePage = ret.u.iVal;
717 return S_OK;
720 /*************************************************************************
721 * SHPropStgReadMultiple [SHELL32.688]
723 HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
724 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
726 STATPROPSETSTG stat;
727 HRESULT hres;
729 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
731 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
732 hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
733 if(FAILED(hres))
734 return hres;
736 if(!uCodePage) {
737 PROPSPEC prop;
738 PROPVARIANT ret;
740 prop.ulKind = PRSPEC_PROPID;
741 prop.u.propid = PID_CODEPAGE;
742 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
743 if(FAILED(hres) || ret.vt!=VT_I2)
744 return S_OK;
746 uCodePage = ret.u.iVal;
749 hres = IPropertyStorage_Stat(pps, &stat);
750 if(FAILED(hres))
751 return S_OK;
753 /* TODO: do something with codepage and stat */
754 return S_OK;
757 /*************************************************************************
758 * SHPropStgWriteMultiple [SHELL32.689]
760 HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
761 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
763 STATPROPSETSTG stat;
764 UINT codepage;
765 HRESULT hres;
767 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
769 hres = IPropertyStorage_Stat(pps, &stat);
770 if(FAILED(hres))
771 return hres;
773 if(uCodePage && *uCodePage)
774 codepage = *uCodePage;
775 else {
776 PROPSPEC prop;
777 PROPVARIANT ret;
779 prop.ulKind = PRSPEC_PROPID;
780 prop.u.propid = PID_CODEPAGE;
781 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
782 if(FAILED(hres))
783 return hres;
784 if(ret.vt!=VT_I2 || !ret.u.iVal)
785 return E_FAIL;
787 codepage = ret.u.iVal;
788 if(uCodePage)
789 *uCodePage = codepage;
792 /* TODO: do something with codepage and stat */
794 hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
795 return hres;