-
Notifications
You must be signed in to change notification settings - Fork 1
/
shellole.c
1354 lines (1092 loc) · 36.1 KB
/
shellole.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* handling of SHELL32.DLL OLE-Objects
*
* Copyright 1997 Marcus Meissner
* Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#define COBJMACROS
#define NONAMELESSUNION
#include "windef.h"
#include "winbase.h"
#include "shellapi.h"
#include "wingdi.h"
#include "winuser.h"
#include "shlobj.h"
#include "shlguid.h"
#include "shldisp.h"
#include "gdiplus.h"
#include "shimgdata.h"
#include "winreg.h"
#include "winerror.h"
#include "undocshell.h"
#include "wine/unicode.h"
#include "shell32_main.h"
#include "wine/debug.h"
#include "shlwapi.h"
#include "debughlp.h"
WINE_DEFAULT_DEBUG_CHANNEL(shell);
extern INT WINAPI SHStringFromGUIDW(REFGUID guid, LPWSTR lpszDest, INT cchMax); /* shlwapi.24 */
static HRESULT WINAPI ShellImageDataFactory_Constructor(IUnknown *outer, REFIID riid, void **obj);
/**************************************************************************
* Default ClassFactory types
*/
typedef HRESULT (CALLBACK *LPFNCREATEINSTANCE)(IUnknown* pUnkOuter, REFIID riid, LPVOID* ppvObject);
static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst);
/* this table contains all CLSIDs of shell32 objects */
static const struct {
REFIID clsid;
LPFNCREATEINSTANCE lpfnCI;
} InterfaceTable[] = {
{&CLSID_ApplicationAssociationRegistration, ApplicationAssociationRegistration_Constructor},
{&CLSID_ApplicationDestinations, ApplicationDestinations_Constructor},
{&CLSID_AutoComplete, IAutoComplete_Constructor},
{&CLSID_ControlPanel, IControlPanel_Constructor},
{&CLSID_DragDropHelper, IDropTargetHelper_Constructor},
{&CLSID_FolderShortcut, FolderShortcut_Constructor},
{&CLSID_MyComputer, ISF_MyComputer_Constructor},
{&CLSID_MyDocuments, MyDocuments_Constructor},
{&CLSID_NetworkPlaces, ISF_NetworkPlaces_Constructor},
{&CLSID_Printers, Printers_Constructor},
{&CLSID_QueryAssociations, QueryAssociations_Constructor},
{&CLSID_RecycleBin, RecycleBin_Constructor},
{&CLSID_ShellDesktop, ISF_Desktop_Constructor},
{&CLSID_ShellFSFolder, IFSFolder_Constructor},
{&CLSID_ShellItem, IShellItem_Constructor},
{&CLSID_ShellLink, IShellLink_Constructor},
{&CLSID_UnixDosFolder, UnixDosFolder_Constructor},
{&CLSID_UnixFolder, UnixFolder_Constructor},
{&CLSID_ExplorerBrowser,ExplorerBrowser_Constructor},
{&CLSID_KnownFolderManager, KnownFolderManager_Constructor},
{&CLSID_Shell, IShellDispatch_Constructor},
{&CLSID_DestinationList, CustomDestinationList_Constructor},
{&CLSID_ShellImageDataFactory, ShellImageDataFactory_Constructor},
{NULL, NULL}
};
/*************************************************************************
* SHCoCreateInstance [SHELL32.102]
*
* Equivalent to CoCreateInstance. Under Windows 9x this function could sometimes
* use the shell32 built-in "mini-COM" without the need to load ole32.dll - see
* SHLoadOLE for details.
*
* Under wine if a "LoadWithoutCOM" value is present or the object resides in
* shell32.dll the function will load the object manually without the help of ole32
*
* NOTES
* exported by ordinal
*
* SEE ALSO
* CoCreateInstance, SHLoadOLE
*/
HRESULT WINAPI SHCoCreateInstance(
LPCWSTR aclsid,
const CLSID *clsid,
LPUNKNOWN pUnkOuter,
REFIID refiid,
LPVOID *ppv)
{
DWORD hres;
IID iid;
const CLSID * myclsid = clsid;
WCHAR sKeyName[MAX_PATH];
static const WCHAR sCLSID[] = {'C','L','S','I','D','\\','\0'};
WCHAR sClassID[60];
static const WCHAR sInProcServer32[] = {'\\','I','n','p','r','o','c','S','e','r','v','e','r','3','2','\0'};
static const WCHAR sLoadWithoutCOM[] = {'L','o','a','d','W','i','t','h','o','u','t','C','O','M','\0'};
WCHAR sDllPath[MAX_PATH];
HKEY hKey = 0;
DWORD dwSize;
IClassFactory * pcf = NULL;
if(!ppv) return E_POINTER;
*ppv=NULL;
/* if the clsid is a string, convert it */
if (!clsid)
{
if (!aclsid) return REGDB_E_CLASSNOTREG;
SHCLSIDFromStringW(aclsid, &iid);
myclsid = &iid;
}
TRACE("(%p,%s,unk:%p,%s,%p)\n",
aclsid,shdebugstr_guid(myclsid),pUnkOuter,shdebugstr_guid(refiid),ppv);
if (SUCCEEDED(DllGetClassObject(myclsid, &IID_IClassFactory,(LPVOID*)&pcf)))
{
hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
IClassFactory_Release(pcf);
goto end;
}
/* we look up the dll path in the registry */
SHStringFromGUIDW(myclsid, sClassID, ARRAY_SIZE(sClassID));
lstrcpyW(sKeyName, sCLSID);
lstrcatW(sKeyName, sClassID);
lstrcatW(sKeyName, sInProcServer32);
if (RegOpenKeyExW(HKEY_CLASSES_ROOT, sKeyName, 0, KEY_READ, &hKey))
return E_ACCESSDENIED;
/* if a special registry key is set, we load a shell extension without help of OLE32 */
if (!SHQueryValueExW(hKey, sLoadWithoutCOM, 0, 0, 0, 0))
{
/* load an external dll without ole32 */
HANDLE hLibrary;
typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid, REFIID iid, LPVOID *ppv);
DllGetClassObjectFunc DllGetClassObject;
dwSize = sizeof(sDllPath);
SHQueryValueExW(hKey, NULL, 0,0, sDllPath, &dwSize );
if ((hLibrary = LoadLibraryExW(sDllPath, 0, LOAD_WITH_ALTERED_SEARCH_PATH)) == 0) {
ERR("couldn't load InprocServer32 dll %s\n", debugstr_w(sDllPath));
hres = E_ACCESSDENIED;
goto end;
} else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject"))) {
ERR("couldn't find function DllGetClassObject in %s\n", debugstr_w(sDllPath));
FreeLibrary( hLibrary );
hres = E_ACCESSDENIED;
goto end;
} else if (FAILED(hres = DllGetClassObject(myclsid, &IID_IClassFactory, (LPVOID*)&pcf))) {
TRACE("GetClassObject failed 0x%08x\n", hres);
goto end;
}
hres = IClassFactory_CreateInstance(pcf, pUnkOuter, refiid, ppv);
IClassFactory_Release(pcf);
} else {
/* load an external dll in the usual way */
hres = CoCreateInstance(myclsid, pUnkOuter, CLSCTX_INPROC_SERVER, refiid, ppv);
}
end:
if (hKey) RegCloseKey(hKey);
if(hres!=S_OK)
{
ERR("failed (0x%08x) to create CLSID:%s IID:%s\n",
hres, shdebugstr_guid(myclsid), shdebugstr_guid(refiid));
ERR("class not found in registry\n");
}
TRACE("-- instance: %p\n",*ppv);
return hres;
}
/*************************************************************************
* DllGetClassObject [SHELL32.@]
* SHDllGetClassObject [SHELL32.128]
*/
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
{
IClassFactory * pcf = NULL;
HRESULT hres;
int i;
TRACE("CLSID:%s,IID:%s\n",shdebugstr_guid(rclsid),shdebugstr_guid(iid));
if (!ppv) return E_INVALIDARG;
*ppv = NULL;
/* search our internal interface table */
for(i=0;InterfaceTable[i].clsid;i++) {
if(IsEqualIID(InterfaceTable[i].clsid, rclsid)) {
TRACE("index[%u]\n", i);
pcf = IDefClF_fnConstructor(InterfaceTable[i].lpfnCI, NULL, NULL);
break;
}
}
if (!pcf) {
FIXME("failed for CLSID=%s\n", shdebugstr_guid(rclsid));
return CLASS_E_CLASSNOTAVAILABLE;
}
hres = IClassFactory_QueryInterface(pcf, iid, ppv);
IClassFactory_Release(pcf);
TRACE("-- pointer to class factory: %p\n",*ppv);
return hres;
}
/*************************************************************************
* SHCLSIDFromString [SHELL32.147]
*
* Under Windows 9x this was an ANSI version of CLSIDFromString. It also allowed
* to avoid dependency on ole32.dll (see SHLoadOLE for details).
*
* Under Windows NT/2000/XP this is equivalent to CLSIDFromString
*
* NOTES
* exported by ordinal
*
* SEE ALSO
* CLSIDFromString, SHLoadOLE
*/
DWORD WINAPI SHCLSIDFromStringA (LPCSTR clsid, CLSID *id)
{
WCHAR buffer[40];
TRACE("(%p(%s) %p)\n", clsid, clsid, id);
if (!MultiByteToWideChar( CP_ACP, 0, clsid, -1, buffer, ARRAY_SIZE(buffer) ))
return CO_E_CLASSSTRING;
return CLSIDFromString( buffer, id );
}
DWORD WINAPI SHCLSIDFromStringW (LPCWSTR clsid, CLSID *id)
{
TRACE("(%p(%s) %p)\n", clsid, debugstr_w(clsid), id);
return CLSIDFromString(clsid, id);
}
DWORD WINAPI SHCLSIDFromStringAW (LPCVOID clsid, CLSID *id)
{
if (SHELL_OsIsUnicode())
return SHCLSIDFromStringW (clsid, id);
return SHCLSIDFromStringA (clsid, id);
}
/*************************************************************************
* SHGetMalloc [SHELL32.@]
*
* Equivalent to CoGetMalloc(MEMCTX_TASK, ...). Under Windows 9x this function
* could use the shell32 built-in "mini-COM" without the need to load ole32.dll -
* see SHLoadOLE for details.
*
* PARAMS
* lpmal [O] Destination for IMalloc interface.
*
* RETURNS
* Success: S_OK. lpmal contains the shells IMalloc interface.
* Failure. An HRESULT error code.
*
* SEE ALSO
* CoGetMalloc, SHLoadOLE
*/
HRESULT WINAPI SHGetMalloc(LPMALLOC *lpmal)
{
TRACE("(%p)\n", lpmal);
return CoGetMalloc(MEMCTX_TASK, lpmal);
}
/*************************************************************************
* SHAlloc [SHELL32.196]
*
* Equivalent to CoTaskMemAlloc. Under Windows 9x this function could use
* the shell32 built-in "mini-COM" without the need to load ole32.dll -
* see SHLoadOLE for details.
*
* NOTES
* exported by ordinal
*
* SEE ALSO
* CoTaskMemAlloc, SHLoadOLE
*/
LPVOID WINAPI SHAlloc(DWORD len)
{
LPVOID ret;
ret = CoTaskMemAlloc(len);
TRACE("%u bytes at %p\n",len, ret);
return ret;
}
/*************************************************************************
* SHFree [SHELL32.195]
*
* Equivalent to CoTaskMemFree. Under Windows 9x this function could use
* the shell32 built-in "mini-COM" without the need to load ole32.dll -
* see SHLoadOLE for details.
*
* NOTES
* exported by ordinal
*
* SEE ALSO
* CoTaskMemFree, SHLoadOLE
*/
void WINAPI SHFree(LPVOID pv)
{
TRACE("%p\n",pv);
CoTaskMemFree(pv);
}
/*************************************************************************
* SHGetDesktopFolder [SHELL32.@]
*/
HRESULT WINAPI SHGetDesktopFolder(IShellFolder **psf)
{
HRESULT hres;
TRACE("(%p)\n", psf);
if(!psf) return E_INVALIDARG;
*psf = NULL;
hres = ISF_Desktop_Constructor(NULL, &IID_IShellFolder, (LPVOID*)psf);
TRACE("-- %p->(%p) 0x%08x\n", psf, *psf, hres);
return hres;
}
/**************************************************************************
* Default ClassFactory Implementation
*
* SHCreateDefClassObject
*
* NOTES
* Helper function for dlls without their own classfactory.
* A generic classfactory is returned.
* When the CreateInstance of the cf is called the callback is executed.
*/
typedef struct
{
IClassFactory IClassFactory_iface;
LONG ref;
CLSID *rclsid;
LPFNCREATEINSTANCE lpfnCI;
const IID * riidInst;
LONG * pcRefDll; /* pointer to refcounter in external dll (ugrrr...) */
} IDefClFImpl;
static inline IDefClFImpl *impl_from_IClassFactory(IClassFactory *iface)
{
return CONTAINING_RECORD(iface, IDefClFImpl, IClassFactory_iface);
}
static const IClassFactoryVtbl dclfvt;
/**************************************************************************
* IDefClF_fnConstructor
*/
static IClassFactory * IDefClF_fnConstructor(LPFNCREATEINSTANCE lpfnCI, PLONG pcRefDll, REFIID riidInst)
{
IDefClFImpl* lpclf;
lpclf = heap_alloc(sizeof(*lpclf));
lpclf->ref = 1;
lpclf->IClassFactory_iface.lpVtbl = &dclfvt;
lpclf->lpfnCI = lpfnCI;
lpclf->pcRefDll = pcRefDll;
if (pcRefDll) InterlockedIncrement(pcRefDll);
lpclf->riidInst = riidInst;
TRACE("(%p)%s\n",lpclf, shdebugstr_guid(riidInst));
return &lpclf->IClassFactory_iface;
}
/**************************************************************************
* IDefClF_fnQueryInterface
*/
static HRESULT WINAPI IDefClF_fnQueryInterface(
LPCLASSFACTORY iface, REFIID riid, LPVOID *ppvObj)
{
IDefClFImpl *This = impl_from_IClassFactory(iface);
TRACE("(%p)->(%s)\n",This,shdebugstr_guid(riid));
*ppvObj = NULL;
if(IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory)) {
*ppvObj = This;
InterlockedIncrement(&This->ref);
return S_OK;
}
TRACE("-- E_NOINTERFACE\n");
return E_NOINTERFACE;
}
/******************************************************************************
* IDefClF_fnAddRef
*/
static ULONG WINAPI IDefClF_fnAddRef(LPCLASSFACTORY iface)
{
IDefClFImpl *This = impl_from_IClassFactory(iface);
ULONG refCount = InterlockedIncrement(&This->ref);
TRACE("(%p)->(count=%u)\n", This, refCount - 1);
return refCount;
}
/******************************************************************************
* IDefClF_fnRelease
*/
static ULONG WINAPI IDefClF_fnRelease(LPCLASSFACTORY iface)
{
IDefClFImpl *This = impl_from_IClassFactory(iface);
ULONG refCount = InterlockedDecrement(&This->ref);
TRACE("(%p)->(count=%u)\n", This, refCount + 1);
if (!refCount)
{
if (This->pcRefDll) InterlockedDecrement(This->pcRefDll);
TRACE("-- destroying IClassFactory(%p)\n",This);
heap_free(This);
}
return refCount;
}
/******************************************************************************
* IDefClF_fnCreateInstance
*/
static HRESULT WINAPI IDefClF_fnCreateInstance(
LPCLASSFACTORY iface, LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObject)
{
IDefClFImpl *This = impl_from_IClassFactory(iface);
TRACE("%p->(%p,%s,%p)\n",This,pUnkOuter,shdebugstr_guid(riid),ppvObject);
*ppvObject = NULL;
if ( This->riidInst==NULL ||
IsEqualCLSID(riid, This->riidInst) ||
IsEqualCLSID(riid, &IID_IUnknown) )
{
return This->lpfnCI(pUnkOuter, riid, ppvObject);
}
ERR("unknown IID requested %s\n",shdebugstr_guid(riid));
return E_NOINTERFACE;
}
/******************************************************************************
* IDefClF_fnLockServer
*/
static HRESULT WINAPI IDefClF_fnLockServer(LPCLASSFACTORY iface, BOOL fLock)
{
IDefClFImpl *This = impl_from_IClassFactory(iface);
TRACE("%p->(0x%x), not implemented\n",This, fLock);
return E_NOTIMPL;
}
static const IClassFactoryVtbl dclfvt =
{
IDefClF_fnQueryInterface,
IDefClF_fnAddRef,
IDefClF_fnRelease,
IDefClF_fnCreateInstance,
IDefClF_fnLockServer
};
/******************************************************************************
* SHCreateDefClassObject [SHELL32.70]
*/
HRESULT WINAPI SHCreateDefClassObject(
REFIID riid,
LPVOID* ppv,
LPFNCREATEINSTANCE lpfnCI, /* [in] create instance callback entry */
LPDWORD pcRefDll, /* [in/out] ref count of the dll */
REFIID riidInst) /* [in] optional interface to the instance */
{
IClassFactory * pcf;
TRACE("%s %p %p %p %s\n",
shdebugstr_guid(riid), ppv, lpfnCI, pcRefDll, shdebugstr_guid(riidInst));
if (! IsEqualCLSID(riid, &IID_IClassFactory) ) return E_NOINTERFACE;
if (! (pcf = IDefClF_fnConstructor(lpfnCI, (PLONG)pcRefDll, riidInst))) return E_OUTOFMEMORY;
*ppv = pcf;
return S_OK;
}
/*************************************************************************
* DragAcceptFiles [SHELL32.@]
*/
void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
{
LONG exstyle;
if( !IsWindow(hWnd) ) return;
exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
if (b)
exstyle |= WS_EX_ACCEPTFILES;
else
exstyle &= ~WS_EX_ACCEPTFILES;
SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
}
/*************************************************************************
* DragFinish [SHELL32.@]
*/
void WINAPI DragFinish(HDROP h)
{
TRACE("\n");
GlobalFree(h);
}
/*************************************************************************
* DragQueryPoint [SHELL32.@]
*/
BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
{
DROPFILES *lpDropFileStruct;
BOOL bRet;
TRACE("\n");
lpDropFileStruct = GlobalLock(hDrop);
*p = lpDropFileStruct->pt;
bRet = !lpDropFileStruct->fNC;
GlobalUnlock(hDrop);
return bRet;
}
/*************************************************************************
* DragQueryFileA [SHELL32.@]
* DragQueryFile [SHELL32.@]
*/
UINT WINAPI DragQueryFileA(
HDROP hDrop,
UINT lFile,
LPSTR lpszFile,
UINT lLength)
{
LPSTR lpDrop;
UINT i = 0;
DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszFile,lLength);
if(!lpDropFileStruct) goto end;
lpDrop = (LPSTR) lpDropFileStruct + lpDropFileStruct->pFiles;
if(lpDropFileStruct->fWide) {
LPWSTR lpszFileW = NULL;
if(lpszFile && lFile != 0xFFFFFFFF) {
lpszFileW = heap_alloc(lLength*sizeof(WCHAR));
if(lpszFileW == NULL) {
goto end;
}
}
i = DragQueryFileW(hDrop, lFile, lpszFileW, lLength);
if(lpszFileW) {
WideCharToMultiByte(CP_ACP, 0, lpszFileW, -1, lpszFile, lLength, 0, NULL);
heap_free(lpszFileW);
}
goto end;
}
while (i++ < lFile)
{
while (*lpDrop++); /* skip filename */
if (!*lpDrop)
{
i = (lFile == 0xFFFFFFFF) ? i : 0;
goto end;
}
}
i = strlen(lpDrop);
if (!lpszFile ) goto end; /* needed buffer size */
lstrcpynA (lpszFile, lpDrop, lLength);
end:
GlobalUnlock(hDrop);
return i;
}
/*************************************************************************
* DragQueryFileW [SHELL32.@]
*/
UINT WINAPI DragQueryFileW(
HDROP hDrop,
UINT lFile,
LPWSTR lpszwFile,
UINT lLength)
{
LPWSTR lpwDrop;
UINT i = 0;
DROPFILES *lpDropFileStruct = GlobalLock(hDrop);
TRACE("(%p, %x, %p, %u)\n", hDrop,lFile,lpszwFile,lLength);
if(!lpDropFileStruct) goto end;
lpwDrop = (LPWSTR) ((LPSTR)lpDropFileStruct + lpDropFileStruct->pFiles);
if(lpDropFileStruct->fWide == FALSE) {
LPSTR lpszFileA = NULL;
if(lpszwFile && lFile != 0xFFFFFFFF) {
lpszFileA = heap_alloc(lLength);
if(lpszFileA == NULL) {
goto end;
}
}
i = DragQueryFileA(hDrop, lFile, lpszFileA, lLength);
if(lpszFileA) {
MultiByteToWideChar(CP_ACP, 0, lpszFileA, -1, lpszwFile, lLength);
heap_free(lpszFileA);
}
goto end;
}
i = 0;
while (i++ < lFile)
{
while (*lpwDrop++); /* skip filename */
if (!*lpwDrop)
{
i = (lFile == 0xFFFFFFFF) ? i : 0;
goto end;
}
}
i = strlenW(lpwDrop);
if ( !lpszwFile) goto end; /* needed buffer size */
lstrcpynW (lpszwFile, lpwDrop, lLength);
end:
GlobalUnlock(hDrop);
return i;
}
/*************************************************************************
* SHPropStgCreate [SHELL32.685]
*/
HRESULT WINAPI SHPropStgCreate(IPropertySetStorage *psstg, REFFMTID fmtid,
const CLSID *pclsid, DWORD grfFlags, DWORD grfMode,
DWORD dwDisposition, IPropertyStorage **ppstg, UINT *puCodePage)
{
PROPSPEC prop;
PROPVARIANT ret;
HRESULT hres;
TRACE("%p %s %s %x %x %x %p %p\n", psstg, debugstr_guid(fmtid), debugstr_guid(pclsid),
grfFlags, grfMode, dwDisposition, ppstg, puCodePage);
hres = IPropertySetStorage_Open(psstg, fmtid, grfMode, ppstg);
switch(dwDisposition) {
case CREATE_ALWAYS:
if(SUCCEEDED(hres)) {
IPropertyStorage_Release(*ppstg);
hres = IPropertySetStorage_Delete(psstg, fmtid);
if(FAILED(hres))
return hres;
hres = E_FAIL;
}
case OPEN_ALWAYS:
case CREATE_NEW:
if(FAILED(hres))
hres = IPropertySetStorage_Create(psstg, fmtid, pclsid,
grfFlags, grfMode, ppstg);
case OPEN_EXISTING:
if(FAILED(hres))
return hres;
if(puCodePage) {
prop.ulKind = PRSPEC_PROPID;
prop.u.propid = PID_CODEPAGE;
hres = IPropertyStorage_ReadMultiple(*ppstg, 1, &prop, &ret);
if(FAILED(hres) || ret.vt!=VT_I2)
*puCodePage = 0;
else
*puCodePage = ret.u.iVal;
}
}
return S_OK;
}
/*************************************************************************
* SHPropStgReadMultiple [SHELL32.688]
*/
HRESULT WINAPI SHPropStgReadMultiple(IPropertyStorage *pps, UINT uCodePage,
ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar)
{
STATPROPSETSTG stat;
HRESULT hres;
FIXME("%p %u %u %p %p\n", pps, uCodePage, cpspec, rgpspec, rgvar);
memset(rgvar, 0, cpspec*sizeof(PROPVARIANT));
hres = IPropertyStorage_ReadMultiple(pps, cpspec, rgpspec, rgvar);
if(FAILED(hres))
return hres;
if(!uCodePage) {
PROPSPEC prop;
PROPVARIANT ret;
prop.ulKind = PRSPEC_PROPID;
prop.u.propid = PID_CODEPAGE;
hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
if(FAILED(hres) || ret.vt!=VT_I2)
return S_OK;
uCodePage = ret.u.iVal;
}
hres = IPropertyStorage_Stat(pps, &stat);
if(FAILED(hres))
return S_OK;
/* TODO: do something with codepage and stat */
return S_OK;
}
/*************************************************************************
* SHPropStgWriteMultiple [SHELL32.689]
*/
HRESULT WINAPI SHPropStgWriteMultiple(IPropertyStorage *pps, UINT *uCodePage,
ULONG cpspec, const PROPSPEC *rgpspec, PROPVARIANT *rgvar, PROPID propidNameFirst)
{
STATPROPSETSTG stat;
UINT codepage;
HRESULT hres;
FIXME("%p %p %u %p %p %d\n", pps, uCodePage, cpspec, rgpspec, rgvar, propidNameFirst);
hres = IPropertyStorage_Stat(pps, &stat);
if(FAILED(hres))
return hres;
if(uCodePage && *uCodePage)
codepage = *uCodePage;
else {
PROPSPEC prop;
PROPVARIANT ret;
prop.ulKind = PRSPEC_PROPID;
prop.u.propid = PID_CODEPAGE;
hres = IPropertyStorage_ReadMultiple(pps, 1, &prop, &ret);
if(FAILED(hres))
return hres;
if(ret.vt!=VT_I2 || !ret.u.iVal)
return E_FAIL;
codepage = ret.u.iVal;
if(uCodePage)
*uCodePage = codepage;
}
/* TODO: do something with codepage and stat */
hres = IPropertyStorage_WriteMultiple(pps, cpspec, rgpspec, rgvar, propidNameFirst);
return hres;
}
/*************************************************************************
* SHCreateQueryCancelAutoPlayMoniker [SHELL32.@]
*/
HRESULT WINAPI SHCreateQueryCancelAutoPlayMoniker(IMoniker **moniker)
{
TRACE("%p\n", moniker);
if (!moniker) return E_INVALIDARG;
return CreateClassMoniker(&CLSID_QueryCancelAutoPlay, moniker);
}
static HRESULT gpstatus_to_hresult(GpStatus status)
{
switch (status)
{
case Ok:
return S_OK;
case InvalidParameter:
return E_INVALIDARG;
case OutOfMemory:
return E_OUTOFMEMORY;
case NotImplemented:
return E_NOTIMPL;
default:
return E_FAIL;
}
}
/* IShellImageData */
typedef struct
{
IShellImageData IShellImageData_iface;
LONG ref;
WCHAR *path;
GpImage *image;
} ShellImageData;
static inline ShellImageData *impl_from_IShellImageData(IShellImageData *iface)
{
return CONTAINING_RECORD(iface, ShellImageData, IShellImageData_iface);
}
static HRESULT WINAPI ShellImageData_QueryInterface(IShellImageData *iface, REFIID riid, void **obj)
{
ShellImageData *This = impl_from_IShellImageData(iface);
TRACE("%p, %s, %p\n", This, debugstr_guid(riid), obj);
if (IsEqualIID(riid, &IID_IShellImageData) || IsEqualIID(riid, &IID_IUnknown))
{
*obj = &This->IShellImageData_iface;
IShellImageData_AddRef(iface);
return S_OK;
}
*obj = NULL;
return E_NOINTERFACE;
}
static ULONG WINAPI ShellImageData_AddRef(IShellImageData *iface)
{
ShellImageData *This = impl_from_IShellImageData(iface);
ULONG ref = InterlockedIncrement(&This->ref);
TRACE("%p, %u\n", This, ref);
return ref;
}
static ULONG WINAPI ShellImageData_Release(IShellImageData *iface)
{
ShellImageData *This = impl_from_IShellImageData(iface);
ULONG ref = InterlockedDecrement(&This->ref);
TRACE("%p, %u\n", This, ref);
if (!ref)
{
GdipDisposeImage(This->image);
heap_free(This->path);
SHFree(This);
}
return ref;
}
static HRESULT WINAPI ShellImageData_Decode(IShellImageData *iface, DWORD flags, ULONG cx_desired, ULONG cy_desired)
{
ShellImageData *This = impl_from_IShellImageData(iface);
GpImage *image;
HRESULT hr;
TRACE("%p, %#x, %u, %u\n", This, flags, cx_desired, cy_desired);
if (This->image)
return S_FALSE;
if (flags & SHIMGDEC_LOADFULL)
FIXME("LOADFULL flag ignored\n");
hr = gpstatus_to_hresult(GdipLoadImageFromFile(This->path, &image));
if (FAILED(hr))
return hr;
if (flags & SHIMGDEC_THUMBNAIL)
{
hr = gpstatus_to_hresult(GdipGetImageThumbnail(image, cx_desired, cy_desired, &This->image, NULL, NULL));
GdipDisposeImage(image);
}
else
This->image = image;
return hr;
}
static HRESULT WINAPI ShellImageData_Draw(IShellImageData *iface, HDC hdc, RECT *dest, RECT *src)
{
ShellImageData *This = impl_from_IShellImageData(iface);
GpGraphics *graphics;
HRESULT hr;
TRACE("%p, %p, %s, %s\n", This, hdc, wine_dbgstr_rect(dest), wine_dbgstr_rect(src));
if (!This->image)
return E_FAIL;
if (!dest)
return E_INVALIDARG;
if (!src)
return S_OK;
hr = gpstatus_to_hresult(GdipCreateFromHDC(hdc, &graphics));
if (FAILED(hr))
return hr;
hr = gpstatus_to_hresult(GdipDrawImageRectRectI(graphics, This->image, dest->left, dest->top, dest->right - dest->left,
dest->bottom - dest->top, src->left, src->top, src->right - src->left, src->bottom - src->top,
UnitPixel, NULL, NULL, NULL));
GdipDeleteGraphics(graphics);
return hr;
}
static HRESULT WINAPI ShellImageData_NextFrame(IShellImageData *iface)
{
ShellImageData *This = impl_from_IShellImageData(iface);
FIXME("%p: stub\n", This);
return E_NOTIMPL;
}
static HRESULT WINAPI ShellImageData_NextPage(IShellImageData *iface)
{
ShellImageData *This = impl_from_IShellImageData(iface);
FIXME("%p: stub\n", This);
return E_NOTIMPL;
}
static HRESULT WINAPI ShellImageData_PrevPage(IShellImageData *iface)
{
ShellImageData *This = impl_from_IShellImageData(iface);
FIXME("%p: stub\n", This);
return E_NOTIMPL;
}
static HRESULT WINAPI ShellImageData_IsTransparent(IShellImageData *iface)
{
ShellImageData *This = impl_from_IShellImageData(iface);
FIXME("%p: stub\n", This);
return E_NOTIMPL;
}
static HRESULT WINAPI ShellImageData_IsAnimated(IShellImageData *iface)
{
ShellImageData *This = impl_from_IShellImageData(iface);
FIXME("%p: stub\n", This);
return E_NOTIMPL;
}
static HRESULT WINAPI ShellImageData_IsVector(IShellImageData *iface)
{
ShellImageData *This = impl_from_IShellImageData(iface);
FIXME("%p: stub\n", This);