-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path221205.mypatch
312 lines (292 loc) · 9.67 KB
/
221205.mypatch
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
From: Jactry Zeng <[email protected]>
Subject: [PATCH 1/3] comsvcs: Add IDispatch support for ISharedPropertyGroupManager.
Message-Id: <[email protected]>
Date: Thu, 2 Dec 2021 02:38:45 -0600
Signed-off-by: Jactry Zeng <[email protected]>
---
dlls/comsvcs/Makefile.in | 2 +-
dlls/comsvcs/comsvcs_private.h | 15 +++++++
dlls/comsvcs/main.c | 82 ++++++++++++++++++++++++++++++++++
dlls/comsvcs/property.c | 46 +++++++++++++++----
dlls/comsvcs/tests/property.c | 61 +++++++++++++++++++++++++
5 files changed, 197 insertions(+), 9 deletions(-)
diff --git a/dlls/comsvcs/Makefile.in b/dlls/comsvcs/Makefile.in
index 22090938b52..5ad3d085b90 100644
--- a/dlls/comsvcs/Makefile.in
+++ b/dlls/comsvcs/Makefile.in
@@ -1,6 +1,6 @@
MODULE = comsvcs.dll
IMPORTLIB = comsvcs
-IMPORTS = ole32 uuid
+IMPORTS = ole32 oleaut32 uuid
EXTRADLLFLAGS = -Wb,--prefer-native
diff --git a/dlls/comsvcs/comsvcs_private.h b/dlls/comsvcs/comsvcs_private.h
index c09c2174e0e..0051fb95831 100644
--- a/dlls/comsvcs/comsvcs_private.h
+++ b/dlls/comsvcs/comsvcs_private.h
@@ -31,4 +31,19 @@
HRESULT WINAPI group_manager_create(IClassFactory *iface, IUnknown *outer, REFIID riid, void **out);
+enum tid_t
+{
+ NULL_tid,
+ ISharedPropertyGroupManager_tid,
+ LAST_tid
+};
+
+static REFIID tid_ids[] =
+{
+ &IID_NULL,
+ &IID_ISharedPropertyGroupManager,
+};
+
+HRESULT get_typeinfo(enum tid_t tid, ITypeInfo **typeinfo);
+
#endif
diff --git a/dlls/comsvcs/main.c b/dlls/comsvcs/main.c
index 797e2db97db..7903d2c2e07 100644
--- a/dlls/comsvcs/main.c
+++ b/dlls/comsvcs/main.c
@@ -26,6 +26,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(comsvcs);
+HINSTANCE dll_instance = NULL;
+
typedef struct dispensermanager
{
IDispenserManager IDispenserManager_iface;
@@ -1024,3 +1026,83 @@ HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
return CLASS_E_CLASSNOTAVAILABLE;
}
+
+static ITypeLib *typelib;
+static ITypeInfo *typeinfos[LAST_tid];
+
+static HRESULT load_typelib(void)
+{
+ ITypeLib *tl;
+ HRESULT hr;
+
+ if (typelib)
+ return S_OK;
+
+ hr = LoadRegTypeLib(&LIBID_COMSVCSLib, 1, 0, LOCALE_SYSTEM_DEFAULT, &tl);
+ if (FAILED(hr))
+ {
+ ERR("LoadRegTypeLib failed: %#x.\n", hr);
+ return hr;
+ }
+
+ if (InterlockedCompareExchangePointer((void **)&typelib, tl, NULL))
+ ITypeLib_Release(tl);
+ return hr;
+}
+
+HRESULT get_typeinfo(enum tid_t tid, ITypeInfo **typeinfo)
+{
+ HRESULT hr;
+
+ hr = load_typelib();
+ if (FAILED(hr))
+ return hr;
+
+ if (!typeinfos[tid])
+ {
+ ITypeInfo *ti;
+
+ hr = ITypeLib_GetTypeInfoOfGuid(typelib, tid_ids[tid], &ti);
+ if (FAILED(hr))
+ {
+ ERR("GetTypeInfoOfGuid(%s) failed: %#x.\n", debugstr_guid(tid_ids[tid]), hr);
+ return hr;
+ }
+
+ if (InterlockedCompareExchangePointer((void **)(typeinfos + tid), ti, NULL))
+ ITypeInfo_Release(ti);
+ }
+
+ *typeinfo = typeinfos[tid];
+ ITypeInfo_AddRef(typeinfos[tid]);
+ return S_OK;
+}
+
+static void release_typelib(void)
+{
+ unsigned i;
+
+ if (!typelib)
+ return;
+
+ for (i = 0; i < ARRAY_SIZE(typeinfos); i++)
+ if (typeinfos[i])
+ ITypeInfo_Release(typeinfos[i]);
+
+ ITypeLib_Release(typelib);
+}
+
+BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
+{
+ switch (reason)
+ {
+ case DLL_PROCESS_ATTACH:
+ dll_instance = instance;
+ DisableThreadLibraryCalls(instance);
+ break;
+ case DLL_PROCESS_DETACH:
+ release_typelib();
+ break;
+ }
+ return TRUE;
+}
diff --git a/dlls/comsvcs/property.c b/dlls/comsvcs/property.c
index 4dc6e1d9a46..382089f87b2 100644
--- a/dlls/comsvcs/property.c
+++ b/dlls/comsvcs/property.c
@@ -76,32 +76,62 @@ static ULONG WINAPI group_manager_Release(ISharedPropertyGroupManager *iface)
static HRESULT WINAPI group_manager_GetTypeInfoCount(ISharedPropertyGroupManager *iface, UINT *info)
{
- FIXME("iface %p, info %p: stub.\n", iface, info);
- return E_NOTIMPL;
+ TRACE("iface %p, info %p.\n", iface, info);
+
+ if (!info)
+ return E_INVALIDARG;
+
+ *info = 1;
+ return S_OK;
}
static HRESULT WINAPI group_manager_GetTypeInfo(ISharedPropertyGroupManager *iface, UINT index, LCID lcid,
ITypeInfo **info)
{
- FIXME("iface %p, index %u, lcid %u, info %p: stub.\n", iface, index, lcid, info);
- return E_NOTIMPL;
+ TRACE("iface %p, index %u, lcid %u, info %p.\n", iface, index, lcid, info);
+
+ if (index)
+ return DISP_E_BADINDEX;
+
+ return get_typeinfo(ISharedPropertyGroupManager_tid, info);
}
static HRESULT WINAPI group_manager_GetIDsOfNames(ISharedPropertyGroupManager *iface, REFIID riid,
LPOLESTR *names, UINT count, LCID lcid, DISPID *dispid)
{
- FIXME("iface %p, riid %s, names %p, count %u, lcid %u, dispid %p: stub.\n",
+ ITypeInfo *typeinfo;
+ HRESULT hr;
+
+ TRACE("iface %p, riid %s, names %p, count %u, lcid %u, dispid %p.\n",
iface, debugstr_guid(riid), names, count, lcid, dispid);
- return E_NOTIMPL;
+ hr = get_typeinfo(ISharedPropertyGroupManager_tid, &typeinfo);
+ if (SUCCEEDED(hr))
+ {
+ hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, dispid);
+ ITypeInfo_Release(typeinfo);
+ }
+
+ return hr;
}
static HRESULT WINAPI group_manager_Invoke(ISharedPropertyGroupManager *iface, DISPID member, REFIID riid,
LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *except, UINT *argerr)
{
- FIXME("iface %p, member %u, riid %s, lcid %u, flags %x, params %p, result %p, except %p, argerr %p: stub.\n",
+ ITypeInfo *typeinfo;
+ HRESULT hr;
+
+ TRACE("iface %p, member %u, riid %s, lcid %u, flags %x, params %p, result %p, except %p, argerr %p.\n",
iface, member, debugstr_guid(riid), lcid, flags, params, result, except, argerr);
- return E_NOTIMPL;
+
+ hr = get_typeinfo(ISharedPropertyGroupManager_tid, &typeinfo);
+ if (SUCCEEDED(hr))
+ {
+ hr = ITypeInfo_Invoke(typeinfo, iface, member, flags, params, result, except, argerr);
+ ITypeInfo_Release(typeinfo);
+ }
+
+ return hr;
}
static HRESULT WINAPI group_manager_CreatePropertyGroup(ISharedPropertyGroupManager *iface, BSTR name,
diff --git a/dlls/comsvcs/tests/property.c b/dlls/comsvcs/tests/property.c
index 7be62987507..53dcfae8c8e 100644
--- a/dlls/comsvcs/tests/property.c
+++ b/dlls/comsvcs/tests/property.c
@@ -60,6 +60,59 @@ static const IUnknownVtbl outer_vtbl =
static IUnknown test_outer = {&outer_vtbl};
+struct test_name_id
+{
+ const WCHAR *name;
+ DISPID id;
+};
+
+#define TEST_TYPEINFO(dispatch,test_name_ids,id_count,riid) \
+ _test_typeinfo(dispatch, test_name_ids, id_count, riid, __LINE__)
+static void _test_typeinfo(IDispatch *dispatch, const struct test_name_id *test_name_ids,
+ UINT id_count, REFIID riid, int line)
+{
+ static const LCID english = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT);
+ ITypeInfo *typeinfo;
+ TYPEATTR *typeattr;
+ ULONG refcount;
+ DISPID dispid;
+ UINT count;
+ BSTR names;
+ HRESULT hr;
+ int i;
+
+ hr = IDispatch_GetTypeInfoCount(dispatch, NULL);
+ ok_(__FILE__,line)(hr == E_INVALIDARG, "GetTypeInfoCount got hr %#x.\n", hr);
+
+ count = 0xdeadbeef;
+ hr = IDispatch_GetTypeInfoCount(dispatch, &count);
+ ok_(__FILE__,line)(hr == S_OK, "GetTypeInfoCount got hr %#x.\n", hr);
+ ok_(__FILE__,line)(count == 1, "Got unexpected count: %d.\n", count);
+
+ hr = IDispatch_GetTypeInfo(dispatch, 1, english, &typeinfo);
+ ok_(__FILE__,line)(hr == DISP_E_BADINDEX, "GetTypeInfo got hr %#x.\n", hr);
+
+ hr = IDispatch_GetTypeInfo(dispatch, 0, english, &typeinfo);
+ ok_(__FILE__,line)(hr == S_OK, "GetTypeInfo failed %#x.\n", hr);
+ hr = ITypeInfo_GetTypeAttr(typeinfo, &typeattr);
+ ok_(__FILE__,line)(hr == S_OK, "GetTypeAttr got hr %#x.\n", hr);
+ ok_(__FILE__,line)(IsEqualGUID(&typeattr->guid, riid),
+ "Got unexpected type guid: %s.\n", wine_dbgstr_guid(&typeattr->guid));
+ refcount = get_refcount(typeinfo);
+ ok_(__FILE__,line)(refcount == 2, "Got refcount: %u.\n", refcount);
+ ITypeInfo_Release(typeinfo);
+
+ for (i = 0; i < id_count; i++)
+ {
+ names = SysAllocString(test_name_ids[i].name);
+ dispid = 0xdeadbeef;
+ hr = IDispatch_GetIDsOfNames(dispatch, &IID_NULL, &names, 1, english, &dispid);
+ SysFreeString(names);
+ ok_(__FILE__,line)(hr == S_OK, "tests[%d] got hr %#x.\n", i, hr);
+ ok_(__FILE__,line)(dispid == test_name_ids[i].id, "tests[%d] got wrong dispid %x.\n", i, dispid);
+ }
+}
+
static void test_interfaces(void)
{
ISharedPropertyGroupManager *manager, *manager1;
@@ -67,6 +120,12 @@ static void test_interfaces(void)
IDispatch *dispatch;
IUnknown *unk;
HRESULT hr;
+ static const struct test_name_id test_name_ids[] =
+ {
+ {L"CreatePropertyGroup", 0x1},
+ {L"Group", 0x2},
+ {L"_NewEnum", DISPID_NEWENUM},
+ };
hr = CoCreateInstance(&CLSID_SharedPropertyGroupManager, &test_outer, CLSCTX_INPROC_SERVER,
&IID_ISharedPropertyGroupManager, (void **)&manager);
@@ -100,6 +159,8 @@ static void test_interfaces(void)
refcount = get_refcount(manager);
ok(refcount == expected_refcount, "Got refcount: %u, expected %u.\n", refcount, expected_refcount);
+ TEST_TYPEINFO(dispatch, test_name_ids, ARRAY_SIZE(test_name_ids), &IID_ISharedPropertyGroupManager);
+
IDispatch_Release(dispatch);
IUnknown_Release(unk);
ISharedPropertyGroupManager_Release(manager);
--
2.33.0