Signed-off-by: Jactry Zeng jzeng@codeweavers.com
--- v3: - Fix some leaks. - Test reference count of ITypeInfo. v2: No changes. --- dlls/comsvcs/Makefile.in | 2 +- dlls/comsvcs/comsvcs_private.h | 15 ++++++++ dlls/comsvcs/main.c | 68 ++++++++++++++++++++++++++++++++++ dlls/comsvcs/property.c | 45 ++++++++++++++++++---- dlls/comsvcs/tests/property.c | 59 +++++++++++++++++++++++++++++ 5 files changed, 180 insertions(+), 9 deletions(-)
diff --git a/dlls/comsvcs/Makefile.in b/dlls/comsvcs/Makefile.in index b4a4244bce..82a496ea9c 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 = -mno-cygwin
diff --git a/dlls/comsvcs/comsvcs_private.h b/dlls/comsvcs/comsvcs_private.h index 6d299d3a88..8a67bcffd8 100644 --- a/dlls/comsvcs/comsvcs_private.h +++ b/dlls/comsvcs/comsvcs_private.h @@ -33,6 +33,21 @@ #include "wine/heap.h" #include "wine/debug.h"
+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); + HRESULT WINAPI group_manager_create(IClassFactory *iface, IUnknown *outer, REFIID riid, void **out);
#endif diff --git a/dlls/comsvcs/main.c b/dlls/comsvcs/main.c index 1d3f7db174..7d00084f8a 100644 --- a/dlls/comsvcs/main.c +++ b/dlls/comsvcs/main.c @@ -361,6 +361,71 @@ static HRESULT WINAPI dispenser_manager_cf_CreateInstance(IClassFactory *iface, return ret; }
+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 hinst, DWORD reason, LPVOID lpv) { switch(reason) @@ -371,6 +436,9 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID lpv) COMSVCS_hInstance = hinst; DisableThreadLibraryCalls(hinst); break; + case DLL_PROCESS_DETACH: + release_typelib(); + break; } return TRUE; } diff --git a/dlls/comsvcs/property.c b/dlls/comsvcs/property.c index 3c9917c926..44e111fe71 100644 --- a/dlls/comsvcs/property.c +++ b/dlls/comsvcs/property.c @@ -75,31 +75,60 @@ 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, LONG *isolation, diff --git a/dlls/comsvcs/tests/property.c b/dlls/comsvcs/tests/property.c index adad7bd539..2cc7ff1d44 100644 --- a/dlls/comsvcs/tests/property.c +++ b/dlls/comsvcs/tests/property.c @@ -60,6 +60,57 @@ 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 +118,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 +157,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);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=77760
Your paranoid android.
=== debiant (32 bit report) ===
comsvcs: property.c:130: Test failed: Got hr 0x80040154. property.c:134: Test failed: Got hr 0x80040154. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040372d).
Report validation errors: comsvcs:property crashed (c0000005)
=== debiant (32 bit French report) ===
comsvcs: property.c:130: Test failed: Got hr 0x80040154. property.c:134: Test failed: Got hr 0x80040154. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040372d).
Report validation errors: comsvcs:property crashed (c0000005)
=== debiant (32 bit Japanese:Japan report) ===
comsvcs: property.c:130: Test failed: Got hr 0x80040154. property.c:134: Test failed: Got hr 0x80040154. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040372d).
Report validation errors: comsvcs:property crashed (c0000005)
=== debiant (32 bit Chinese:China report) ===
comsvcs: property.c:130: Test failed: Got hr 0x80040154. property.c:134: Test failed: Got hr 0x80040154. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040372d).
Report validation errors: comsvcs:property crashed (c0000005)
=== debiant (32 bit WoW report) ===
comsvcs: property.c:130: Test failed: Got hr 0x80040154. property.c:134: Test failed: Got hr 0x80040154. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040372d).
Report validation errors: comsvcs:property crashed (c0000005)
=== debiant (64 bit WoW report) ===
comsvcs: property.c:130: Test failed: Got hr 0x80040154. property.c:134: Test failed: Got hr 0x80040154. Unhandled exception: page fault on read access to 0x00000000 in 32-bit code (0x0040372d).
Report validation errors: comsvcs:property crashed (c0000005)