blob: 2fac86436f66b2795f28648b4758ea409b3d7ff5 [file] [log] [blame]
Alexandre Julliard85ed45e1998-08-22 19:03:56 +00001/*
Juergen Schmiedcd390f31998-12-14 14:51:27 +00002 * handling of SHELL32.DLL OLE-Objects
Alexandre Julliard85ed45e1998-08-22 19:03:56 +00003 *
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
6 *
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00007 * 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.
11 *
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.
16 *
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
Jonathan Ernst360a3f92006-05-18 14:49:52 +020019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000020 */
21
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +000022#include "config.h"
23
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000024#include <stdarg.h>
Alexandre Julliard85ed45e1998-08-22 19:03:56 +000025#include <stdlib.h>
26#include <string.h>
Juergen Schmied8e7cb4d1999-03-25 10:57:12 +000027
Francois Gouget486d0202004-10-07 03:06:48 +000028#define COBJMACROS
Piotr Cabanbfaae9b2010-11-16 14:58:03 +010029#define NONAMELESSUNION
Francois Gouget486d0202004-10-07 03:06:48 +000030
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000031#include "windef.h"
32#include "winbase.h"
François Gougetdea3d782001-01-02 21:00:46 +000033#include "shellapi.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000034#include "wingdi.h"
35#include "winuser.h"
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +000036#include "shlobj.h"
Juergen Schmiedba28ba11999-01-23 14:12:48 +000037#include "shlguid.h"
Alexander Morozov8b308492011-01-18 21:35:41 +030038#include "shldisp.h"
Juergen Schmied8e7cb4d1999-03-25 10:57:12 +000039#include "winreg.h"
40#include "winerror.h"
Marcus Meissner317af321999-02-17 13:51:06 +000041
Alexandre Julliard39541172001-08-16 18:49:56 +000042#include "undocshell.h"
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +000043#include "wine/unicode.h"
Juergen Schmied8e7cb4d1999-03-25 10:57:12 +000044#include "shell32_main.h"
45
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000046#include "wine/debug.h"
Juergen Schmied23b80872002-07-02 02:05:17 +000047#include "shlwapi.h"
Juergen Schmied1e5ec882002-07-24 01:56:03 +000048#include "debughlp.h"
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +000049
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000050WINE_DEFAULT_DEBUG_CHANNEL(shell);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000051
Alexandre Julliard366fcaf2008-12-03 12:09:17 +010052extern INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax); /* shlwapi.24 */
Juergen Schmied23b80872002-07-02 02:05:17 +000053
Juergen Schmied23b80872002-07-02 02:05:17 +000054/**************************************************************************
55 * Default ClassFactory types
56 */
57typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
Andrew Talbotdfe3d5b2007-02-06 22:05:10 +000058static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
Juergen Schmied23b80872002-07-02 02:05:17 +000059
Frédéric Delanoy7e309602011-08-02 22:20:32 +020060/* this table contains all CLSIDs of shell32 objects */
Alexandre Julliard7a0396a2006-06-12 13:44:21 +020061static const struct {
Juergen Schmied23b80872002-07-02 02:05:17 +000062 REFIID riid;
63 LPFNCREATEINSTANCE lpfnCI;
Martin Fuchsdd46d6d2004-03-27 01:42:22 +000064} InterfaceTable[] = {
Nikolay Sivovda32b072010-04-06 11:55:10 +040065
66 {&CLSID_AutoComplete, IAutoComplete_Constructor},
67 {&CLSID_ControlPanel, IControlPanel_Constructor},
68 {&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
69 {&CLSID_FolderShortcut, FolderShortcut_Constructor},
Andrew Talbot93f656b2008-07-06 13:00:42 +010070 {&CLSID_MyComputer, ISF_MyComputer_Constructor},
Nikolay Sivovda32b072010-04-06 11:55:10 +040071 {&CLSID_MyDocuments, MyDocuments_Constructor},
Andrew Talbot93f656b2008-07-06 13:00:42 +010072 {&CLSID_NetworkPlaces, ISF_NetworkPlaces_Constructor},
Nikolay Sivovda32b072010-04-06 11:55:10 +040073 {&CLSID_Printers, Printers_Constructor},
74 {&CLSID_QueryAssociations, QueryAssociations_Constructor},
75 {&CLSID_RecycleBin, RecycleBin_Constructor},
Andrew Talbot93f656b2008-07-06 13:00:42 +010076 {&CLSID_ShellDesktop, ISF_Desktop_Constructor},
Nikolay Sivovda32b072010-04-06 11:55:10 +040077 {&CLSID_ShellFSFolder, IFSFolder_Constructor},
Vincent Povirke69c6632009-02-18 12:32:32 -060078 {&CLSID_ShellItem, IShellItem_Constructor},
Andrew Talbot93f656b2008-07-06 13:00:42 +010079 {&CLSID_ShellLink, IShellLink_Constructor},
Andrew Talbot93f656b2008-07-06 13:00:42 +010080 {&CLSID_UnixDosFolder, UnixDosFolder_Constructor},
Nikolay Sivovda32b072010-04-06 11:55:10 +040081 {&CLSID_UnixFolder, UnixFolder_Constructor},
David Hedbergd6626962010-08-20 07:45:56 +020082 {&CLSID_ExplorerBrowser,ExplorerBrowser_Constructor},
Hans Leidekkere7e1ec62010-09-23 09:25:57 +020083 {&CLSID_KnownFolderManager, KnownFolderManager_Constructor},
Alexander Morozov8b308492011-01-18 21:35:41 +030084 {&CLSID_Shell, IShellDispatch_Constructor},
Nikolay Sivovda32b072010-04-06 11:55:10 +040085 {NULL, NULL}
Juergen Schmied23b80872002-07-02 02:05:17 +000086};
87
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +020088/*************************************************************************
89 * SHCoCreateInstance [SHELL32.102]
90 *
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.
94 *
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
97 *
98 * NOTES
99 * exported by ordinal
100 *
101 * SEE ALSO
102 * CoCreateInstace, SHLoadOLE
103 */
Vincent Béron6c644d62004-10-19 23:55:15 +0000104HRESULT WINAPI SHCoCreateInstance(
Alexandre Julliard72ecbb02004-01-06 20:42:47 +0000105 LPCWSTR aclsid,
106 const CLSID *clsid,
Juergen Schmied23b80872002-07-02 02:05:17 +0000107 LPUNKNOWN pUnkOuter,
Juergen Schmied61adb761999-07-10 11:48:15 +0000108 REFIID refiid,
109 LPVOID *ppv)
110{
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000111 DWORD hres;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000112 IID iid;
Andrew Talbot2f4bb7b2006-11-14 22:13:36 +0000113 const CLSID * myclsid = clsid;
Juergen Schmied23b80872002-07-02 02:05:17 +0000114 WCHAR sKeyName[MAX_PATH];
115 const WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
116 WCHAR sClassID[60];
117 const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
118 const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
119 WCHAR sDllPath[MAX_PATH];
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200120 HKEY hKey = 0;
Juergen Schmied23b80872002-07-02 02:05:17 +0000121 DWORD dwSize;
Juergen Schmied23b80872002-07-02 02:05:17 +0000122 IClassFactory * pcf = NULL;
Vincent Béron9a624912002-05-31 23:06:46 +0000123
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000124 if(!ppv) return E_POINTER;
125 *ppv=NULL;
126
Juergen Schmied23b80872002-07-02 02:05:17 +0000127 /* if the clsid is a string, convert it */
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000128 if (!clsid)
129 {
130 if (!aclsid) return REGDB_E_CLASSNOTREG;
Alexandre Julliard72ecbb02004-01-06 20:42:47 +0000131 SHCLSIDFromStringW(aclsid, &iid);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000132 myclsid = &iid;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000133 }
Juergen Schmied61adb761999-07-10 11:48:15 +0000134
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000135 TRACE("(%p,%s,unk:%p,%s,%p)\n",
136 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000137
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200138 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
139 {
140 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
141 IClassFactory_Release(pcf);
142 goto end;
143 }
144
Juergen Schmied23b80872002-07-02 02:05:17 +0000145 /* we look up the dll path in the registry */
Alexandre Julliard366fcaf2008-12-03 12:09:17 +0100146 SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
Juergen Schmied23b80872002-07-02 02:05:17 +0000147 lstrcpyW(sKeyName, sCLSID);
148 lstrcatW(sKeyName, sClassID);
149 lstrcatW(sKeyName, sInProcServer32);
150
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200151 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
152 return E_ACCESSDENIED;
Juergen Schmied23b80872002-07-02 02:05:17 +0000153
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200154 /* 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))
156 {
Francois Gouget93416cd2005-03-23 13:15:18 +0000157 /* load an external dll without ole32 */
Juergen Schmied23b80872002-07-02 02:05:17 +0000158 HANDLE hLibrary;
159 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
160 DllGetClassObjectFunc DllGetClassObject;
161
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200162 dwSize = sizeof(sDllPath);
163 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
164
Juergen Schmied23b80872002-07-02 02:05:17 +0000165 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;
Michael Stefaniucf6baf972008-10-08 01:32:38 +0200174 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
Hans Leidekker89e1d292006-10-07 20:18:14 +0200175 TRACE("GetClassObject failed 0x%08x\n", hres);
Juergen Schmied23b80872002-07-02 02:05:17 +0000176 goto end;
177 }
178
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200179 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
180 IClassFactory_Release(pcf);
Juergen Schmied23b80872002-07-02 02:05:17 +0000181 } else {
182
Francois Gouget93416cd2005-03-23 13:15:18 +0000183 /* load an external dll in the usual way */
Robert Shearman77b7f952004-06-18 00:23:38 +0000184 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
Juergen Schmied23b80872002-07-02 02:05:17 +0000185 }
186
Juergen Schmied23b80872002-07-02 02:05:17 +0000187end:
Alexandre Julliardd7892cc2007-10-18 15:15:40 +0200188 if (hKey) RegCloseKey(hKey);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000189 if(hres!=S_OK)
190 {
Hans Leidekker89e1d292006-10-07 20:18:14 +0200191 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000192 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
Juergen Schmiedafe53ed1999-11-23 22:31:18 +0000193 ERR("class not found in registry\n");
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000194 }
195
Juergen Schmiedafe53ed1999-11-23 22:31:18 +0000196 TRACE("-- instance: %p\n",*ppv);
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000197 return hres;
198}
199
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000200/*************************************************************************
Francois Gougetd3aa2312006-02-07 21:18:12 +0100201 * DllGetClassObject [SHELL32.@]
202 * SHDllGetClassObject [SHELL32.128]
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000203 */
Alexandre Julliardd37f0ab2005-08-08 17:35:28 +0000204HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
Juergen Schmied23b80872002-07-02 02:05:17 +0000205{
206 HRESULT hres = E_OUTOFMEMORY;
207 IClassFactory * pcf = NULL;
208 int i;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000209
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000210 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
Vincent Béron9a624912002-05-31 23:06:46 +0000211
Juergen Schmied23b80872002-07-02 02:05:17 +0000212 if (!ppv) return E_INVALIDARG;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000213 *ppv = NULL;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000214
Juergen Schmied23b80872002-07-02 02:05:17 +0000215 /* 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);
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000219 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
Juergen Schmied23b80872002-07-02 02:05:17 +0000220 }
221 }
Juergen Schmiedcd390f31998-12-14 14:51:27 +0000222
Juergen Schmied23b80872002-07-02 02:05:17 +0000223 if (!pcf) {
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000224 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
Juergen Schmied23b80872002-07-02 02:05:17 +0000225 return CLASS_E_CLASSNOTAVAILABLE;
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000226 }
Juergen Schmied23b80872002-07-02 02:05:17 +0000227
228 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
229 IClassFactory_Release(pcf);
230
Alexandre Julliarda099a551999-06-12 15:45:58 +0000231 TRACE("-- pointer to class factory: %p\n",*ppv);
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000232 return hres;
233}
234
235/*************************************************************************
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000236 * SHCLSIDFromString [SHELL32.147]
237 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200238 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
239 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
240 *
241 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
242 *
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000243 * NOTES
244 * exported by ordinal
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200245 *
246 * SEE ALSO
247 * CLSIDFromString, SHLoadOLE
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000248 */
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +0000249DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000250{
Alexandre Julliard91791032000-06-23 16:13:33 +0000251 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 );
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000256}
Alexandre Julliard72ecbb02004-01-06 20:42:47 +0000257DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000258{
259 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
Mikhail Maroukhinef930c872010-03-26 23:59:50 +0600260 return CLSIDFromString(clsid, id);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000261}
Andrew Talbotc289a332007-09-13 09:42:50 +0100262DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000263{
Alexandre Julliardd586dc92000-08-14 14:35:01 +0000264 if (SHELL_OsIsUnicode())
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000265 return SHCLSIDFromStringW (clsid, id);
266 return SHCLSIDFromStringA (clsid, id);
267}
Juergen Schmiedb18f3d61999-04-01 10:23:09 +0000268
269/*************************************************************************
Patrik Stridvall8b216b32001-06-19 18:20:47 +0000270 * SHGetMalloc [SHELL32.@]
Jon Griffithscd4234a2003-03-18 18:35:48 +0000271 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200272 * 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.
Jon Griffithscd4234a2003-03-18 18:35:48 +0000275 *
276 * PARAMS
277 * lpmal [O] Destination for IMalloc interface.
278 *
279 * RETURNS
280 * Success: S_OK. lpmal contains the shells IMalloc interface.
281 * Failure. An HRESULT error code.
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000282 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200283 * SEE ALSO
284 * CoGetMalloc, SHLoadOLE
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000285 */
Dimitrie O. Paundfa6b122003-01-03 03:07:21 +0000286HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000287{
288 TRACE("(%p)\n", lpmal);
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200289 return CoGetMalloc(MEMCTX_TASK, lpmal);
Juergen Schmied23b80872002-07-02 02:05:17 +0000290}
291
292/*************************************************************************
293 * SHAlloc [SHELL32.196]
294 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200295 * 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.
298 *
Juergen Schmied23b80872002-07-02 02:05:17 +0000299 * NOTES
300 * exported by ordinal
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200301 *
302 * SEE ALSO
303 * CoTaskMemAlloc, SHLoadOLE
Juergen Schmied23b80872002-07-02 02:05:17 +0000304 */
305LPVOID WINAPI SHAlloc(DWORD len)
306{
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200307 LPVOID ret;
Juergen Schmied23b80872002-07-02 02:05:17 +0000308
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200309 ret = CoTaskMemAlloc(len);
Hans Leidekker89e1d292006-10-07 20:18:14 +0200310 TRACE("%u bytes at %p\n",len, ret);
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200311 return ret;
Juergen Schmied23b80872002-07-02 02:05:17 +0000312}
313
314/*************************************************************************
315 * SHFree [SHELL32.195]
316 *
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200317 * 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.
320 *
Juergen Schmied23b80872002-07-02 02:05:17 +0000321 * NOTES
322 * exported by ordinal
Mikołaj Zalewski8fcc0bd2006-09-08 21:11:01 +0200323 *
324 * SEE ALSO
325 * CoTaskMemFree, SHLoadOLE
Juergen Schmied23b80872002-07-02 02:05:17 +0000326 */
327void WINAPI SHFree(LPVOID pv)
328{
Juergen Schmied23b80872002-07-02 02:05:17 +0000329 TRACE("%p\n",pv);
Mikołaj Zalewski455991a2006-09-08 21:14:52 +0200330 CoTaskMemFree(pv);
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000331}
332
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000333/*************************************************************************
Patrik Stridvall8b216b32001-06-19 18:20:47 +0000334 * SHGetDesktopFolder [SHELL32.@]
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000335 */
Ge van Geldorpc390bb22004-06-28 20:32:53 +0000336HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000337{
Nikolay Sivov0f794f92010-03-21 04:42:59 +0300338 HRESULT hres;
339
340 TRACE("(%p)\n", psf);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000341
Juergen Schmied23b80872002-07-02 02:05:17 +0000342 if(!psf) return E_INVALIDARG;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000343
Nikolay Sivov0f794f92010-03-21 04:42:59 +0300344 *psf = NULL;
345 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
346
347 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000348 return hres;
349}
Alexandre Julliard85ed45e1998-08-22 19:03:56 +0000350/**************************************************************************
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000351 * Default ClassFactory Implementation
352 *
353 * SHCreateDefClassObject
354 *
355 * NOTES
Francois Gouget93416cd2005-03-23 13:15:18 +0000356 * 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.
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000359 */
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000360
361typedef struct
362{
Michael Stefaniuc151b3512010-12-07 11:09:48 +0100363 IClassFactory IClassFactory_iface;
Mike McCormacke28c0142005-07-03 12:03:35 +0000364 LONG ref;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000365 CLSID *rclsid;
366 LPFNCREATEINSTANCE lpfnCI;
367 const IID * riidInst;
Mike McCormacke28c0142005-07-03 12:03:35 +0000368 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000369} IDefClFImpl;
370
Michael Stefaniuc151b3512010-12-07 11:09:48 +0100371static inline IDefClFImpl *impl_from_IClassFactory(IClassFactory *iface)
372{
373 return CONTAINING_RECORD(iface, IDefClFImpl, IClassFactory_iface);
374}
375
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +0000376static const IClassFactoryVtbl dclfvt;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000377
378/**************************************************************************
379 * IDefClF_fnConstructor
380 */
381
Andrew Talbotdfe3d5b2007-02-06 22:05:10 +0000382static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000383{
384 IDefClFImpl* lpclf;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000385
Mike McCormack17c31062005-03-21 11:25:13 +0000386 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000387 lpclf->ref = 1;
Michael Stefaniuc151b3512010-12-07 11:09:48 +0100388 lpclf->IClassFactory_iface.lpVtbl = &dclfvt;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000389 lpclf->lpfnCI = lpfnCI;
390 lpclf->pcRefDll = pcRefDll;
391
Juergen Schmiedd6509032000-04-28 20:19:03 +0000392 if (pcRefDll) InterlockedIncrement(pcRefDll);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000393 lpclf->riidInst = riidInst;
394
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000395 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000396 return (LPCLASSFACTORY)lpclf;
397}
398/**************************************************************************
399 * IDefClF_fnQueryInterface
400 */
401static HRESULT WINAPI IDefClF_fnQueryInterface(
402 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
403{
Michael Stefaniuc151b3512010-12-07 11:09:48 +0100404 IDefClFImpl *This = impl_from_IClassFactory(iface);
Alexandre Julliard681c75b2000-01-18 05:09:49 +0000405
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000406 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000407
408 *ppvObj = NULL;
409
Juergen Schmied23b80872002-07-02 02:05:17 +0000410 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
411 *ppvObj = This;
412 InterlockedIncrement(&This->ref);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000413 return S_OK;
414 }
Juergen Schmied23b80872002-07-02 02:05:17 +0000415
416 TRACE("-- E_NOINTERFACE\n");
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000417 return E_NOINTERFACE;
Vincent Béron9a624912002-05-31 23:06:46 +0000418}
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000419/******************************************************************************
420 * IDefClF_fnAddRef
421 */
422static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
423{
Michael Stefaniuc151b3512010-12-07 11:09:48 +0100424 IDefClFImpl *This = impl_from_IClassFactory(iface);
James Hawkinsba92d292005-01-14 16:02:20 +0000425 ULONG refCount = InterlockedIncrement(&This->ref);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000426
Hans Leidekker89e1d292006-10-07 20:18:14 +0200427 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
James Hawkinsba92d292005-01-14 16:02:20 +0000428
429 return refCount;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000430}
431/******************************************************************************
432 * IDefClF_fnRelease
433 */
434static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
435{
Michael Stefaniuc151b3512010-12-07 11:09:48 +0100436 IDefClFImpl *This = impl_from_IClassFactory(iface);
James Hawkinsba92d292005-01-14 16:02:20 +0000437 ULONG refCount = InterlockedDecrement(&This->ref);
Michael Stefaniuc151b3512010-12-07 11:09:48 +0100438
Hans Leidekker89e1d292006-10-07 20:18:14 +0200439 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000440
James Hawkinsba92d292005-01-14 16:02:20 +0000441 if (!refCount)
Vincent Béron9a624912002-05-31 23:06:46 +0000442 {
Juergen Schmiedd6509032000-04-28 20:19:03 +0000443 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000444
445 TRACE("-- destroying IClassFactory(%p)\n",This);
446 HeapFree(GetProcessHeap(),0,This);
447 return 0;
448 }
James Hawkinsba92d292005-01-14 16:02:20 +0000449 return refCount;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000450}
451/******************************************************************************
452 * IDefClF_fnCreateInstance
453 */
454static HRESULT WINAPI IDefClF_fnCreateInstance(
455 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
456{
Michael Stefaniuc151b3512010-12-07 11:09:48 +0100457 IDefClFImpl *This = impl_from_IClassFactory(iface);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000458
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000459 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000460
461 *ppvObject = NULL;
Vincent Béron9a624912002-05-31 23:06:46 +0000462
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000463 if ( This->riidInst==NULL ||
464 IsEqualCLSID(riid, This->riidInst) ||
465 IsEqualCLSID(riid, &IID_IUnknown) )
466 {
467 return This->lpfnCI(pUnkOuter, riid, ppvObject);
468 }
469
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000470 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000471 return E_NOINTERFACE;
472}
473/******************************************************************************
474 * IDefClF_fnLockServer
475 */
476static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
477{
Michael Stefaniuc151b3512010-12-07 11:09:48 +0100478 IDefClFImpl *This = impl_from_IClassFactory(iface);
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000479 TRACE("%p->(0x%x), not implemented\n",This, fLock);
480 return E_NOTIMPL;
481}
482
Dmitry Timoshkoveba47f12005-06-06 19:50:35 +0000483static const IClassFactoryVtbl dclfvt =
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000484{
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000485 IDefClF_fnQueryInterface,
486 IDefClF_fnAddRef,
487 IDefClF_fnRelease,
488 IDefClF_fnCreateInstance,
489 IDefClF_fnLockServer
490};
491
492/******************************************************************************
493 * SHCreateDefClassObject [SHELL32.70]
494 */
495HRESULT WINAPI SHCreateDefClassObject(
Vincent Béron9a624912002-05-31 23:06:46 +0000496 REFIID riid,
497 LPVOID* ppv,
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000498 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
Patrik Stridvallbc38d6b2001-07-20 18:00:00 +0000499 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000500 REFIID riidInst) /* [in] optional interface to the instance */
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000501{
Juergen Schmied23b80872002-07-02 02:05:17 +0000502 IClassFactory * pcf;
503
Juergen Schmied1e5ec882002-07-24 01:56:03 +0000504 TRACE("%s %p %p %p %s\n",
505 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000506
Juergen Schmied23b80872002-07-02 02:05:17 +0000507 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
Mike McCormackeafa6662005-08-22 09:26:53 +0000508 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
Juergen Schmied23b80872002-07-02 02:05:17 +0000509 *ppv = pcf;
510 return NOERROR;
Juergen Schmied6d28b6e1999-07-25 12:22:13 +0000511}
512
Juergen Schmiedd6509032000-04-28 20:19:03 +0000513/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000514 * DragAcceptFiles [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000515 */
516void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
517{
518 LONG exstyle;
Vincent Béron9a624912002-05-31 23:06:46 +0000519
Juergen Schmiedd6509032000-04-28 20:19:03 +0000520 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);
527}
528
529/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000530 * DragFinish [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000531 */
532void WINAPI DragFinish(HDROP h)
533{
534 TRACE("\n");
Michael Stefaniuc6c54ad32009-02-18 22:46:39 +0100535 GlobalFree(h);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000536}
537
538/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000539 * DragQueryPoint [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000540 */
541BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
542{
Alexandre Julliard60e17522000-09-25 23:56:41 +0000543 DROPFILES *lpDropFileStruct;
Juergen Schmiedd6509032000-04-28 20:19:03 +0000544 BOOL bRet;
545
546 TRACE("\n");
547
Michael Stefaniucb7de2662008-11-05 23:00:50 +0100548 lpDropFileStruct = GlobalLock(hDrop);
Alexandre Julliard60e17522000-09-25 23:56:41 +0000549
550 *p = lpDropFileStruct->pt;
551 bRet = lpDropFileStruct->fNC;
Vincent Béron9a624912002-05-31 23:06:46 +0000552
Juergen Schmiedd6509032000-04-28 20:19:03 +0000553 GlobalUnlock(hDrop);
554 return bRet;
555}
556
557/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000558 * DragQueryFileA [SHELL32.@]
Markus Amsler671738d2005-11-10 11:15:22 +0000559 * DragQueryFile [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000560 */
561UINT WINAPI DragQueryFileA(
562 HDROP hDrop,
563 UINT lFile,
564 LPSTR lpszFile,
565 UINT lLength)
566{
567 LPSTR lpDrop;
568 UINT i = 0;
Michael Stefaniucb7de2662008-11-05 23:00:50 +0100569 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
Vincent Béron9a624912002-05-31 23:06:46 +0000570
Johan Dahlin991fd852002-11-21 23:56:42 +0000571 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
Vincent Béron9a624912002-05-31 23:06:46 +0000572
Juergen Schmiedd6509032000-04-28 20:19:03 +0000573 if(!lpDropFileStruct) goto end;
574
Alexandre Julliard60e17522000-09-25 23:56:41 +0000575 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
Juergen Schmiedd6509032000-04-28 20:19:03 +0000576
Alexandre Julliardebe3c522004-12-09 14:07:59 +0000577 if(lpDropFileStruct->fWide) {
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000578 LPWSTR lpszFileW = NULL;
579
580 if(lpszFile) {
Mike McCormack17c31062005-03-21 11:25:13 +0000581 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000582 if(lpszFileW == NULL) {
583 goto end;
584 }
585 }
586 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
587
588 if(lpszFileW) {
589 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
590 HeapFree(GetProcessHeap(), 0, lpszFileW);
591 }
592 goto end;
593 }
594
Juergen Schmiedd6509032000-04-28 20:19:03 +0000595 while (i++ < lFile)
596 {
597 while (*lpDrop++); /* skip filename */
Vincent Béron9a624912002-05-31 23:06:46 +0000598 if (!*lpDrop)
Juergen Schmiedd6509032000-04-28 20:19:03 +0000599 {
Vincent Béron9a624912002-05-31 23:06:46 +0000600 i = (lFile == 0xFFFFFFFF) ? i : 0;
Juergen Schmiedd6509032000-04-28 20:19:03 +0000601 goto end;
602 }
603 }
Vincent Béron9a624912002-05-31 23:06:46 +0000604
Alexandre Julliardd586dc92000-08-14 14:35:01 +0000605 i = strlen(lpDrop);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000606 if (!lpszFile ) goto end; /* needed buffer size */
Damjan Jovanovic1d5575b2007-07-06 07:27:56 +0200607 lstrcpynA (lpszFile, lpDrop, lLength);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000608end:
609 GlobalUnlock(hDrop);
610 return i;
611}
612
613/*************************************************************************
Martin Fuchsd3b50182005-04-13 15:17:16 +0000614 * DragQueryFileW [SHELL32.@]
Juergen Schmiedd6509032000-04-28 20:19:03 +0000615 */
616UINT WINAPI DragQueryFileW(
617 HDROP hDrop,
618 UINT lFile,
619 LPWSTR lpszwFile,
620 UINT lLength)
621{
622 LPWSTR lpwDrop;
623 UINT i = 0;
Michael Stefaniucb7de2662008-11-05 23:00:50 +0100624 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
Vincent Béron9a624912002-05-31 23:06:46 +0000625
Johan Dahlin991fd852002-11-21 23:56:42 +0000626 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
Vincent Béron9a624912002-05-31 23:06:46 +0000627
Juergen Schmiedd6509032000-04-28 20:19:03 +0000628 if(!lpDropFileStruct) goto end;
629
Sander van Leeuwenb7828ac2002-06-02 21:23:45 +0000630 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000631
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000632 if(lpDropFileStruct->fWide == FALSE) {
633 LPSTR lpszFileA = NULL;
Juergen Schmied23b80872002-07-02 02:05:17 +0000634
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000635 if(lpszwFile) {
Mike McCormack17c31062005-03-21 11:25:13 +0000636 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
Sander van Leeuwenddf16e02002-06-10 02:29:09 +0000637 if(lpszFileA == NULL) {
638 goto end;
639 }
640 }
641 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
642
643 if(lpszFileA) {
644 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
645 HeapFree(GetProcessHeap(), 0, lpszFileA);
646 }
647 goto end;
648 }
649
Juergen Schmiedd6509032000-04-28 20:19:03 +0000650 i = 0;
651 while (i++ < lFile)
652 {
653 while (*lpwDrop++); /* skip filename */
Vincent Béron9a624912002-05-31 23:06:46 +0000654 if (!*lpwDrop)
Juergen Schmiedd6509032000-04-28 20:19:03 +0000655 {
Vincent Béron9a624912002-05-31 23:06:46 +0000656 i = (lFile == 0xFFFFFFFF) ? i : 0;
Juergen Schmiedd6509032000-04-28 20:19:03 +0000657 goto end;
658 }
659 }
Vincent Béron9a624912002-05-31 23:06:46 +0000660
Alexandre Julliard60e17522000-09-25 23:56:41 +0000661 i = strlenW(lpwDrop);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000662 if ( !lpszwFile) goto end; /* needed buffer size */
Damjan Jovanovic1d5575b2007-07-06 07:27:56 +0200663 lstrcpynW (lpszwFile, lpwDrop, lLength);
Juergen Schmiedd6509032000-04-28 20:19:03 +0000664end:
665 GlobalUnlock(hDrop);
666 return i;
667}
Piotr Caban14b13f72010-11-16 14:57:52 +0100668
669/*************************************************************************
670 * SHPropStgCreate [SHELL32.685]
671 */
672HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
673 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
674 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
675{
Piotr Cabanbfaae9b2010-11-16 14:58:03 +0100676 PROPSPEC prop;
677 PROPVARIANT ret;
678 HRESULT hres;
679
680 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
681 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
682
683 hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
684
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;
693 }
694
695 case OPEN_ALWAYS:
696 case CREATE_NEW:
697 if(FAILED(hres))
698 hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
699 grfFlags, grfMode, ppstg);
700
701 case OPEN_EXISTING:
702 if(FAILED(hres))
703 return hres;
704
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;
713 }
714 }
715
716 return S_OK;
Piotr Caban14b13f72010-11-16 14:57:52 +0100717}
718
719/*************************************************************************
720 * SHPropStgReadMultiple [SHELL32.688]
721 */
722HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
723 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
724{
Piotr Cabanc148c042010-11-16 14:58:13 +0100725 STATPROPSETSTG stat;
726 HRESULT hres;
727
728 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
729
730 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
731 hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
732 if(FAILED(hres))
733 return hres;
734
735 if(!uCodePage) {
736 PROPSPEC prop;
737 PROPVARIANT ret;
738
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;
744
745 uCodePage = ret.u.iVal;
746 }
747
748 hres = IPropertyStorage_Stat(pps, &stat);
749 if(FAILED(hres))
750 return S_OK;
751
752 /* TODO: do something with codepage and stat */
753 return S_OK;
Piotr Caban14b13f72010-11-16 14:57:52 +0100754}
755
756/*************************************************************************
757 * SHPropStgWriteMultiple [SHELL32.689]
758 */
759HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
760 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
761{
Piotr Cabanb4908032010-11-16 14:58:22 +0100762 STATPROPSETSTG stat;
763 UINT codepage;
764 HRESULT hres;
765
766 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
767
768 hres = IPropertyStorage_Stat(pps, &stat);
769 if(FAILED(hres))
770 return hres;
771
772 if(uCodePage && *uCodePage)
773 codepage = *uCodePage;
774 else {
775 PROPSPEC prop;
776 PROPVARIANT ret;
777
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;
785
786 codepage = ret.u.iVal;
787 if(uCodePage)
788 *uCodePage = codepage;
789 }
790
791 /* TODO: do something with codepage and stat */
792
793 hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
794 return hres;
Piotr Caban14b13f72010-11-16 14:57:52 +0100795}