[rshell]
[reactos.git] / dll / win32 / shell32 / shellole.cpp
1 /*
2 * handling of SHELL32.DLL OLE-Objects
3 *
4 * Copyright 1997 Marcus Meissner
5 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
6 *
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.
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
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "precomp.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(shell);
25
26 static const WCHAR sShell32[12] = {'S','H','E','L','L','3','2','.','D','L','L','\0'};
27
28 /**************************************************************************
29 * Default ClassFactory types
30 */
31 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
32 HRESULT IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, const IID *riidInst, IClassFactory **theFactory);
33
34 /* FIXME: this should be SHLWAPI.24 since we can't yet import by ordinal */
35
36 DWORD WINAPI __SHGUIDToStringW (REFGUID guid, LPWSTR str)
37 {
38 WCHAR sFormat[52] = {'{','%','0','8','l','x','-','%','0','4',
39 'x','-','%','0','4','x','-','%','0','2',
40 'x','%','0','2','x','-','%','0','2','x',
41 '%','0','2','x','%','0','2','x','%','0',
42 '2','x','%','0','2','x','%','0','2','x',
43 '}','\0'};
44
45 return swprintf ( str, sFormat,
46 guid.Data1, guid.Data2, guid.Data3,
47 guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
48 guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7] );
49
50 }
51
52 /*************************************************************************
53 * SHCoCreateInstance [SHELL32.102]
54 *
55 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
56 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
57 * SHLoadOLE for details.
58 *
59 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
60 * shell32.dll the function will load the object manually without the help of ole32
61 *
62 * NOTES
63 * exported by ordinal
64 *
65 * SEE ALSO
66 * CoCreateInstace, SHLoadOLE
67 */
68 HRESULT WINAPI SHCoCreateInstance(
69 LPCWSTR aclsid,
70 const CLSID *clsid,
71 LPUNKNOWN pUnkOuter,
72 REFIID refiid,
73 LPVOID *ppv)
74 {
75 DWORD hres;
76 CLSID iid;
77 const CLSID * myclsid = clsid;
78 WCHAR sKeyName[MAX_PATH];
79 const WCHAR sCLSID[7] = {'C','L','S','I','D','\\','\0'};
80 WCHAR sClassID[60];
81 const WCHAR sInProcServer32[16] ={'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
82 const WCHAR sLoadWithoutCOM[15] ={'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
83 WCHAR sDllPath[MAX_PATH];
84 HKEY hKey;
85 DWORD dwSize;
86 BOOLEAN bLoadFromShell32 = FALSE;
87 BOOLEAN bLoadWithoutCOM = FALSE;
88 CComPtr<IClassFactory> pcf;
89
90 if(!ppv) return E_POINTER;
91 *ppv=NULL;
92
93 /* if the clsid is a string, convert it */
94 if (!clsid)
95 {
96 if (!aclsid) return REGDB_E_CLASSNOTREG;
97 CLSIDFromString((LPOLESTR)aclsid, &iid);
98 myclsid = &iid;
99 }
100
101 TRACE("(%p,%s,unk:%p,%s,%p)\n",
102 aclsid, shdebugstr_guid(myclsid), pUnkOuter, shdebugstr_guid(&refiid), ppv);
103
104 /* we look up the dll path in the registry */
105 __SHGUIDToStringW(*myclsid, sClassID);
106 wcscpy(sKeyName, sCLSID);
107 wcscat(sKeyName, sClassID);
108 wcscat(sKeyName, sInProcServer32);
109
110 if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey)) {
111 dwSize = sizeof(sDllPath);
112 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
113
114 /* if a special registry key is set, we load a shell extension without help of OLE32 */
115 bLoadWithoutCOM = (ERROR_SUCCESS == SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0));
116
117 /* if the com object is inside shell32, omit use of ole32 */
118 bLoadFromShell32 = (0==lstrcmpiW( PathFindFileNameW(sDllPath), sShell32));
119
120 RegCloseKey (hKey);
121 } else {
122 /* since we can't find it in the registry we try internally */
123 bLoadFromShell32 = TRUE;
124 }
125
126 TRACE("WithoutCom=%u FromShell=%u\n", bLoadWithoutCOM, bLoadFromShell32);
127
128 /* now we create an instance */
129 if (bLoadFromShell32) {
130 if (! SUCCEEDED(DllGetClassObject(*myclsid, IID_PPV_ARG(IClassFactory, &pcf)))) {
131 ERR("LoadFromShell failed for CLSID=%s\n", shdebugstr_guid(myclsid));
132 }
133 } else if (bLoadWithoutCOM) {
134
135 /* load an external dll without ole32 */
136 HINSTANCE hLibrary;
137 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
138 DllGetClassObjectFunc DllGetClassObject;
139
140 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
141 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
142 hres = E_ACCESSDENIED;
143 goto end;
144 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
145 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
146 FreeLibrary( hLibrary );
147 hres = E_ACCESSDENIED;
148 goto end;
149 } else if (! SUCCEEDED(hres = DllGetClassObject(*myclsid, IID_IClassFactory, (LPVOID*)&pcf))) {
150 TRACE("GetClassObject failed 0x%08x\n", hres);
151 goto end;
152 }
153
154 } else {
155
156 /* load an external dll in the usual way */
157 hres = CoCreateInstance(*myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
158 goto end;
159 }
160
161 /* here we should have a ClassFactory */
162 if (!pcf) return E_ACCESSDENIED;
163
164 hres = pcf->CreateInstance(pUnkOuter, refiid, ppv);
165 end:
166 if(hres!=S_OK)
167 {
168 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
169 hres, shdebugstr_guid(myclsid), shdebugstr_guid(&refiid));
170 ERR("class not found in registry\n");
171 }
172
173 TRACE("-- instance: %p\n",*ppv);
174 return hres;
175 }
176
177 /*************************************************************************
178 * SHCLSIDFromString [SHELL32.147]
179 *
180 * Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
181 * to avoid dependency on ole32.dll (see SHLoadOLE for details).
182 *
183 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
184 *
185 * NOTES
186 * exported by ordinal
187 *
188 * SEE ALSO
189 * CLSIDFromString, SHLoadOLE
190 */
191 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
192 {
193 WCHAR buffer[40];
194 TRACE("(%p(%s) %p)\n", clsid, clsid, id);
195 if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, sizeof(buffer)/sizeof(WCHAR) ))
196 return CO_E_CLASSSTRING;
197 return CLSIDFromString( buffer, id );
198 }
199
200 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
201 {
202 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
203 return CLSIDFromString((LPWSTR)clsid, id);
204 }
205
206 EXTERN_C DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
207 {
208 if (SHELL_OsIsUnicode())
209 return SHCLSIDFromStringW ((LPCWSTR)clsid, id);
210 return SHCLSIDFromStringA ((LPCSTR)clsid, id);
211 }
212
213 /*************************************************************************
214 * SHGetMalloc [SHELL32.@]
215 *
216 * Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
217 * could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
218 * see SHLoadOLE for details.
219 *
220 * PARAMS
221 * lpmal [O] Destination for IMalloc interface.
222 *
223 * RETURNS
224 * Success: S_OK. lpmal contains the shells IMalloc interface.
225 * Failure. An HRESULT error code.
226 *
227 * SEE ALSO
228 * CoGetMalloc, SHLoadOLE
229 */
230 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
231 {
232 TRACE("(%p)\n", lpmal);
233 return CoGetMalloc(MEMCTX_TASK, lpmal);
234 }
235
236 /*************************************************************************
237 * SHAlloc [SHELL32.196]
238 *
239 * Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
240 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
241 * see SHLoadOLE for details.
242 *
243 * NOTES
244 * exported by ordinal
245 *
246 * SEE ALSO
247 * CoTaskMemAlloc, SHLoadOLE
248 */
249 LPVOID WINAPI SHAlloc(SIZE_T len)
250 {
251 LPVOID ret;
252
253 ret = CoTaskMemAlloc(len);
254 TRACE("%u bytes at %p\n",len, ret);
255 return ret;
256 }
257
258 /*************************************************************************
259 * SHFree [SHELL32.195]
260 *
261 * Equivalent to CoTaskMemFree. Under Windows 9x this function could use
262 * the shell32 built-in "mini-COM" without the need to load ole32.dll -
263 * see SHLoadOLE for details.
264 *
265 * NOTES
266 * exported by ordinal
267 *
268 * SEE ALSO
269 * CoTaskMemFree, SHLoadOLE
270 */
271 void WINAPI SHFree(LPVOID pv)
272 {
273 TRACE("%p\n",pv);
274 CoTaskMemFree(pv);
275 }
276
277 /*************************************************************************
278 * SHGetDesktopFolder [SHELL32.@]
279 */
280 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
281 {
282 HRESULT hres = S_OK;
283 TRACE("\n");
284
285 if(!psf) return E_INVALIDARG;
286 *psf = NULL;
287 hres = CDesktopFolder::_CreatorClass::CreateInstance(NULL, IID_PPV_ARG(IShellFolder, psf));
288
289 TRACE("-- %p->(%p)\n",psf, *psf);
290 return hres;
291 }
292 /**************************************************************************
293 * Default ClassFactory Implementation
294 *
295 * SHCreateDefClassObject
296 *
297 * NOTES
298 * Helper function for dlls without their own classfactory.
299 * A generic classfactory is returned.
300 * When the CreateInstance of the cf is called the callback is executed.
301 */
302
303 class IDefClFImpl :
304 public CComObjectRootEx<CComMultiThreadModelNoCS>,
305 public IClassFactory
306 {
307 private:
308 CLSID *rclsid;
309 LPFNCREATEINSTANCE lpfnCI;
310 const IID *riidInst;
311 LONG *pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
312 public:
313 IDefClFImpl();
314 HRESULT Initialize(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, const IID *riidInstx);
315
316 // IClassFactory
317 virtual HRESULT WINAPI CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject);
318 virtual HRESULT WINAPI LockServer(BOOL fLock);
319
320 BEGIN_COM_MAP(IDefClFImpl)
321 COM_INTERFACE_ENTRY_IID(IID_IClassFactory, IClassFactory)
322 END_COM_MAP()
323 };
324
325 IDefClFImpl::IDefClFImpl()
326 {
327 lpfnCI = NULL;
328 riidInst = NULL;
329 pcRefDll = NULL;
330 rclsid = NULL;
331 }
332
333 HRESULT IDefClFImpl::Initialize(LPFNCREATEINSTANCE lpfnCIx, PLONG pcRefDllx, const IID *riidInstx)
334 {
335 lpfnCI = lpfnCIx;
336 riidInst = riidInstx;
337 pcRefDll = pcRefDllx;
338
339 if (pcRefDll)
340 InterlockedIncrement(pcRefDll);
341
342 TRACE("(%p)%s\n", this, shdebugstr_guid(riidInst));
343 return S_OK;
344 }
345
346 /******************************************************************************
347 * IDefClF_fnCreateInstance
348 */
349 HRESULT WINAPI IDefClFImpl::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
350 {
351 TRACE("%p->(%p,%s,%p)\n", this, pUnkOuter, shdebugstr_guid(&riid), ppvObject);
352
353 *ppvObject = NULL;
354
355 if (riidInst == NULL || IsEqualCLSID(riid, *riidInst) || IsEqualCLSID(riid, IID_IUnknown))
356 {
357 return lpfnCI(pUnkOuter, riid, ppvObject);
358 }
359
360 ERR("unknown IID requested %s\n", shdebugstr_guid(&riid));
361 return E_NOINTERFACE;
362 }
363
364 /******************************************************************************
365 * IDefClF_fnLockServer
366 */
367 HRESULT WINAPI IDefClFImpl::LockServer(BOOL fLock)
368 {
369 TRACE("%p->(0x%x), not implemented\n", this, fLock);
370 return E_NOTIMPL;
371 }
372
373 /**************************************************************************
374 * IDefClF_fnConstructor
375 */
376
377 HRESULT IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, const IID *riidInst, IClassFactory **theFactory)
378 {
379 CComObject<IDefClFImpl> *theClassObject;
380 CComPtr<IClassFactory> result;
381 HRESULT hResult;
382
383 if (theFactory == NULL)
384 return E_POINTER;
385 *theFactory = NULL;
386 ATLTRY (theClassObject = new CComObject<IDefClFImpl>);
387 if (theClassObject == NULL)
388 return E_OUTOFMEMORY;
389 hResult = theClassObject->QueryInterface (IID_PPV_ARG(IClassFactory, &result));
390 if (FAILED (hResult))
391 {
392 delete theClassObject;
393 return hResult;
394 }
395 hResult = theClassObject->Initialize (lpfnCI, pcRefDll, riidInst);
396 if (FAILED (hResult))
397 return hResult;
398 *theFactory = result.Detach ();
399 return S_OK;
400 }
401
402 /******************************************************************************
403 * SHCreateDefClassObject [SHELL32.70]
404 */
405 HRESULT WINAPI SHCreateDefClassObject(
406 REFIID riid,
407 LPVOID* ppv,
408 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
409 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
410 REFIID riidInst) /* [in] optional interface to the instance */
411 {
412 IClassFactory *pcf;
413 HRESULT hResult;
414
415 TRACE("%s %p %p %p %s\n", shdebugstr_guid(&riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(&riidInst));
416
417 if (!IsEqualCLSID(riid, IID_IClassFactory))
418 return E_NOINTERFACE;
419 hResult = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, &riidInst, &pcf);
420 if (FAILED(hResult))
421 return hResult;
422 *ppv = pcf;
423 return S_OK;
424 }
425
426 /*************************************************************************
427 * DragAcceptFiles [SHELL32.@]
428 */
429 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
430 {
431 LONG exstyle;
432
433 if( !IsWindow(hWnd) ) return;
434 exstyle = GetWindowLongPtrA(hWnd,GWL_EXSTYLE);
435 if (b)
436 exstyle |= WS_EX_ACCEPTFILES;
437 else
438 exstyle &= ~WS_EX_ACCEPTFILES;
439 SetWindowLongPtrA(hWnd,GWL_EXSTYLE,exstyle);
440 }
441
442 /*************************************************************************
443 * DragFinish [SHELL32.@]
444 */
445 void WINAPI DragFinish(HDROP h)
446 {
447 TRACE("\n");
448 GlobalFree((HGLOBAL)h);
449 }
450
451 /*************************************************************************
452 * DragQueryPoint [SHELL32.@]
453 */
454 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
455 {
456 DROPFILES *lpDropFileStruct;
457 BOOL bRet;
458
459 TRACE("\n");
460
461 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
462
463 *p = lpDropFileStruct->pt;
464 bRet = lpDropFileStruct->fNC;
465
466 GlobalUnlock(hDrop);
467 return bRet;
468 }
469
470 /*************************************************************************
471 * DragQueryFileA [SHELL32.@]
472 * DragQueryFile [SHELL32.@]
473 */
474 UINT WINAPI DragQueryFileA(
475 HDROP hDrop,
476 UINT lFile,
477 LPSTR lpszFile,
478 UINT lLength)
479 {
480 LPSTR lpDrop;
481 UINT i = 0;
482 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
483
484 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
485
486 if(!lpDropFileStruct) goto end;
487
488 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
489
490 if(lpDropFileStruct->fWide) {
491 LPWSTR lpszFileW = NULL;
492
493 if(lpszFile) {
494 lpszFileW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
495 if(lpszFileW == NULL) {
496 goto end;
497 }
498 }
499 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
500
501 if(lpszFileW) {
502 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
503 HeapFree(GetProcessHeap(), 0, lpszFileW);
504 }
505 goto end;
506 }
507
508 while (i++ < lFile)
509 {
510 while (*lpDrop++); /* skip filename */
511 if (!*lpDrop)
512 {
513 i = (lFile == 0xFFFFFFFF) ? i : 0;
514 goto end;
515 }
516 }
517
518 i = strlen(lpDrop);
519 if (!lpszFile ) goto end; /* needed buffer size */
520 lstrcpynA (lpszFile, lpDrop, lLength);
521 end:
522 GlobalUnlock(hDrop);
523 return i;
524 }
525
526 /*************************************************************************
527 * DragQueryFileW [SHELL32.@]
528 */
529 UINT WINAPI DragQueryFileW(
530 HDROP hDrop,
531 UINT lFile,
532 LPWSTR lpszwFile,
533 UINT lLength)
534 {
535 LPWSTR lpwDrop;
536 UINT i = 0;
537 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
538
539 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
540
541 if(!lpDropFileStruct) goto end;
542
543 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
544
545 if(lpDropFileStruct->fWide == FALSE) {
546 LPSTR lpszFileA = NULL;
547
548 if(lpszwFile) {
549 lpszFileA = (LPSTR)HeapAlloc(GetProcessHeap(), 0, lLength);
550 if(lpszFileA == NULL) {
551 goto end;
552 }
553 }
554 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
555
556 if(lpszFileA) {
557 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
558 HeapFree(GetProcessHeap(), 0, lpszFileA);
559 }
560 goto end;
561 }
562
563 i = 0;
564 while (i++ < lFile)
565 {
566 while (*lpwDrop++); /* skip filename */
567 if (!*lpwDrop)
568 {
569 i = (lFile == 0xFFFFFFFF) ? i : 0;
570 goto end;
571 }
572 }
573
574 i = wcslen(lpwDrop);
575 if ( !lpszwFile) goto end; /* needed buffer size */
576 lstrcpynW (lpszwFile, lpwDrop, lLength);
577 end:
578 GlobalUnlock(hDrop);
579 return i;
580 }
581
582 /*************************************************************************
583 * SHPropStgCreate [SHELL32.685]
584 */
585 EXTERN_C HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
586 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
587 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
588 {
589 PROPSPEC prop;
590 PROPVARIANT ret;
591 HRESULT hres;
592
593 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(&fmtid), debugstr_guid(pclsid),
594 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
595
596 hres = psstg->Open(fmtid, grfMode, ppstg);
597
598 switch (dwDisposition)
599 {
600 case CREATE_ALWAYS:
601 if (SUCCEEDED(hres))
602 {
603 reinterpret_cast<IPropertyStorage*>(*ppstg)->Release();
604 hres = psstg->Delete(fmtid);
605 if(FAILED(hres))
606 return hres;
607 hres = E_FAIL;
608 }
609
610 case OPEN_ALWAYS:
611 case CREATE_NEW:
612 if (FAILED(hres))
613 hres = psstg->Create(fmtid, pclsid, grfFlags, grfMode, ppstg);
614
615 case OPEN_EXISTING:
616 if (FAILED(hres))
617 return hres;
618
619 if (puCodePage)
620 {
621 prop.ulKind = PRSPEC_PROPID;
622 prop.propid = PID_CODEPAGE;
623 hres = reinterpret_cast<IPropertyStorage*>(*ppstg)->ReadMultiple(1, &prop, &ret);
624 if (FAILED(hres) || ret.vt!=VT_I2)
625 *puCodePage = 0;
626 else
627 *puCodePage = ret.iVal;
628 }
629 }
630
631 return S_OK;
632 }
633
634 /*************************************************************************
635 * SHPropStgReadMultiple [SHELL32.688]
636 */
637 EXTERN_C HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
638 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
639 {
640 STATPROPSETSTG stat;
641 HRESULT hres;
642
643 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
644
645 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
646 hres = pps->ReadMultiple(cpspec, rgpspec, rgvar);
647 if (FAILED(hres))
648 return hres;
649
650 if (!uCodePage)
651 {
652 PROPSPEC prop;
653 PROPVARIANT ret;
654
655 prop.ulKind = PRSPEC_PROPID;
656 prop.propid = PID_CODEPAGE;
657 hres = pps->ReadMultiple(1, &prop, &ret);
658 if(FAILED(hres) || ret.vt!=VT_I2)
659 return S_OK;
660
661 uCodePage = ret.iVal;
662 }
663
664 hres = pps->Stat(&stat);
665 if (FAILED(hres))
666 return S_OK;
667
668 /* TODO: do something with codepage and stat */
669 return S_OK;
670 }
671
672 /*************************************************************************
673 * SHPropStgWriteMultiple [SHELL32.689]
674 */
675 EXTERN_C HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
676 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
677 {
678 STATPROPSETSTG stat;
679 UINT codepage;
680 HRESULT hres;
681
682 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
683
684 hres = pps->Stat(&stat);
685 if (FAILED(hres))
686 return hres;
687
688 if (uCodePage && *uCodePage)
689 codepage = *uCodePage;
690 else
691 {
692 PROPSPEC prop;
693 PROPVARIANT ret;
694
695 prop.ulKind = PRSPEC_PROPID;
696 prop.propid = PID_CODEPAGE;
697 hres = pps->ReadMultiple(1, &prop, &ret);
698 if (FAILED(hres))
699 return hres;
700 if (ret.vt!=VT_I2 || !ret.iVal)
701 return E_FAIL;
702
703 codepage = ret.iVal;
704 if (uCodePage)
705 *uCodePage = codepage;
706 }
707
708 /* TODO: do something with codepage and stat */
709
710 hres = pps->WriteMultiple(cpspec, rgpspec, rgvar, propidNameFirst);
711 return hres;
712 }