msvideo.dll16: Check if any 16 bit thunks have been allocated before accessing pointer.
[wine.git] / dlls / shell32 / shellole.c
blobdd54900cec6bc49301e4da4a22104074413c1c5b
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 clsid;
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 {&CLSID_DestinationList, CustomDestinationList_Constructor},
87 {NULL, NULL}
90 /*************************************************************************
91 * SHCoCreateInstance [SHELL32.102]
93 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
94 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
95 * SHLoadOLE for details.
97 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
98 * shell32.dll the function will load the object manually without the help of ole32
100 * NOTES
101 * exported by ordinal
103 * SEE ALSO
104 * CoCreateInstance, SHLoadOLE
106 HRESULT WINAPI SHCoCreateInstance(
107 LPCWSTR aclsid,
108 const CLSID *clsid,
109 LPUNKNOWN pUnkOuter,
110 REFIID refiid,
111 LPVOID *ppv)
113 DWORD hres;
114 IID iid;
115 const CLSID * myclsid = clsid;
116 WCHAR sKeyName[MAX_PATH];
117 static const WCHAR sCLSID[] = {'C','L','S','I','D','\\','\0'};
118 WCHAR sClassID[60];
119 static const WCHAR sInProcServer32[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
120 static const WCHAR sLoadWithoutCOM[] = {'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
121 WCHAR sDllPath[MAX_PATH];
122 HKEY hKey = 0;
123 DWORD dwSize;
124 IClassFactory * pcf = NULL;
126 if(!ppv) return E_POINTER;
127 *ppv=NULL;
129 /* if the clsid is a string, convert it */
130 if (!clsid)
132 if (!aclsid) return REGDB_E_CLASSNOTREG;
133 SHCLSIDFromStringW(aclsid, &iid);
134 myclsid = &iid;
137 TRACE("(%p,%s,unk:%p,%s,%p)\n",
138 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
140 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
142 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
143 IClassFactory_Release(pcf);
144 goto end;
147 /* we look up the dll path in the registry */
148 SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
149 lstrcpyW(sKeyName, sCLSID);
150 lstrcatW(sKeyName, sClassID);
151 lstrcatW(sKeyName, sInProcServer32);
153 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
154 return E_ACCESSDENIED;
156 /* if a special registry key is set, we load a shell extension without help of OLE32 */
157 if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
159 /* load an external dll without ole32 */
160 HANDLE hLibrary;
161 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
162 DllGetClassObjectFunc DllGetClassObject;
164 dwSize = sizeof(sDllPath);
165 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
167 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
168 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
169 hres = E_ACCESSDENIED;
170 goto end;
171 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
172 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
173 FreeLibrary( hLibrary );
174 hres = E_ACCESSDENIED;
175 goto end;
176 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
177 TRACE("GetClassObject failed 0x%08x\n", hres);
178 goto end;
181 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
182 IClassFactory_Release(pcf);
183 } else {
185 /* load an external dll in the usual way */
186 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
189 end:
190 if (hKey) RegCloseKey(hKey);
191 if(hres!=S_OK)
193 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
194 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
195 ERR("class not found in registry\n");
198 TRACE("-- instance: %p\n",*ppv);
199 return hres;
202 /*************************************************************************
203 * DllGetClassObject [SHELL32.@]
204 * SHDllGetClassObject [SHELL32.128]
206 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
208 IClassFactory * pcf = NULL;
209 HRESULT hres;
210 int i;
212 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
214 if (!ppv) return E_INVALIDARG;
215 *ppv = NULL;
217 /* search our internal interface table */
218 for(i=0;InterfaceTable[i].clsid;i++) {
219 if(IsEqualIID(InterfaceTable[i].clsid, rclsid)) {
220 TRACE("index[%u]\n", i);
221 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
222 break;
226 if (!pcf) {
227 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
228 return CLASS_E_CLASSNOTAVAILABLE;
231 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
232 IClassFactory_Release(pcf);
234 TRACE("-- pointer to class factory: %p\n",*ppv);
235 return hres;
238 /*************************************************************************
239 * SHCLSIDFromString [SHELL32.147]
241 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
242 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
244 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
246 * NOTES
247 * exported by ordinal
249 * SEE ALSO
250 * CLSIDFromString, SHLoadOLE
252 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
254 WCHAR buffer[40];
255 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
256 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
257 return CO_E_CLASSSTRING;
258 return CLSIDFromString( buffer, id );
260 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
262 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
263 return CLSIDFromString(clsid, id);
265 DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
267 if (SHELL_OsIsUnicode())
268 return SHCLSIDFromStringW (clsid, id);
269 return SHCLSIDFromStringA (clsid, id);
272 /*************************************************************************
273 * SHGetMalloc [SHELL32.@]
275 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
276 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
277 * see SHLoadOLE for details.
279 * PARAMS
280 * lpmal [O] Destination for IMalloc interface.
282 * RETURNS
283 * Success: S_OK. lpmal contains the shells IMalloc interface.
284 * Failure. An HRESULT error code.
286 * SEE ALSO
287 * CoGetMalloc, SHLoadOLE
289 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
291 TRACE("(%p)\n", lpmal);
292 return CoGetMalloc(MEMCTX_TASK, lpmal);
295 /*************************************************************************
296 * SHAlloc [SHELL32.196]
298 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
299 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
300 * see SHLoadOLE for details.
302 * NOTES
303 * exported by ordinal
305 * SEE ALSO
306 * CoTaskMemAlloc, SHLoadOLE
308 LPVOID WINAPI SHAlloc(DWORD len)
310 LPVOID ret;
312 ret = CoTaskMemAlloc(len);
313 TRACE("%u bytes at %p\n",len, ret);
314 return ret;
317 /*************************************************************************
318 * SHFree [SHELL32.195]
320 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
321 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
322 * see SHLoadOLE for details.
324 * NOTES
325 * exported by ordinal
327 * SEE ALSO
328 * CoTaskMemFree, SHLoadOLE
330 void WINAPI SHFree(LPVOID pv)
332 TRACE("%p\n",pv);
333 CoTaskMemFree(pv);
336 /*************************************************************************
337 * SHGetDesktopFolder [SHELL32.@]
339 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
341 HRESULT hres;
343 TRACE("(%p)\n", psf);
345 if(!psf) return E_INVALIDARG;
347 *psf = NULL;
348 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
350 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
351 return hres;
353 /**************************************************************************
354 * Default ClassFactory Implementation
356 * SHCreateDefClassObject
358 * NOTES
359 * Helper function for dlls without their own classfactory.
360 * A generic classfactory is returned.
361 * When the CreateInstance of the cf is called the callback is executed.
364 typedef struct
366 IClassFactory IClassFactory_iface;
367 LONG ref;
368 CLSID *rclsid;
369 LPFNCREATEINSTANCE lpfnCI;
370 const IID * riidInst;
371 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
372 } IDefClFImpl;
374 static inline IDefClFImpl *impl_from_IClassFactory(IClassFactory *iface)
376 return CONTAINING_RECORD(iface, IDefClFImpl, IClassFactory_iface);
379 static const IClassFactoryVtbl dclfvt;
381 /**************************************************************************
382 * IDefClF_fnConstructor
385 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
387 IDefClFImpl* lpclf;
389 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
390 lpclf->ref = 1;
391 lpclf->IClassFactory_iface.lpVtbl = &dclfvt;
392 lpclf->lpfnCI = lpfnCI;
393 lpclf->pcRefDll = pcRefDll;
395 if (pcRefDll) InterlockedIncrement(pcRefDll);
396 lpclf->riidInst = riidInst;
398 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
399 return (LPCLASSFACTORY)lpclf;
401 /**************************************************************************
402 * IDefClF_fnQueryInterface
404 static HRESULT WINAPI IDefClF_fnQueryInterface(
405 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
407 IDefClFImpl *This = impl_from_IClassFactory(iface);
409 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
411 *ppvObj = NULL;
413 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
414 *ppvObj = This;
415 InterlockedIncrement(&This->ref);
416 return S_OK;
419 TRACE("-- E_NOINTERFACE\n");
420 return E_NOINTERFACE;
422 /******************************************************************************
423 * IDefClF_fnAddRef
425 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
427 IDefClFImpl *This = impl_from_IClassFactory(iface);
428 ULONG refCount = InterlockedIncrement(&This->ref);
430 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
432 return refCount;
434 /******************************************************************************
435 * IDefClF_fnRelease
437 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
439 IDefClFImpl *This = impl_from_IClassFactory(iface);
440 ULONG refCount = InterlockedDecrement(&This->ref);
442 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
444 if (!refCount)
446 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
448 TRACE("-- destroying IClassFactory(%p)\n",This);
449 HeapFree(GetProcessHeap(),0,This);
450 return 0;
452 return refCount;
454 /******************************************************************************
455 * IDefClF_fnCreateInstance
457 static HRESULT WINAPI IDefClF_fnCreateInstance(
458 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
460 IDefClFImpl *This = impl_from_IClassFactory(iface);
462 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
464 *ppvObject = NULL;
466 if ( This->riidInst==NULL ||
467 IsEqualCLSID(riid, This->riidInst) ||
468 IsEqualCLSID(riid, &IID_IUnknown) )
470 return This->lpfnCI(pUnkOuter, riid, ppvObject);
473 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
474 return E_NOINTERFACE;
476 /******************************************************************************
477 * IDefClF_fnLockServer
479 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
481 IDefClFImpl *This = impl_from_IClassFactory(iface);
482 TRACE("%p->(0x%x), not implemented\n",This, fLock);
483 return E_NOTIMPL;
486 static const IClassFactoryVtbl dclfvt =
488 IDefClF_fnQueryInterface,
489 IDefClF_fnAddRef,
490 IDefClF_fnRelease,
491 IDefClF_fnCreateInstance,
492 IDefClF_fnLockServer
495 /******************************************************************************
496 * SHCreateDefClassObject [SHELL32.70]
498 HRESULT WINAPI SHCreateDefClassObject(
499 REFIID riid,
500 LPVOID* ppv,
501 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
502 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
503 REFIID riidInst) /* [in] optional interface to the instance */
505 IClassFactory * pcf;
507 TRACE("%s %p %p %p %s\n",
508 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
510 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
511 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
512 *ppv = pcf;
513 return S_OK;
516 /*************************************************************************
517 * DragAcceptFiles [SHELL32.@]
519 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
521 LONG exstyle;
523 if( !IsWindow(hWnd) ) return;
524 exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
525 if (b)
526 exstyle |= WS_EX_ACCEPTFILES;
527 else
528 exstyle &= ~WS_EX_ACCEPTFILES;
529 SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
532 /*************************************************************************
533 * DragFinish [SHELL32.@]
535 void WINAPI DragFinish(HDROP h)
537 TRACE("\n");
538 GlobalFree(h);
541 /*************************************************************************
542 * DragQueryPoint [SHELL32.@]
544 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
546 DROPFILES *lpDropFileStruct;
547 BOOL bRet;
549 TRACE("\n");
551 lpDropFileStruct = GlobalLock(hDrop);
553 *p = lpDropFileStruct->pt;
554 bRet = lpDropFileStruct->fNC;
556 GlobalUnlock(hDrop);
557 return bRet;
560 /*************************************************************************
561 * DragQueryFileA [SHELL32.@]
562 * DragQueryFile [SHELL32.@]
564 UINT WINAPI DragQueryFileA(
565 HDROP hDrop,
566 UINT lFile,
567 LPSTR lpszFile,
568 UINT lLength)
570 LPSTR lpDrop;
571 UINT i = 0;
572 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
574 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
576 if(!lpDropFileStruct) goto end;
578 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
580 if(lpDropFileStruct->fWide) {
581 LPWSTR lpszFileW = NULL;
583 if(lpszFile && lFile != 0xFFFFFFFF) {
584 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
585 if(lpszFileW == NULL) {
586 goto end;
589 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
591 if(lpszFileW) {
592 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
593 HeapFree(GetProcessHeap(), 0, lpszFileW);
595 goto end;
598 while (i++ < lFile)
600 while (*lpDrop++); /* skip filename */
601 if (!*lpDrop)
603 i = (lFile == 0xFFFFFFFF) ? i : 0;
604 goto end;
608 i = strlen(lpDrop);
609 if (!lpszFile ) goto end; /* needed buffer size */
610 lstrcpynA (lpszFile, lpDrop, lLength);
611 end:
612 GlobalUnlock(hDrop);
613 return i;
616 /*************************************************************************
617 * DragQueryFileW [SHELL32.@]
619 UINT WINAPI DragQueryFileW(
620 HDROP hDrop,
621 UINT lFile,
622 LPWSTR lpszwFile,
623 UINT lLength)
625 LPWSTR lpwDrop;
626 UINT i = 0;
627 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
629 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
631 if(!lpDropFileStruct) goto end;
633 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
635 if(lpDropFileStruct->fWide == FALSE) {
636 LPSTR lpszFileA = NULL;
638 if(lpszwFile && lFile != 0xFFFFFFFF) {
639 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
640 if(lpszFileA == NULL) {
641 goto end;
644 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
646 if(lpszFileA) {
647 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
648 HeapFree(GetProcessHeap(), 0, lpszFileA);
650 goto end;
653 i = 0;
654 while (i++ < lFile)
656 while (*lpwDrop++); /* skip filename */
657 if (!*lpwDrop)
659 i = (lFile == 0xFFFFFFFF) ? i : 0;
660 goto end;
664 i = strlenW(lpwDrop);
665 if ( !lpszwFile) goto end; /* needed buffer size */
666 lstrcpynW (lpszwFile, lpwDrop, lLength);
667 end:
668 GlobalUnlock(hDrop);
669 return i;
672 /*************************************************************************
673 * SHPropStgCreate [SHELL32.685]
675 HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
676 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
677 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
679 PROPSPEC prop;
680 PROPVARIANT ret;
681 HRESULT hres;
683 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
684 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
686 hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
688 switch(dwDisposition) {
689 case CREATE_ALWAYS:
690 if(SUCCEEDED(hres)) {
691 IPropertyStorage_Release(*ppstg);
692 hres = IPropertySetStorage_Delete(psstg, fmtid);
693 if(FAILED(hres))
694 return hres;
695 hres = E_FAIL;
698 case OPEN_ALWAYS:
699 case CREATE_NEW:
700 if(FAILED(hres))
701 hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
702 grfFlags, grfMode, ppstg);
704 case OPEN_EXISTING:
705 if(FAILED(hres))
706 return hres;
708 if(puCodePage) {
709 prop.ulKind = PRSPEC_PROPID;
710 prop.u.propid = PID_CODEPAGE;
711 hres = IPropertyStorage_ReadMultiple(*ppstg, 1, &prop, &ret);
712 if(FAILED(hres) || ret.vt!=VT_I2)
713 *puCodePage = 0;
714 else
715 *puCodePage = ret.u.iVal;
719 return S_OK;
722 /*************************************************************************
723 * SHPropStgReadMultiple [SHELL32.688]
725 HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
726 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
728 STATPROPSETSTG stat;
729 HRESULT hres;
731 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
733 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
734 hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
735 if(FAILED(hres))
736 return hres;
738 if(!uCodePage) {
739 PROPSPEC prop;
740 PROPVARIANT ret;
742 prop.ulKind = PRSPEC_PROPID;
743 prop.u.propid = PID_CODEPAGE;
744 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
745 if(FAILED(hres) || ret.vt!=VT_I2)
746 return S_OK;
748 uCodePage = ret.u.iVal;
751 hres = IPropertyStorage_Stat(pps, &stat);
752 if(FAILED(hres))
753 return S_OK;
755 /* TODO: do something with codepage and stat */
756 return S_OK;
759 /*************************************************************************
760 * SHPropStgWriteMultiple [SHELL32.689]
762 HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
763 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
765 STATPROPSETSTG stat;
766 UINT codepage;
767 HRESULT hres;
769 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
771 hres = IPropertyStorage_Stat(pps, &stat);
772 if(FAILED(hres))
773 return hres;
775 if(uCodePage && *uCodePage)
776 codepage = *uCodePage;
777 else {
778 PROPSPEC prop;
779 PROPVARIANT ret;
781 prop.ulKind = PRSPEC_PROPID;
782 prop.u.propid = PID_CODEPAGE;
783 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
784 if(FAILED(hres))
785 return hres;
786 if(ret.vt!=VT_I2 || !ret.u.iVal)
787 return E_FAIL;
789 codepage = ret.u.iVal;
790 if(uCodePage)
791 *uCodePage = codepage;
794 /* TODO: do something with codepage and stat */
796 hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
797 return hres;
800 /*************************************************************************
801 * SHCreateQueryCancelAutoPlayMoniker [SHELL32.@]
803 HRESULT WINAPI SHCreateQueryCancelAutoPlayMoniker(IMoniker **moniker)
805 TRACE("%p\n", moniker);
807 if (!moniker) return E_INVALIDARG;
808 return CreateClassMoniker(&CLSID_QueryCancelAutoPlay, moniker);