[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 IUnknown * 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_PPV_ARG(IClassFactory, &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(IUnknown * 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(IUnknown * 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 return ShellObjectCreatorInit<IDefClFImpl>(lpfnCI, pcRefDll, riidInst, IID_IClassFactory, theFactory);
380 }
381
382 /******************************************************************************
383 * SHCreateDefClassObject [SHELL32.70]
384 */
385 HRESULT WINAPI SHCreateDefClassObject(
386 REFIID riid,
387 LPVOID* ppv,
388 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
389 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
390 REFIID riidInst) /* [in] optional interface to the instance */
391 {
392 IClassFactory *pcf;
393 HRESULT hResult;
394
395 TRACE("%s %p %p %p %s\n", shdebugstr_guid(&riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(&riidInst));
396
397 if (!IsEqualCLSID(riid, IID_IClassFactory))
398 return E_NOINTERFACE;
399 hResult = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, &riidInst, &pcf);
400 if (FAILED(hResult))
401 return hResult;
402 *ppv = pcf;
403 return S_OK;
404 }
405
406 /*************************************************************************
407 * DragAcceptFiles [SHELL32.@]
408 */
409 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
410 {
411 LONG exstyle;
412
413 if( !IsWindow(hWnd) ) return;
414 exstyle = GetWindowLongPtrA(hWnd,GWL_EXSTYLE);
415 if (b)
416 exstyle |= WS_EX_ACCEPTFILES;
417 else
418 exstyle &= ~WS_EX_ACCEPTFILES;
419 SetWindowLongPtrA(hWnd,GWL_EXSTYLE,exstyle);
420 }
421
422 /*************************************************************************
423 * DragFinish [SHELL32.@]
424 */
425 void WINAPI DragFinish(HDROP h)
426 {
427 TRACE("\n");
428 GlobalFree((HGLOBAL)h);
429 }
430
431 /*************************************************************************
432 * DragQueryPoint [SHELL32.@]
433 */
434 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
435 {
436 DROPFILES *lpDropFileStruct;
437 BOOL bRet;
438
439 TRACE("\n");
440
441 lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
442
443 *p = lpDropFileStruct->pt;
444 bRet = lpDropFileStruct->fNC;
445
446 GlobalUnlock(hDrop);
447 return bRet;
448 }
449
450 /*************************************************************************
451 * DragQueryFileA [SHELL32.@]
452 * DragQueryFile [SHELL32.@]
453 */
454 UINT WINAPI DragQueryFileA(
455 HDROP hDrop,
456 UINT lFile,
457 LPSTR lpszFile,
458 UINT lLength)
459 {
460 LPSTR lpDrop;
461 UINT i = 0;
462 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
463
464 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
465
466 if(!lpDropFileStruct) goto end;
467
468 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
469
470 if(lpDropFileStruct->fWide) {
471 LPWSTR lpszFileW = NULL;
472
473 if(lpszFile) {
474 lpszFileW = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
475 if(lpszFileW == NULL) {
476 goto end;
477 }
478 }
479 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
480
481 if(lpszFileW) {
482 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
483 HeapFree(GetProcessHeap(), 0, lpszFileW);
484 }
485 goto end;
486 }
487
488 while (i++ < lFile)
489 {
490 while (*lpDrop++); /* skip filename */
491 if (!*lpDrop)
492 {
493 i = (lFile == 0xFFFFFFFF) ? i : 0;
494 goto end;
495 }
496 }
497
498 i = strlen(lpDrop);
499 if (!lpszFile ) goto end; /* needed buffer size */
500 lstrcpynA (lpszFile, lpDrop, lLength);
501 end:
502 GlobalUnlock(hDrop);
503 return i;
504 }
505
506 /*************************************************************************
507 * DragQueryFileW [SHELL32.@]
508 */
509 UINT WINAPI DragQueryFileW(
510 HDROP hDrop,
511 UINT lFile,
512 LPWSTR lpszwFile,
513 UINT lLength)
514 {
515 LPWSTR lpwDrop;
516 UINT i = 0;
517 DROPFILES *lpDropFileStruct = (DROPFILES *) GlobalLock(hDrop);
518
519 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
520
521 if(!lpDropFileStruct) goto end;
522
523 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
524
525 if(lpDropFileStruct->fWide == FALSE) {
526 LPSTR lpszFileA = NULL;
527
528 if(lpszwFile) {
529 lpszFileA = (LPSTR)HeapAlloc(GetProcessHeap(), 0, lLength);
530 if(lpszFileA == NULL) {
531 goto end;
532 }
533 }
534 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
535
536 if(lpszFileA) {
537 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
538 HeapFree(GetProcessHeap(), 0, lpszFileA);
539 }
540 goto end;
541 }
542
543 i = 0;
544 while (i++ < lFile)
545 {
546 while (*lpwDrop++); /* skip filename */
547 if (!*lpwDrop)
548 {
549 i = (lFile == 0xFFFFFFFF) ? i : 0;
550 goto end;
551 }
552 }
553
554 i = wcslen(lpwDrop);
555 if ( !lpszwFile) goto end; /* needed buffer size */
556 lstrcpynW (lpszwFile, lpwDrop, lLength);
557 end:
558 GlobalUnlock(hDrop);
559 return i;
560 }
561
562 /*************************************************************************
563 * SHPropStgCreate [SHELL32.685]
564 */
565 EXTERN_C HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
566 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
567 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
568 {
569 PROPSPEC prop;
570 PROPVARIANT ret;
571 HRESULT hres;
572
573 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(&fmtid), debugstr_guid(pclsid),
574 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
575
576 hres = psstg->Open(fmtid, grfMode, ppstg);
577
578 switch (dwDisposition)
579 {
580 case CREATE_ALWAYS:
581 if (SUCCEEDED(hres))
582 {
583 (*ppstg)->Release();
584 hres = psstg->Delete(fmtid);
585 if(FAILED(hres))
586 return hres;
587 hres = E_FAIL;
588 }
589
590 case OPEN_ALWAYS:
591 case CREATE_NEW:
592 if (FAILED(hres))
593 hres = psstg->Create(fmtid, pclsid, grfFlags, grfMode, ppstg);
594
595 case OPEN_EXISTING:
596 if (FAILED(hres))
597 return hres;
598
599 if (puCodePage)
600 {
601 prop.ulKind = PRSPEC_PROPID;
602 prop.propid = PID_CODEPAGE;
603 hres = (*ppstg)->ReadMultiple(1, &prop, &ret);
604 if (FAILED(hres) || ret.vt!=VT_I2)
605 *puCodePage = 0;
606 else
607 *puCodePage = ret.iVal;
608 }
609 }
610
611 return S_OK;
612 }
613
614 /*************************************************************************
615 * SHPropStgReadMultiple [SHELL32.688]
616 */
617 EXTERN_C HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
618 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
619 {
620 STATPROPSETSTG stat;
621 HRESULT hres;
622
623 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
624
625 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
626 hres = pps->ReadMultiple(cpspec, rgpspec, rgvar);
627 if (FAILED(hres))
628 return hres;
629
630 if (!uCodePage)
631 {
632 PROPSPEC prop;
633 PROPVARIANT ret;
634
635 prop.ulKind = PRSPEC_PROPID;
636 prop.propid = PID_CODEPAGE;
637 hres = pps->ReadMultiple(1, &prop, &ret);
638 if(FAILED(hres) || ret.vt!=VT_I2)
639 return S_OK;
640
641 uCodePage = ret.iVal;
642 }
643
644 hres = pps->Stat(&stat);
645 if (FAILED(hres))
646 return S_OK;
647
648 /* TODO: do something with codepage and stat */
649 return S_OK;
650 }
651
652 /*************************************************************************
653 * SHPropStgWriteMultiple [SHELL32.689]
654 */
655 EXTERN_C HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
656 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
657 {
658 STATPROPSETSTG stat;
659 UINT codepage;
660 HRESULT hres;
661
662 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
663
664 hres = pps->Stat(&stat);
665 if (FAILED(hres))
666 return hres;
667
668 if (uCodePage && *uCodePage)
669 codepage = *uCodePage;
670 else
671 {
672 PROPSPEC prop;
673 PROPVARIANT ret;
674
675 prop.ulKind = PRSPEC_PROPID;
676 prop.propid = PID_CODEPAGE;
677 hres = pps->ReadMultiple(1, &prop, &ret);
678 if (FAILED(hres))
679 return hres;
680 if (ret.vt!=VT_I2 || !ret.iVal)
681 return E_FAIL;
682
683 codepage = ret.iVal;
684 if (uCodePage)
685 *uCodePage = codepage;
686 }
687
688 /* TODO: do something with codepage and stat */
689
690 hres = pps->WriteMultiple(cpspec, rgpspec, rgvar, propidNameFirst);
691 return hres;
692 }
693
694 /*************************************************************************
695 * SHCreateQueryCancelAutoPlayMoniker [SHELL32.@]
696 */
697 HRESULT WINAPI SHCreateQueryCancelAutoPlayMoniker(IMoniker **moniker)
698 {
699 TRACE("%p\n", moniker);
700
701 if (!moniker) return E_INVALIDARG;
702 return CreateClassMoniker(CLSID_QueryCancelAutoPlay, moniker);
703 }