mirrored from git://source.winehq.org/git/wine.git
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
ole2.c
3163 lines (2706 loc) · 86.3 KB
/
ole2.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
/*
* OLE2 library
*
* Copyright 1995 Martin von Loewis
* Copyright 1999 Francis Beaudet
* Copyright 1999 Noel Borthwick
* Copyright 1999, 2000 Marcus Meissner
* Copyright 1999-2000 Abey George
* Copyright 2005 Juan Lang
* Copyright 2011 Adam Martinson for CodeWeavers
*
* 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 <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#define COBJMACROS
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "wingdi.h"
#include "winuser.h"
#include "winnls.h"
#include "winreg.h"
#include "ole2.h"
#include "ole2ver.h"
#include "compobj_private.h"
#include "olestd.h"
#include "wine/list.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(ole);
WINE_DECLARE_DEBUG_CHANNEL(accel);
/******************************************************************************
* These are static/global variables and internal data structures that the
* OLE module uses to maintain its state.
*/
typedef struct tagTrackerWindowInfo
{
IDataObject* dataObject;
IDropSource* dropSource;
DWORD dwOKEffect;
DWORD* pdwEffect;
BOOL trackingDone;
BOOL inTrackCall;
HRESULT returnValue;
BOOL escPressed;
HWND curTargetHWND; /* window the mouse is hovering over */
IDropTarget* curDragTarget;
POINTL curMousePos; /* current position of the mouse in screen coordinates */
DWORD dwKeyState; /* current state of the shift and ctrl keys and the mouse buttons */
} TrackerWindowInfo;
typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
{
HWND hwndFrame; /* The containers frame window */
HWND hwndActiveObject; /* The active objects window */
OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
HMENU hmenuCombined; /* The combined menu */
BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
} OleMenuDescriptor;
typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
{
DWORD tid; /* Thread Id */
HANDLE hHeap; /* Heap this is allocated from */
HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
struct tagOleMenuHookItem *next;
} OleMenuHookItem;
static OleMenuHookItem *hook_list;
/*
* This is the lock count on the OLE library. It is controlled by the
* OLEInitialize/OLEUninitialize methods.
*/
static LONG OLE_moduleLockCount = 0;
/*
* Name of our registered window class.
*/
static const WCHAR OLEDD_DRAGTRACKERCLASS[] = L"WineDragDropTracker32";
/*
* Name of menu descriptor property.
*/
static const WCHAR prop_olemenuW[] = L"PROP_OLEMenuDescriptor";
/* property to store IDropTarget pointer */
static const WCHAR prop_oledroptarget[] = L"OleDropTargetInterface";
/* property to store Marshalled IDropTarget pointer */
static const WCHAR prop_marshalleddroptarget[] = L"WineMarshalledDropTarget";
/******************************************************************************
* These are the prototypes of miscellaneous utility methods
*/
static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
/******************************************************************************
* These are the prototypes of the utility methods used to manage a shared menu
*/
static void OLEMenu_Initialize(void);
static void OLEMenu_UnInitialize(void);
static BOOL OLEMenu_InstallHooks( DWORD tid );
static BOOL OLEMenu_UnInstallHooks( DWORD tid );
static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
/******************************************************************************
* This is a prototype of the OLE Clipboard uninitialization method (in clipboard.c)
*/
extern void clipbrd_uninitialize(void);
/******************************************************************************
* These are the prototypes of the utility methods used for OLE Drag n Drop
*/
static void OLEDD_Initialize(void);
static LRESULT WINAPI OLEDD_DragTrackerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo);
static DWORD OLEDD_GetButtonState(void);
/******************************************************************************
* OleBuildVersion [OLE32.@]
*/
DWORD WINAPI OleBuildVersion(void)
{
TRACE("Returning version %d, build %d.\n", rmm, rup);
return (rmm<<16)+rup;
}
/***********************************************************************
* OleInitialize (OLE32.@)
*/
HRESULT WINAPI DECLSPEC_HOTPATCH OleInitialize(LPVOID reserved)
{
HRESULT hr;
TRACE("(%p)\n", reserved);
/*
* The first duty of the OleInitialize is to initialize the COM libraries.
*/
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
/*
* If the CoInitializeEx call failed, the OLE libraries can't be
* initialized.
*/
if (FAILED(hr))
return hr;
if (!COM_CurrentInfo()->ole_inits)
hr = S_OK;
else
hr = S_FALSE;
/*
* Then, it has to initialize the OLE specific modules.
* This includes:
* Clipboard
* Drag and Drop
* Object linking and Embedding
* In-place activation
*/
if (!COM_CurrentInfo()->ole_inits++ &&
InterlockedIncrement(&OLE_moduleLockCount) == 1)
{
/*
* Initialize the libraries.
*/
TRACE("() - Initializing the OLE libraries\n");
/*
* Drag and Drop
*/
OLEDD_Initialize();
/*
* OLE shared menu
*/
OLEMenu_Initialize();
}
return hr;
}
/******************************************************************************
* OleUninitialize [OLE32.@]
*/
void WINAPI DECLSPEC_HOTPATCH OleUninitialize(void)
{
TRACE("()\n");
if (COM_CurrentInfo()->ole_inits == 0)
{
WARN("ole_inits is already 0\n");
return ;
}
/*
* If we hit the bottom of the lock stack, free the libraries.
*/
if (!--COM_CurrentInfo()->ole_inits && !InterlockedDecrement(&OLE_moduleLockCount))
{
/*
* Actually free the libraries.
*/
TRACE("() - Freeing the last reference count\n");
/*
* OLE Clipboard
*/
clipbrd_uninitialize();
/*
* OLE shared menu
*/
OLEMenu_UnInitialize();
}
/*
* Then, uninitialize the COM libraries.
*/
CoUninitialize();
}
/******************************************************************************
* OleInitializeWOW [OLE32.@]
*/
HRESULT WINAPI OleInitializeWOW(DWORD x, DWORD y)
{
FIXME("%#lx, %#lx stub!\n", x, y);
return 0;
}
/*************************************************************
* get_droptarget_handle
*
* Retrieve a handle to the map containing the marshalled IDropTarget.
* This handle belongs to the process that called RegisterDragDrop.
* See get_droptarget_local_handle().
*/
static inline HANDLE get_droptarget_handle(HWND hwnd)
{
return GetPropW(hwnd, prop_marshalleddroptarget);
}
/*************************************************************
* is_droptarget
*
* Is the window a droptarget.
*/
static inline BOOL is_droptarget(HWND hwnd)
{
return get_droptarget_handle(hwnd) != 0;
}
/*************************************************************
* get_droptarget_local_handle
*
* Retrieve a handle to the map containing the marshalled IDropTarget.
* The handle should be closed when finished with.
*/
static HANDLE get_droptarget_local_handle(HWND hwnd)
{
HANDLE handle, local_handle = 0;
handle = get_droptarget_handle(hwnd);
if(handle)
{
DWORD pid;
HANDLE process;
GetWindowThreadProcessId(hwnd, &pid);
process = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid);
if(process)
{
DuplicateHandle(process, handle, GetCurrentProcess(), &local_handle, 0, FALSE, DUPLICATE_SAME_ACCESS);
CloseHandle(process);
}
}
return local_handle;
}
/***********************************************************************
* create_map_from_stream
*
* Helper for RegisterDragDrop. Creates a file mapping object
* with the contents of the provided stream. The stream must
* be a global memory backed stream.
*/
static HRESULT create_map_from_stream(IStream *stream, HANDLE *map)
{
HGLOBAL hmem;
DWORD size;
HRESULT hr;
void *data;
hr = GetHGlobalFromStream(stream, &hmem);
if(FAILED(hr)) return hr;
size = GlobalSize(hmem);
*map = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, NULL);
if(!*map) return E_OUTOFMEMORY;
data = MapViewOfFile(*map, FILE_MAP_WRITE, 0, 0, size);
memcpy(data, GlobalLock(hmem), size);
GlobalUnlock(hmem);
UnmapViewOfFile(data);
return S_OK;
}
/***********************************************************************
* create_stream_from_map
*
* Creates a stream from the provided map.
*/
static HRESULT create_stream_from_map(HANDLE map, IStream **stream)
{
HRESULT hr = E_OUTOFMEMORY;
HGLOBAL hmem;
void *data;
MEMORY_BASIC_INFORMATION info;
data = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
if(!data) return hr;
VirtualQuery(data, &info, sizeof(info));
TRACE("size %d\n", (int)info.RegionSize);
hmem = GlobalAlloc(GMEM_MOVEABLE, info.RegionSize);
if(hmem)
{
memcpy(GlobalLock(hmem), data, info.RegionSize);
GlobalUnlock(hmem);
hr = CreateStreamOnHGlobal(hmem, TRUE, stream);
}
UnmapViewOfFile(data);
return hr;
}
/* This is to work around apps which break COM rules by not implementing
* IDropTarget::QueryInterface(). Windows doesn't expose this because it
* doesn't call CoMarshallInterface() in RegisterDragDrop().
* The wrapper is only used internally, and only exists for the life of
* the marshal. We don't want to hold a ref on the app provided target
* as some apps destroy this prior to CoUninitialize without calling
* RevokeDragDrop. The only (long-term) ref is held by the window prop. */
typedef struct {
IDropTarget IDropTarget_iface;
HWND hwnd;
LONG refs;
} DropTargetWrapper;
static inline DropTargetWrapper* impl_from_IDropTarget(IDropTarget* iface)
{
return CONTAINING_RECORD(iface, DropTargetWrapper, IDropTarget_iface);
}
static HRESULT WINAPI DropTargetWrapper_QueryInterface(IDropTarget* iface,
REFIID riid,
void** ppvObject)
{
DropTargetWrapper* This = impl_from_IDropTarget(iface);
if (IsEqualIID(riid, &IID_IUnknown) ||
IsEqualIID(riid, &IID_IDropTarget))
{
IDropTarget_AddRef(&This->IDropTarget_iface);
*ppvObject = &This->IDropTarget_iface;
return S_OK;
}
*ppvObject = NULL;
return E_NOINTERFACE;
}
static ULONG WINAPI DropTargetWrapper_AddRef(IDropTarget* iface)
{
DropTargetWrapper* This = impl_from_IDropTarget(iface);
return InterlockedIncrement(&This->refs);
}
static ULONG WINAPI DropTargetWrapper_Release(IDropTarget* iface)
{
DropTargetWrapper* This = impl_from_IDropTarget(iface);
ULONG refs = InterlockedDecrement(&This->refs);
if (!refs) HeapFree(GetProcessHeap(), 0, This);
return refs;
}
static inline HRESULT get_target_from_wrapper( IDropTarget *wrapper, IDropTarget **target )
{
DropTargetWrapper* This = impl_from_IDropTarget( wrapper );
*target = GetPropW( This->hwnd, prop_oledroptarget );
if (!*target) return DRAGDROP_E_NOTREGISTERED;
IDropTarget_AddRef( *target );
return S_OK;
}
static HRESULT WINAPI DropTargetWrapper_DragEnter(IDropTarget* iface,
IDataObject* pDataObj,
DWORD grfKeyState,
POINTL pt,
DWORD* pdwEffect)
{
IDropTarget *target;
HRESULT r = get_target_from_wrapper( iface, &target );
if (SUCCEEDED( r ))
{
r = IDropTarget_DragEnter( target, pDataObj, grfKeyState, pt, pdwEffect );
IDropTarget_Release( target );
}
return r;
}
static HRESULT WINAPI DropTargetWrapper_DragOver(IDropTarget* iface,
DWORD grfKeyState,
POINTL pt,
DWORD* pdwEffect)
{
IDropTarget *target;
HRESULT r = get_target_from_wrapper( iface, &target );
if (SUCCEEDED( r ))
{
r = IDropTarget_DragOver( target, grfKeyState, pt, pdwEffect );
IDropTarget_Release( target );
}
return r;
}
static HRESULT WINAPI DropTargetWrapper_DragLeave(IDropTarget* iface)
{
IDropTarget *target;
HRESULT r = get_target_from_wrapper( iface, &target );
if (SUCCEEDED( r ))
{
r = IDropTarget_DragLeave( target );
IDropTarget_Release( target );
}
return r;
}
static HRESULT WINAPI DropTargetWrapper_Drop(IDropTarget* iface,
IDataObject* pDataObj,
DWORD grfKeyState,
POINTL pt,
DWORD* pdwEffect)
{
IDropTarget *target;
HRESULT r = get_target_from_wrapper( iface, &target );
if (SUCCEEDED( r ))
{
r = IDropTarget_Drop( target, pDataObj, grfKeyState, pt, pdwEffect );
IDropTarget_Release( target );
}
return r;
}
static const IDropTargetVtbl DropTargetWrapperVTbl =
{
DropTargetWrapper_QueryInterface,
DropTargetWrapper_AddRef,
DropTargetWrapper_Release,
DropTargetWrapper_DragEnter,
DropTargetWrapper_DragOver,
DropTargetWrapper_DragLeave,
DropTargetWrapper_Drop
};
static IDropTarget* WrapDropTarget( HWND hwnd )
{
DropTargetWrapper* This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
if (This)
{
This->IDropTarget_iface.lpVtbl = &DropTargetWrapperVTbl;
This->hwnd = hwnd;
This->refs = 1;
}
return &This->IDropTarget_iface;
}
/***********************************************************************
* get_droptarget_pointer
*
* Retrieves the marshalled IDropTarget from the window.
*/
static IDropTarget* get_droptarget_pointer(HWND hwnd)
{
IDropTarget *droptarget = NULL;
HANDLE map;
IStream *stream;
map = get_droptarget_local_handle(hwnd);
if(!map) return NULL;
if(SUCCEEDED(create_stream_from_map(map, &stream)))
{
CoUnmarshalInterface(stream, &IID_IDropTarget, (void**)&droptarget);
IStream_Release(stream);
}
CloseHandle(map);
return droptarget;
}
/***********************************************************************
* RegisterDragDrop (OLE32.@)
*/
HRESULT WINAPI RegisterDragDrop(HWND hwnd, LPDROPTARGET pDropTarget)
{
DWORD pid = 0;
HRESULT hr;
IStream *stream;
HANDLE map;
IDropTarget *wrapper;
TRACE("(%p,%p)\n", hwnd, pDropTarget);
if (!COM_CurrentApt())
{
ERR("COM not initialized\n");
return E_OUTOFMEMORY;
}
if (!pDropTarget)
return E_INVALIDARG;
if (!IsWindow(hwnd))
{
ERR("invalid hwnd %p\n", hwnd);
return DRAGDROP_E_INVALIDHWND;
}
/* block register for other processes windows */
GetWindowThreadProcessId(hwnd, &pid);
if (pid != GetCurrentProcessId())
{
FIXME("register for another process windows is disabled\n");
return DRAGDROP_E_INVALIDHWND;
}
/* check if the window is already registered */
if (is_droptarget(hwnd))
return DRAGDROP_E_ALREADYREGISTERED;
/*
* Marshal the drop target pointer into a shared memory map and
* store the map's handle in a Wine specific window prop. We also
* store the drop target pointer itself in the
* "OleDropTargetInterface" prop for compatibility with Windows.
*/
hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
if(FAILED(hr)) return hr;
/* IDropTarget::QueryInterface() shouldn't be called, some (broken) apps depend on this. */
wrapper = WrapDropTarget( hwnd );
if(!wrapper)
{
IStream_Release(stream);
return E_OUTOFMEMORY;
}
hr = CoMarshalInterface(stream, &IID_IDropTarget, (IUnknown*)wrapper, MSHCTX_LOCAL, NULL, MSHLFLAGS_TABLESTRONG);
IDropTarget_Release(wrapper);
if(SUCCEEDED(hr))
{
hr = create_map_from_stream(stream, &map);
if(SUCCEEDED(hr))
{
IDropTarget_AddRef(pDropTarget);
SetPropW(hwnd, prop_oledroptarget, pDropTarget);
SetPropW(hwnd, prop_marshalleddroptarget, map);
}
else
{
LARGE_INTEGER zero;
zero.QuadPart = 0;
IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
CoReleaseMarshalData(stream);
}
}
IStream_Release(stream);
return hr;
}
/***********************************************************************
* RevokeDragDrop (OLE32.@)
*/
HRESULT WINAPI RevokeDragDrop(HWND hwnd)
{
HANDLE map;
IStream *stream;
IDropTarget *drop_target;
HRESULT hr;
TRACE("(%p)\n", hwnd);
if (!IsWindow(hwnd))
{
ERR("invalid hwnd %p\n", hwnd);
return DRAGDROP_E_INVALIDHWND;
}
/* no registration data */
if (!(map = get_droptarget_handle(hwnd)))
return DRAGDROP_E_NOTREGISTERED;
drop_target = GetPropW(hwnd, prop_oledroptarget);
if(drop_target) IDropTarget_Release(drop_target);
RemovePropW(hwnd, prop_oledroptarget);
RemovePropW(hwnd, prop_marshalleddroptarget);
hr = create_stream_from_map(map, &stream);
if(SUCCEEDED(hr))
{
CoReleaseMarshalData(stream);
IStream_Release(stream);
}
CloseHandle(map);
return hr;
}
/***********************************************************************
* OleRegGetUserType (OLE32.@)
*/
HRESULT WINAPI OleRegGetUserType(REFCLSID clsid, DWORD form, LPOLESTR *usertype)
{
DWORD valuetype, valuelen;
WCHAR auxkeynameW[16];
HKEY usertypekey;
HRESULT hres;
LONG ret;
TRACE("%s, %lu, %p.\n", debugstr_guid(clsid), form, usertype);
if (!usertype)
return E_INVALIDARG;
*usertype = NULL;
/* Return immediately if it's not registered. */
hres = COM_OpenKeyForCLSID(clsid, NULL, KEY_READ, &usertypekey);
if (FAILED(hres))
return hres;
valuelen = 0;
/* Try additional types if requested. If they don't exist fall back to USERCLASSTYPE_FULL. */
if (form != USERCLASSTYPE_FULL)
{
HKEY auxkey;
swprintf(auxkeynameW, ARRAY_SIZE(auxkeynameW), L"AuxUserType\\%d", form);
if (COM_OpenKeyForCLSID(clsid, auxkeynameW, KEY_READ, &auxkey) == S_OK)
{
if (!RegQueryValueExW(auxkey, L"", NULL, &valuetype, NULL, &valuelen) && valuelen)
{
RegCloseKey(usertypekey);
usertypekey = auxkey;
}
else
RegCloseKey(auxkey);
}
}
valuelen = 0;
if (RegQueryValueExW(usertypekey, L"", NULL, &valuetype, NULL, &valuelen))
{
RegCloseKey(usertypekey);
return REGDB_E_READREGDB;
}
*usertype = CoTaskMemAlloc(valuelen);
if (!*usertype)
{
RegCloseKey(usertypekey);
return E_OUTOFMEMORY;
}
ret = RegQueryValueExW(usertypekey, L"", NULL, &valuetype, (BYTE *)*usertype, &valuelen);
RegCloseKey(usertypekey);
if (ret != ERROR_SUCCESS)
{
CoTaskMemFree(*usertype);
*usertype = NULL;
return REGDB_E_READREGDB;
}
return S_OK;
}
/***********************************************************************
* DoDragDrop [OLE32.@]
*/
HRESULT WINAPI DoDragDrop (
IDataObject *pDataObject, /* [in] ptr to the data obj */
IDropSource* pDropSource, /* [in] ptr to the source obj */
DWORD dwOKEffect, /* [in] effects allowed by the source */
DWORD *pdwEffect) /* [out] ptr to effects of the source */
{
TrackerWindowInfo trackerInfo;
HWND hwndTrackWindow;
MSG msg;
TRACE("%p, %p, %#lx, %p.\n", pDataObject, pDropSource, dwOKEffect, pdwEffect);
if (!pDataObject || !pDropSource || !pdwEffect)
return E_INVALIDARG;
/*
* Setup the drag n drop tracking window.
*/
trackerInfo.dataObject = pDataObject;
trackerInfo.dropSource = pDropSource;
trackerInfo.dwOKEffect = dwOKEffect;
trackerInfo.pdwEffect = pdwEffect;
trackerInfo.trackingDone = FALSE;
trackerInfo.inTrackCall = FALSE;
trackerInfo.escPressed = FALSE;
trackerInfo.curTargetHWND = 0;
trackerInfo.curDragTarget = 0;
hwndTrackWindow = CreateWindowW(OLEDD_DRAGTRACKERCLASS, L"TrackerWindow",
WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0,
&trackerInfo);
if (hwndTrackWindow)
{
/*
* Capture the mouse input
*/
SetCapture(hwndTrackWindow);
msg.message = 0;
/*
* Pump messages. All mouse input should go to the capture window.
*/
while (!trackerInfo.trackingDone && GetMessageW(&msg, 0, 0, 0) )
{
trackerInfo.curMousePos.x = msg.pt.x;
trackerInfo.curMousePos.y = msg.pt.y;
trackerInfo.dwKeyState = OLEDD_GetButtonState();
if ( (msg.message >= WM_KEYFIRST) &&
(msg.message <= WM_KEYLAST) )
{
/*
* When keyboard messages are sent to windows on this thread, we
* want to ignore notify the drop source that the state changed.
* in the case of the Escape key, we also notify the drop source
* we give it a special meaning.
*/
if ( (msg.message==WM_KEYDOWN) &&
(msg.wParam==VK_ESCAPE) )
{
trackerInfo.escPressed = TRUE;
}
/*
* Notify the drop source.
*/
OLEDD_TrackStateChange(&trackerInfo);
}
else
{
/*
* Dispatch the messages only when it's not a keyboard message.
*/
DispatchMessageW(&msg);
}
}
/* re-post the quit message to outer message loop */
if (msg.message == WM_QUIT)
PostQuitMessage(msg.wParam);
/*
* Destroy the temporary window.
*/
DestroyWindow(hwndTrackWindow);
return trackerInfo.returnValue;
}
return E_FAIL;
}
/***********************************************************************
* OleQueryLinkFromData [OLE32.@]
*/
HRESULT WINAPI OleQueryLinkFromData(
IDataObject* pSrcDataObject)
{
FIXME("(%p),stub!\n", pSrcDataObject);
return S_FALSE;
}
/***********************************************************************
* OleRegGetMiscStatus [OLE32.@]
*/
HRESULT WINAPI OleRegGetMiscStatus(
REFCLSID clsid,
DWORD dwAspect,
DWORD* pdwStatus)
{
WCHAR keyName[16];
HKEY miscStatusKey;
HKEY aspectKey;
LONG result;
HRESULT hr;
TRACE("%s, %ld, %p.\n", debugstr_guid(clsid), dwAspect, pdwStatus);
if (!pdwStatus) return E_INVALIDARG;
*pdwStatus = 0;
if (actctx_get_miscstatus(clsid, dwAspect, pdwStatus)) return S_OK;
hr = COM_OpenKeyForCLSID(clsid, L"MiscStatus", KEY_READ, &miscStatusKey);
if (FAILED(hr))
/* missing key is not a failure */
return hr == REGDB_E_KEYMISSING ? S_OK : hr;
OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
/*
* Open the key specific to the requested aspect.
*/
swprintf(keyName, ARRAY_SIZE(keyName), L"%d", dwAspect);
result = open_classes_key(miscStatusKey, keyName, KEY_READ, &aspectKey);
if (result == ERROR_SUCCESS)
{
OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
RegCloseKey(aspectKey);
}
RegCloseKey(miscStatusKey);
return S_OK;
}
static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum);
typedef struct
{
IEnumOLEVERB IEnumOLEVERB_iface;
LONG ref;
HKEY hkeyVerb;
ULONG index;
} EnumOLEVERB;
static inline EnumOLEVERB *impl_from_IEnumOLEVERB(IEnumOLEVERB *iface)
{
return CONTAINING_RECORD(iface, EnumOLEVERB, IEnumOLEVERB_iface);
}
static HRESULT WINAPI EnumOLEVERB_QueryInterface(
IEnumOLEVERB *iface, REFIID riid, void **ppv)
{
TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
if (IsEqualIID(riid, &IID_IUnknown) ||
IsEqualIID(riid, &IID_IEnumOLEVERB))
{
IEnumOLEVERB_AddRef(iface);
*ppv = iface;
return S_OK;
}
return E_NOINTERFACE;
}
static ULONG WINAPI EnumOLEVERB_AddRef(
IEnumOLEVERB *iface)
{
EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
TRACE("()\n");
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI EnumOLEVERB_Release(
IEnumOLEVERB *iface)
{
EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
LONG refs = InterlockedDecrement(&This->ref);
TRACE("()\n");
if (!refs)
{
RegCloseKey(This->hkeyVerb);
HeapFree(GetProcessHeap(), 0, This);
}
return refs;
}
static HRESULT WINAPI EnumOLEVERB_Next(
IEnumOLEVERB *iface, ULONG celt, LPOLEVERB rgelt,
ULONG *pceltFetched)
{
EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
HRESULT hr = S_OK;
TRACE("%p, %lu, %p, %p.\n", iface, celt, rgelt, pceltFetched);
if (pceltFetched)
*pceltFetched = 0;
for (; celt; celt--, rgelt++)
{
WCHAR wszSubKey[20];
LONG cbData;
LPWSTR pwszOLEVERB;
LPWSTR pwszMenuFlags;
LPWSTR pwszAttribs;
LONG res = RegEnumKeyW(This->hkeyVerb, This->index, wszSubKey, ARRAY_SIZE(wszSubKey));
if (res == ERROR_NO_MORE_ITEMS)
{
hr = S_FALSE;
break;
}
else if (res != ERROR_SUCCESS)
{
ERR("RegEnumKeyW failed with error %ld\n", res);
hr = REGDB_E_READREGDB;
break;
}
res = RegQueryValueW(This->hkeyVerb, wszSubKey, NULL, &cbData);
if (res != ERROR_SUCCESS)
{
ERR("RegQueryValueW failed with error %ld\n", res);
hr = REGDB_E_READREGDB;
break;
}
pwszOLEVERB = CoTaskMemAlloc(cbData);
if (!pwszOLEVERB)
{
hr = E_OUTOFMEMORY;
break;
}
res = RegQueryValueW(This->hkeyVerb, wszSubKey, pwszOLEVERB, &cbData);
if (res != ERROR_SUCCESS)
{
ERR("RegQueryValueW failed with error %ld\n", res);
hr = REGDB_E_READREGDB;
CoTaskMemFree(pwszOLEVERB);
break;
}
TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB));
pwszMenuFlags = wcschr(pwszOLEVERB, ',');
if (!pwszMenuFlags)
{
hr = OLEOBJ_E_INVALIDVERB;
CoTaskMemFree(pwszOLEVERB);
break;
}
/* nul terminate the name string and advance to first character */
*pwszMenuFlags = '\0';
pwszMenuFlags++;
pwszAttribs = wcschr(pwszMenuFlags, ',');
if (!pwszAttribs)
{
hr = OLEOBJ_E_INVALIDVERB;
CoTaskMemFree(pwszOLEVERB);
break;
}
/* nul terminate the menu string and advance to first character */