Revert r66580 and r66579.
[reactos.git] / reactos / dll / win32 / shell32 / wine / shellole.c
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 <wine/config.h>
23
24 #include <stdarg.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #define WIN32_NO_STATUS
29 #define _INC_WINDOWS
30 #define COBJMACROS
31 #define NONAMELESSUNION
32
33 #include <windef.h>
34 #include <winbase.h>
35 #include <shellapi.h>
36 #include <shlobj.h>
37 #include <shlwapi.h>
38 #include <debughlp.h>
39
40 #include <wine/debug.h>
41 #include <wine/unicode.h>
42
43 #include "shell32_main.h"
44
45 WINE_DEFAULT_DEBUG_CHANNEL(shell);
46
47 extern INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax); /* shlwapi.24 */
48
49 /**************************************************************************
50 * Default ClassFactory types
51 */
52 typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
53
54 #ifndef __REACTOS__
55
56 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
57
58 /* this table contains all CLSIDs of shell32 objects */
59 static const struct {
60 REFIID riid;
61 LPFNCREATEINSTANCE lpfnCI;
62 } InterfaceTable[] = {
63
64 {&CLSID_ApplicationAssociationRegistration, ApplicationAssociationRegistration_Constructor},
65 {&CLSID_AutoComplete, IAutoComplete_Constructor},
66 {&CLSID_ControlPanel, IControlPanel_Constructor},
67 {&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
68 {&CLSID_FolderShortcut, FolderShortcut_Constructor},
69 {&CLSID_MyComputer, ISF_MyComputer_Constructor},
70 {&CLSID_MyDocuments, MyDocuments_Constructor},
71 {&CLSID_NetworkPlaces, ISF_NetworkPlaces_Constructor},
72 {&CLSID_Printers, Printers_Constructor},
73 {&CLSID_QueryAssociations, QueryAssociations_Constructor},
74 {&CLSID_RecycleBin, RecycleBin_Constructor},
75 {&CLSID_ShellDesktop, ISF_Desktop_Constructor},
76 {&CLSID_ShellFSFolder, IFSFolder_Constructor},
77 {&CLSID_ShellItem, IShellItem_Constructor},
78 {&CLSID_ShellLink, IShellLink_Constructor},
79 {&CLSID_UnixDosFolder, UnixDosFolder_Constructor},
80 {&CLSID_UnixFolder, UnixFolder_Constructor},
81 {&CLSID_ExplorerBrowser,ExplorerBrowser_Constructor},
82 {&CLSID_KnownFolderManager, KnownFolderManager_Constructor},
83 {&CLSID_Shell, IShellDispatch_Constructor},
84 {NULL, NULL}
85 };
86
87 #endif /* !__REACTOS__ */
88
89 /*************************************************************************
90 * SHCoCreateInstance [SHELL32.102]
91 *
92 * Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
93 * use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
94 * SHLoadOLE for details.
95 *
96 * Under wine if a "LoadWithoutCOM" value is present or the object resides in
97 * shell32.dll the function will load the object manually without the help of ole32
98 *
99 * NOTES
100 * exported by ordinal
101 *
102 * SEE ALSO
103 * CoCreateInstance, SHLoadOLE
104 */
105 HRESULT WINAPI SHCoCreateInstance(
106 LPCWSTR aclsid,
107 const CLSID *clsid,
108 LPUNKNOWN pUnkOuter,
109 REFIID refiid,
110 LPVOID *ppv)
111 {
112 DWORD hres;
113 CLSID iid;
114 const CLSID * myclsid = clsid;
115 WCHAR sKeyName[MAX_PATH];
116 static const WCHAR sCLSID[] = {'C','L','S','I','D','\\','\0'};
117 WCHAR sClassID[60];
118 static const WCHAR sInProcServer32[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
119 static const WCHAR sLoadWithoutCOM[] = {'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
120 WCHAR sDllPath[MAX_PATH];
121 HKEY hKey = 0;
122 DWORD dwSize;
123 IClassFactory * pcf = NULL;
124
125 if(!ppv) return E_POINTER;
126 *ppv=NULL;
127
128 /* if the clsid is a string, convert it */
129 if (!clsid)
130 {
131 if (!aclsid) return REGDB_E_CLASSNOTREG;
132 SHCLSIDFromStringW(aclsid, &iid);
133 myclsid = &iid;
134 }
135
136 TRACE("(%p,%s,unk:%p,%s,%p)\n",
137 aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
138
139 if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
140 {
141 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
142 IClassFactory_Release(pcf);
143 goto end;
144 }
145
146 /* we look up the dll path in the registry */
147 SHStringFromGUIDW(myclsid, sClassID, sizeof(sClassID)/sizeof(WCHAR));
148 lstrcpyW(sKeyName, sCLSID);
149 lstrcatW(sKeyName, sClassID);
150 lstrcatW(sKeyName, sInProcServer32);
151
152 if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
153 return E_ACCESSDENIED;
154
155 /* if a special registry key is set, we load a shell extension without help of OLE32 */
156 if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
157 {
158 /* load an external dll without ole32 */
159 HANDLE hLibrary;
160 typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
161 DllGetClassObjectFunc DllGetClassObject;
162
163 dwSize = sizeof(sDllPath);
164 SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
165
166 if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
167 ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
168 hres = E_ACCESSDENIED;
169 goto end;
170 } else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
171 ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
172 FreeLibrary( hLibrary );
173 hres = E_ACCESSDENIED;
174 goto end;
175 } else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
176 TRACE("GetClassObject failed 0x%08x\n", hres);
177 goto end;
178 }
179
180 hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
181 IClassFactory_Release(pcf);
182 } else {
183
184 /* load an external dll in the usual way */
185 hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
186 }
187
188 end:
189 if (hKey) RegCloseKey(hKey);
190 if(hres!=S_OK)
191 {
192 ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
193 hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
194 ERR("class not found in registry\n");
195 }
196
197 TRACE("-- instance: %p\n",*ppv);
198 return hres;
199 }
200
201 #ifndef __REACTOS__
202 /*************************************************************************
203 * DllGetClassObject [SHELL32.@]
204 * SHDllGetClassObject [SHELL32.128]
205 */
206 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
207 {
208 HRESULT hres = E_OUTOFMEMORY;
209 IClassFactory * pcf = NULL;
210 int i;
211
212 TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
213
214 if (!ppv) return E_INVALIDARG;
215 *ppv = NULL;
216
217 /* search our internal interface table */
218 for(i=0;InterfaceTable[i].riid;i++) {
219 if(IsEqualIID(InterfaceTable[i].riid, rclsid)) {
220 TRACE("index[%u]\n", i);
221 pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
222 }
223 }
224
225 if (!pcf) {
226 FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
227 return CLASS_E_CLASSNOTAVAILABLE;
228 }
229
230 hres = IClassFactory_QueryInterface(pcf, iid, ppv);
231 IClassFactory_Release(pcf);
232
233 TRACE("-- pointer to class factory: %p\n",*ppv);
234 return hres;
235 }
236 #endif
237
238 /*************************************************************************
239 * SHCLSIDFromString [SHELL32.147]
240 *
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).
243 *
244 * Under Windows NT/2000/XP this is equivalent to CLSIDFromString
245 *
246 * NOTES
247 * exported by ordinal
248 *
249 * SEE ALSO
250 * CLSIDFromString, SHLoadOLE
251 */
252 DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
253 {
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 );
259 }
260 DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
261 {
262 TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
263 return CLSIDFromString(clsid, id);
264 }
265 DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
266 {
267 if (SHELL_OsIsUnicode())
268 return SHCLSIDFromStringW (clsid, id);
269 return SHCLSIDFromStringA (clsid, id);
270 }
271
272 /*************************************************************************
273 * SHGetMalloc [SHELL32.@]
274 *
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.
278 *
279 * PARAMS
280 * lpmal [O] Destination for IMalloc interface.
281 *
282 * RETURNS
283 * Success: S_OK. lpmal contains the shells IMalloc interface.
284 * Failure. An HRESULT error code.
285 *
286 * SEE ALSO
287 * CoGetMalloc, SHLoadOLE
288 */
289 HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
290 {
291 TRACE("(%p)\n", lpmal);
292 return CoGetMalloc(MEMCTX_TASK, lpmal);
293 }
294
295 /*************************************************************************
296 * SHAlloc [SHELL32.196]
297 *
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.
301 *
302 * NOTES
303 * exported by ordinal
304 *
305 * SEE ALSO
306 * CoTaskMemAlloc, SHLoadOLE
307 */
308 LPVOID WINAPI SHAlloc(SIZE_T len)
309 {
310 LPVOID ret;
311
312 ret = CoTaskMemAlloc(len);
313 TRACE("%u bytes at %p\n",len, ret);
314 return ret;
315 }
316
317 /*************************************************************************
318 * SHFree [SHELL32.195]
319 *
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.
323 *
324 * NOTES
325 * exported by ordinal
326 *
327 * SEE ALSO
328 * CoTaskMemFree, SHLoadOLE
329 */
330 void WINAPI SHFree(LPVOID pv)
331 {
332 TRACE("%p\n",pv);
333 CoTaskMemFree(pv);
334 }
335
336 #ifndef __REACTOS__
337 /*************************************************************************
338 * SHGetDesktopFolder [SHELL32.@]
339 */
340 HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
341 {
342 HRESULT hres;
343
344 TRACE("(%p)\n", psf);
345
346 if(!psf) return E_INVALIDARG;
347
348 *psf = NULL;
349 hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
350
351 TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
352 return hres;
353 }
354 #endif
355
356 /**************************************************************************
357 * Default ClassFactory Implementation
358 *
359 * SHCreateDefClassObject
360 *
361 * NOTES
362 * Helper function for dlls without their own classfactory.
363 * A generic classfactory is returned.
364 * When the CreateInstance of the cf is called the callback is executed.
365 */
366
367 typedef struct
368 {
369 IClassFactory IClassFactory_iface;
370 LONG ref;
371 CLSID *rclsid;
372 LPFNCREATEINSTANCE lpfnCI;
373 const IID * riidInst;
374 LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
375 } IDefClFImpl;
376
377 static inline IDefClFImpl *impl_from_IClassFactory(IClassFactory *iface)
378 {
379 return CONTAINING_RECORD(iface, IDefClFImpl, IClassFactory_iface);
380 }
381
382 #ifndef __REACTOS__
383
384 static const IClassFactoryVtbl dclfvt;
385
386 /**************************************************************************
387 * IDefClF_fnConstructor
388 */
389
390 static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
391 {
392 IDefClFImpl* lpclf;
393
394 lpclf = HeapAlloc(GetProcessHeap(),0,sizeof(IDefClFImpl));
395 lpclf->ref = 1;
396 lpclf->IClassFactory_iface.lpVtbl = &dclfvt;
397 lpclf->lpfnCI = lpfnCI;
398 lpclf->pcRefDll = pcRefDll;
399
400 if (pcRefDll) InterlockedIncrement(pcRefDll);
401 lpclf->riidInst = riidInst;
402
403 TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
404 return (LPCLASSFACTORY)lpclf;
405 }
406 /**************************************************************************
407 * IDefClF_fnQueryInterface
408 */
409 static HRESULT WINAPI IDefClF_fnQueryInterface(
410 LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
411 {
412 IDefClFImpl *This = impl_from_IClassFactory(iface);
413
414 TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
415
416 *ppvObj = NULL;
417
418 if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
419 *ppvObj = This;
420 InterlockedIncrement(&This->ref);
421 return S_OK;
422 }
423
424 TRACE("-- E_NOINTERFACE\n");
425 return E_NOINTERFACE;
426 }
427 /******************************************************************************
428 * IDefClF_fnAddRef
429 */
430 static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
431 {
432 IDefClFImpl *This = impl_from_IClassFactory(iface);
433 ULONG refCount = InterlockedIncrement(&This->ref);
434
435 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
436
437 return refCount;
438 }
439 /******************************************************************************
440 * IDefClF_fnRelease
441 */
442 static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
443 {
444 IDefClFImpl *This = impl_from_IClassFactory(iface);
445 ULONG refCount = InterlockedDecrement(&This->ref);
446
447 TRACE("(%p)->(count=%u)\n", This, refCount + 1);
448
449 if (!refCount)
450 {
451 if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
452
453 TRACE("-- destroying IClassFactory(%p)\n",This);
454 HeapFree(GetProcessHeap(),0,This);
455 return 0;
456 }
457 return refCount;
458 }
459 /******************************************************************************
460 * IDefClF_fnCreateInstance
461 */
462 static HRESULT WINAPI IDefClF_fnCreateInstance(
463 LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
464 {
465 IDefClFImpl *This = impl_from_IClassFactory(iface);
466
467 TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
468
469 *ppvObject = NULL;
470
471 if ( This->riidInst==NULL ||
472 IsEqualCLSID(riid, This->riidInst) ||
473 IsEqualCLSID(riid, &IID_IUnknown) )
474 {
475 return This->lpfnCI(pUnkOuter, riid, ppvObject);
476 }
477
478 ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
479 return E_NOINTERFACE;
480 }
481 /******************************************************************************
482 * IDefClF_fnLockServer
483 */
484 static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
485 {
486 IDefClFImpl *This = impl_from_IClassFactory(iface);
487 TRACE("%p->(0x%x), not implemented\n",This, fLock);
488 return E_NOTIMPL;
489 }
490
491 static const IClassFactoryVtbl dclfvt =
492 {
493 IDefClF_fnQueryInterface,
494 IDefClF_fnAddRef,
495 IDefClF_fnRelease,
496 IDefClF_fnCreateInstance,
497 IDefClF_fnLockServer
498 };
499
500 /******************************************************************************
501 * SHCreateDefClassObject [SHELL32.70]
502 */
503 HRESULT WINAPI SHCreateDefClassObject(
504 REFIID riid,
505 LPVOID* ppv,
506 LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
507 LPDWORD pcRefDll, /* [in/out] ref count of the dll */
508 REFIID riidInst) /* [in] optional interface to the instance */
509 {
510 IClassFactory * pcf;
511
512 TRACE("%s %p %p %p %s\n",
513 shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
514
515 if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
516 if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
517 *ppv = pcf;
518 return S_OK;
519 }
520
521 #endif /* !__REACTOS__ */
522
523 /*************************************************************************
524 * DragAcceptFiles [SHELL32.@]
525 */
526 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
527 {
528 LONG exstyle;
529
530 if( !IsWindow(hWnd) ) return;
531 exstyle = GetWindowLongPtrA(hWnd,GWL_EXSTYLE);
532 if (b)
533 exstyle |= WS_EX_ACCEPTFILES;
534 else
535 exstyle &= ~WS_EX_ACCEPTFILES;
536 SetWindowLongPtrA(hWnd,GWL_EXSTYLE,exstyle);
537 }
538
539 /*************************************************************************
540 * DragFinish [SHELL32.@]
541 */
542 void WINAPI DragFinish(HDROP h)
543 {
544 TRACE("\n");
545 GlobalFree(h);
546 }
547
548 /*************************************************************************
549 * DragQueryPoint [SHELL32.@]
550 */
551 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
552 {
553 DROPFILES *lpDropFileStruct;
554 BOOL bRet;
555
556 TRACE("\n");
557
558 lpDropFileStruct = GlobalLock(hDrop);
559
560 *p = lpDropFileStruct->pt;
561 bRet = lpDropFileStruct->fNC;
562
563 GlobalUnlock(hDrop);
564 return bRet;
565 }
566
567 /*************************************************************************
568 * DragQueryFileA [SHELL32.@]
569 * DragQueryFile [SHELL32.@]
570 */
571 UINT WINAPI DragQueryFileA(
572 HDROP hDrop,
573 UINT lFile,
574 LPSTR lpszFile,
575 UINT lLength)
576 {
577 LPSTR lpDrop;
578 UINT i = 0;
579 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
580
581 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
582
583 if(!lpDropFileStruct) goto end;
584
585 lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
586
587 if(lpDropFileStruct->fWide) {
588 LPWSTR lpszFileW = NULL;
589
590 if(lpszFile) {
591 lpszFileW = HeapAlloc(GetProcessHeap(), 0, lLength*sizeof(WCHAR));
592 if(lpszFileW == NULL) {
593 goto end;
594 }
595 }
596 i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
597
598 if(lpszFileW) {
599 WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
600 HeapFree(GetProcessHeap(), 0, lpszFileW);
601 }
602 goto end;
603 }
604
605 while (i++ < lFile)
606 {
607 while (*lpDrop++); /* skip filename */
608 if (!*lpDrop)
609 {
610 i = (lFile == 0xFFFFFFFF) ? i : 0;
611 goto end;
612 }
613 }
614
615 i = strlen(lpDrop);
616 if (!lpszFile ) goto end; /* needed buffer size */
617 lstrcpynA (lpszFile, lpDrop, lLength);
618 end:
619 GlobalUnlock(hDrop);
620 return i;
621 }
622
623 /*************************************************************************
624 * DragQueryFileW [SHELL32.@]
625 */
626 UINT WINAPI DragQueryFileW(
627 HDROP hDrop,
628 UINT lFile,
629 LPWSTR lpszwFile,
630 UINT lLength)
631 {
632 LPWSTR lpwDrop;
633 UINT i = 0;
634 DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
635
636 TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
637
638 if(!lpDropFileStruct) goto end;
639
640 lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
641
642 if(lpDropFileStruct->fWide == FALSE) {
643 LPSTR lpszFileA = NULL;
644
645 if(lpszwFile) {
646 lpszFileA = HeapAlloc(GetProcessHeap(), 0, lLength);
647 if(lpszFileA == NULL) {
648 goto end;
649 }
650 }
651 i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
652
653 if(lpszFileA) {
654 MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
655 HeapFree(GetProcessHeap(), 0, lpszFileA);
656 }
657 goto end;
658 }
659
660 i = 0;
661 while (i++ < lFile)
662 {
663 while (*lpwDrop++); /* skip filename */
664 if (!*lpwDrop)
665 {
666 i = (lFile == 0xFFFFFFFF) ? i : 0;
667 goto end;
668 }
669 }
670
671 i = strlenW(lpwDrop);
672 if ( !lpszwFile) goto end; /* needed buffer size */
673 lstrcpynW (lpszwFile, lpwDrop, lLength);
674 end:
675 GlobalUnlock(hDrop);
676 return i;
677 }
678
679 /*************************************************************************
680 * SHPropStgCreate [SHELL32.685]
681 */
682 HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
683 const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
684 DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
685 {
686 PROPSPEC prop;
687 PROPVARIANT ret;
688 HRESULT hres;
689
690 TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
691 grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
692
693 hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
694
695 switch(dwDisposition) {
696 case CREATE_ALWAYS:
697 if(SUCCEEDED(hres)) {
698 IPropertyStorage_Release(*ppstg);
699 hres = IPropertySetStorage_Delete(psstg, fmtid);
700 if(FAILED(hres))
701 return hres;
702 hres = E_FAIL;
703 }
704
705 case OPEN_ALWAYS:
706 case CREATE_NEW:
707 if(FAILED(hres))
708 hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
709 grfFlags, grfMode, ppstg);
710
711 case OPEN_EXISTING:
712 if(FAILED(hres))
713 return hres;
714
715 if(puCodePage) {
716 prop.ulKind = PRSPEC_PROPID;
717 prop.u.propid = PID_CODEPAGE;
718 hres = IPropertyStorage_ReadMultiple(*ppstg, 1, &prop, &ret);
719 if(FAILED(hres) || ret.vt!=VT_I2)
720 *puCodePage = 0;
721 else
722 *puCodePage = ret.u.iVal;
723 }
724 }
725
726 return S_OK;
727 }
728
729 /*************************************************************************
730 * SHPropStgReadMultiple [SHELL32.688]
731 */
732 HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
733 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
734 {
735 STATPROPSETSTG stat;
736 HRESULT hres;
737
738 FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
739
740 memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
741 hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
742 if(FAILED(hres))
743 return hres;
744
745 if(!uCodePage) {
746 PROPSPEC prop;
747 PROPVARIANT ret;
748
749 prop.ulKind = PRSPEC_PROPID;
750 prop.u.propid = PID_CODEPAGE;
751 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
752 if(FAILED(hres) || ret.vt!=VT_I2)
753 return S_OK;
754
755 uCodePage = ret.u.iVal;
756 }
757
758 hres = IPropertyStorage_Stat(pps, &stat);
759 if(FAILED(hres))
760 return S_OK;
761
762 /* TODO: do something with codepage and stat */
763 return S_OK;
764 }
765
766 /*************************************************************************
767 * SHPropStgWriteMultiple [SHELL32.689]
768 */
769 HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
770 ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
771 {
772 STATPROPSETSTG stat;
773 UINT codepage;
774 HRESULT hres;
775
776 FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
777
778 hres = IPropertyStorage_Stat(pps, &stat);
779 if(FAILED(hres))
780 return hres;
781
782 if(uCodePage && *uCodePage)
783 codepage = *uCodePage;
784 else {
785 PROPSPEC prop;
786 PROPVARIANT ret;
787
788 prop.ulKind = PRSPEC_PROPID;
789 prop.u.propid = PID_CODEPAGE;
790 hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
791 if(FAILED(hres))
792 return hres;
793 if(ret.vt!=VT_I2 || !ret.u.iVal)
794 return E_FAIL;
795
796 codepage = ret.u.iVal;
797 if(uCodePage)
798 *uCodePage = codepage;
799 }
800
801 /* TODO: do something with codepage and stat */
802
803 hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
804 return hres;
805 }
806
807 /*************************************************************************
808 * SHCreateQueryCancelAutoPlayMoniker [SHELL32.@]
809 */
810 HRESULT WINAPI SHCreateQueryCancelAutoPlayMoniker(IMoniker **moniker)
811 {
812 TRACE("%p\n", moniker);
813
814 if (!moniker) return E_INVALIDARG;
815 return CreateClassMoniker(&CLSID_QueryCancelAutoPlay, moniker);
816 }