Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- 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);