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