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);
Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- include/winerror.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/include/winerror.h b/include/winerror.h index 377c61e724b..f412989a6a4 100644 --- a/include/winerror.h +++ b/include/winerror.h @@ -3040,6 +3040,21 @@ static inline HRESULT HRESULT_FROM_WIN32(unsigned int x) #define CO_E_DECODEFAILED _HRESULT_TYPEDEF_(0x8004021A) #define CO_E_ACNOTINITIALIZED _HRESULT_TYPEDEF_(0x8004021B)
+#define CONTEXT_S_FIRST _HRESULT_TYPEDEF_(0x0004e000) +#define CONTEXT_S_LAST _HRESULT_TYPEDEF_(0x0004e02f) +#define CONTEXT_E_FIRST _HRESULT_TYPEDEF_(0x8004e000) +#define CONTEXT_E_ABORTED _HRESULT_TYPEDEF_(0x8004e002) +#define CONTEXT_E_ABORTING _HRESULT_TYPEDEF_(0x8004e003) +#define CONTEXT_E_NOCONTEXT _HRESULT_TYPEDEF_(0x8004e004) +#define CONTEXT_E_WOULD_DEADLOCK _HRESULT_TYPEDEF_(0x8004e005) +#define CONTEXT_E_SYNCH_TIMEOUT _HRESULT_TYPEDEF_(0x8004e006) +#define CONTEXT_E_OLDREF _HRESULT_TYPEDEF_(0x8004e007) +#define CONTEXT_E_ROLENOTFOUND _HRESULT_TYPEDEF_(0x8004e00c) +#define CONTEXT_E_TMNOTAVAILABLE _HRESULT_TYPEDEF_(0x8004e00f) +#define CONTEXT_E_NOJIT _HRESULT_TYPEDEF_(0x8004e026) +#define CONTEXT_E_NOTRANSACTION _HRESULT_TYPEDEF_(0x8004e027) +#define CONTEXT_E_LAST _HRESULT_TYPEDEF_(0x8004e02f) + /* Task Scheduler Service Error Codes */ #define SCHED_S_TASK_READY _HRESULT_TYPEDEF_(0x00041300) #define SCHED_S_TASK_RUNNING _HRESULT_TYPEDEF_(0x00041301)
Signed-off-by: Jactry Zeng jzeng@codeweavers.com --- dlls/comsvcs/comsvcs_private.h | 2 + dlls/comsvcs/property.c | 256 ++++++++++++++++++++++++++++++++- dlls/comsvcs/tests/property.c | 129 +++++++++++++++++ include/comsvcs.idl | 12 ++ 4 files changed, 397 insertions(+), 2 deletions(-)
diff --git a/dlls/comsvcs/comsvcs_private.h b/dlls/comsvcs/comsvcs_private.h index 0051fb95831..f969f9b3943 100644 --- a/dlls/comsvcs/comsvcs_private.h +++ b/dlls/comsvcs/comsvcs_private.h @@ -35,6 +35,7 @@ enum tid_t { NULL_tid, ISharedPropertyGroupManager_tid, + ISharedPropertyGroup_tid, LAST_tid };
@@ -42,6 +43,7 @@ static REFIID tid_ids[] = { &IID_NULL, &IID_ISharedPropertyGroupManager, + &IID_ISharedPropertyGroup, };
HRESULT get_typeinfo(enum tid_t tid, ITypeInfo **typeinfo); diff --git a/dlls/comsvcs/property.c b/dlls/comsvcs/property.c index 382089f87b2..0c0b3a04083 100644 --- a/dlls/comsvcs/property.c +++ b/dlls/comsvcs/property.c @@ -17,6 +17,7 @@ */
#include "comsvcs_private.h" +#include "wine/list.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(comsvcs); @@ -25,6 +26,18 @@ struct group_manager { ISharedPropertyGroupManager ISharedPropertyGroupManager_iface; LONG refcount; + struct list property_groups; + CRITICAL_SECTION cs; +}; + +struct property_group +{ + ISharedPropertyGroup ISharedPropertyGroup_iface; + LONG refcount; + struct group_manager *parent; + LONG isolation, release; + struct list entry; + BSTR name; };
static struct group_manager *group_manager = NULL; @@ -34,6 +47,169 @@ static inline struct group_manager *impl_from_ISharedPropertyGroupManager(IShare return CONTAINING_RECORD(iface, struct group_manager, ISharedPropertyGroupManager_iface); }
+static inline struct property_group *impl_from_ISharedPropertyGroup(ISharedPropertyGroup *iface) +{ + return CONTAINING_RECORD(iface, struct property_group, ISharedPropertyGroup_iface); +} + +static HRESULT WINAPI property_group_QueryInterface(ISharedPropertyGroup *iface, REFIID riid, void **out) +{ + struct property_group *group = impl_from_ISharedPropertyGroup(iface); + + TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out); + + if (IsEqualGUID(riid, &IID_IUnknown) + || IsEqualGUID(riid, &IID_IDispatch) + || IsEqualGUID(riid, &IID_ISharedPropertyGroup)) + { + *out = &group->ISharedPropertyGroup_iface; + IUnknown_AddRef((IUnknown *)*out); + return S_OK; + } + + WARN("%s not implemented.\n", debugstr_guid(riid)); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI property_group_AddRef(ISharedPropertyGroup *iface) +{ + struct property_group *group = impl_from_ISharedPropertyGroup(iface); + ULONG refcount = InterlockedIncrement(&group->refcount); + + TRACE("%p increasing refcount to %u.\n", iface, refcount); + + return refcount; +} + +static ULONG WINAPI property_group_Release(ISharedPropertyGroup *iface) +{ + struct property_group *group = impl_from_ISharedPropertyGroup(iface); + ULONG refcount = InterlockedDecrement(&group->refcount); + + TRACE("%p decreasing refcount to %u.\n", iface, refcount); + + if (!refcount) + { + struct group_manager *manager = group->parent; + + SysFreeString(group->name); + + EnterCriticalSection(&manager->cs); + list_remove(&group->entry); + LeaveCriticalSection(&manager->cs); + + ISharedPropertyGroupManager_Release(&manager->ISharedPropertyGroupManager_iface); + free(group); + } + + return refcount; +} + +static HRESULT WINAPI property_group_GetTypeInfoCount(ISharedPropertyGroup *iface, UINT *info) +{ + TRACE("iface %p, info %p.\n", iface, info); + + if (!info) + return E_INVALIDARG; + + *info = 1; + return S_OK; +} + +static HRESULT WINAPI property_group_GetTypeInfo(ISharedPropertyGroup *iface, UINT index, + LCID lcid, ITypeInfo **info) +{ + TRACE("iface %p, index %u, lcid %u, info %p.\n", iface, index, lcid, info); + + if (index) + return DISP_E_BADINDEX; + + return get_typeinfo(ISharedPropertyGroup_tid, info); +} + +static HRESULT WINAPI property_group_GetIDsOfNames(ISharedPropertyGroup *iface, REFIID riid, LPOLESTR *names, + UINT count, LCID lcid, DISPID *dispid) +{ + 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); + + hr = get_typeinfo(ISharedPropertyGroup_tid, &typeinfo); + if (SUCCEEDED(hr)) + { + hr = ITypeInfo_GetIDsOfNames(typeinfo, names, count, dispid); + ITypeInfo_Release(typeinfo); + } + + return hr; +} + +static HRESULT WINAPI property_group_Invoke(ISharedPropertyGroup *iface, DISPID member, REFIID riid, + LCID lcid, WORD flags, DISPPARAMS *params, VARIANT *result, EXCEPINFO *except, UINT *argerr) +{ + 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); + + hr = get_typeinfo(ISharedPropertyGroup_tid, &typeinfo); + if (SUCCEEDED(hr)) + { + hr = ITypeInfo_Invoke(typeinfo, iface, member, flags, params, result, except, argerr); + ITypeInfo_Release(typeinfo); + } + + return hr; +} + +static HRESULT WINAPI property_group_CreatePropertyByPosition(ISharedPropertyGroup *iface, int index, + VARIANT_BOOL *exists, ISharedProperty **property) +{ + FIXME("iface %p, index %d, exisits %p, property %p: stub.\n", + iface, index, exists, property); + return E_NOTIMPL; +} + +static HRESULT WINAPI property_group_get_PropertyByPosition(ISharedPropertyGroup *iface, + int index, ISharedProperty **property) +{ + FIXME("iface %p, index %d, property %p: stub.\n", iface, index, property); + return E_NOTIMPL; +} + +static HRESULT WINAPI property_group_CreateProperty(ISharedPropertyGroup *iface, + BSTR name, VARIANT_BOOL *exists, ISharedProperty **property) +{ + FIXME("iface %p, name %s, exists %p, property %p: stub.\n", iface, debugstr_w(name), exists, property); + return E_NOTIMPL; +} + +static HRESULT WINAPI property_group_get_Property(ISharedPropertyGroup *iface, + BSTR name, ISharedProperty **property) +{ + FIXME("iface %p, name %s, property %p: stub.\n", iface, debugstr_w(name), property); + return E_NOTIMPL; +} + +static const ISharedPropertyGroupVtbl property_group_vtbl = +{ + property_group_QueryInterface, + property_group_AddRef, + property_group_Release, + property_group_GetTypeInfoCount, + property_group_GetTypeInfo, + property_group_GetIDsOfNames, + property_group_Invoke, + property_group_CreatePropertyByPosition, + property_group_get_PropertyByPosition, + property_group_CreateProperty, + property_group_get_Property, +}; + static HRESULT WINAPI group_manager_QueryInterface(ISharedPropertyGroupManager *iface, REFIID riid, void **out) { struct group_manager *manager = impl_from_ISharedPropertyGroupManager(iface); @@ -134,12 +310,85 @@ static HRESULT WINAPI group_manager_Invoke(ISharedPropertyGroupManager *iface, D return hr; }
+static struct property_group *find_propery_group(struct group_manager *manager, BSTR name) +{ + struct property_group *group; + + LIST_FOR_EACH_ENTRY(group, &group_manager->property_groups, struct property_group, entry) + { + if (!lstrcmpW(group->name, name)) + return group; + } + return NULL; +} + +struct property_group *create_property_group(struct group_manager* manager, BSTR name, LONG *isolation, + LONG *release, VARIANT_BOOL *exists) +{ + struct property_group *property_group; + + property_group = find_propery_group(manager, name); + if (property_group) + { + *exists = VARIANT_TRUE; + *isolation = property_group->isolation; + *release = property_group->release; + ISharedPropertyGroup_AddRef(&property_group->ISharedPropertyGroup_iface); + } + else + { + property_group = malloc(sizeof(*property_group)); + if (!property_group) + return NULL; + + property_group->ISharedPropertyGroup_iface.lpVtbl = &property_group_vtbl; + property_group->parent = manager; + property_group->isolation = *isolation; + property_group->release = *release; + property_group->refcount = (*release == Process) ? 2 : 1; + property_group->name = SysAllocString(name); + if (!property_group->name) + { + free(property_group); + return NULL; + } + list_add_tail(&manager->property_groups, &property_group->entry); + + *exists = VARIANT_FALSE; + ISharedPropertyGroupManager_AddRef(&property_group->parent->ISharedPropertyGroupManager_iface); + } + return property_group; +} + static HRESULT WINAPI group_manager_CreatePropertyGroup(ISharedPropertyGroupManager *iface, BSTR name, LONG *isolation, LONG *release, VARIANT_BOOL *exists, ISharedPropertyGroup **group) { - FIXME("iface %p, name %s, isolation %p, release %p, exists %p, group %p: stub.\n", + struct group_manager *manager = impl_from_ISharedPropertyGroupManager(iface); + struct property_group *property_group; + + TRACE("iface %p, name %s, isolation %p, release %p, exists %p, group %p.\n", iface, debugstr_w(name), isolation, release, exists, group); - return E_NOTIMPL; + + if (!name) + return E_POINTER; + + if (*isolation > LockMethod || *release > Process) + return E_INVALIDARG; + + *group = NULL; + if (*isolation == LockMethod && *release == Standard) + return CONTEXT_E_NOCONTEXT; + + EnterCriticalSection(&manager->cs); + property_group = create_property_group(manager, name, isolation, release, exists); + LeaveCriticalSection(&manager->cs); + + if (!property_group) + return E_OUTOFMEMORY; + + *group = &property_group->ISharedPropertyGroup_iface; + + return S_OK; }
static HRESULT WINAPI group_manager_get_Group(ISharedPropertyGroupManager *iface, BSTR name, @@ -186,9 +435,12 @@ HRESULT WINAPI group_manager_create(IClassFactory *iface, IUnknown *outer, REFII } manager->ISharedPropertyGroupManager_iface.lpVtbl = &group_manager_vtbl; manager->refcount = 1; + list_init(&manager->property_groups); + InitializeCriticalSection(&manager->cs);
if (InterlockedCompareExchangePointer((void **)&group_manager, manager, NULL)) { + DeleteCriticalSection(&manager->cs); free(manager); } } diff --git a/dlls/comsvcs/tests/property.c b/dlls/comsvcs/tests/property.c index 53dcfae8c8e..a8b3a7424fe 100644 --- a/dlls/comsvcs/tests/property.c +++ b/dlls/comsvcs/tests/property.c @@ -26,6 +26,15 @@
#include "wine/test.h"
+#define EXPECT_REF(obj,ref) _expect_ref((IUnknown*)obj, ref, __LINE__) +static void _expect_ref(IUnknown *obj, ULONG ref, int line) +{ + ULONG count; + IUnknown_AddRef(obj); + count = IUnknown_Release(obj); + ok_(__FILE__,line)(count == ref, "Unexpected refcount %d, expected %d.\n", count, ref); +} + static ULONG get_refcount(void *iface) { IUnknown *unknown = iface; @@ -166,11 +175,131 @@ static void test_interfaces(void) ISharedPropertyGroupManager_Release(manager); }
+static void test_property_group(void) +{ + ISharedPropertyGroup *group, *group1; + ISharedPropertyGroupManager *manager; + ULONG expected_refcount; + LONG isolation, release; + VARIANT_BOOL exists; + IDispatch *dispatch; + HRESULT hr; + BSTR name; + static const struct test_name_id test_name_ids[] = + { + {L"CreatePropertyByPosition", 0x1}, + {L"PropertyByPosition", 0x2}, + {L"CreateProperty", 0x3}, + {L"Property", 0x4}, + }; + + hr = CoCreateInstance(&CLSID_SharedPropertyGroupManager, NULL, CLSCTX_INPROC_SERVER, + &IID_ISharedPropertyGroupManager, (void **)&manager); + ok(hr == S_OK, "Got hr %#x.\n", hr); + + group = (void *)0xdeadbeef; + hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, NULL, &isolation, &release, &exists, &group); + ok(hr == E_POINTER, "Got hr %#x.\n", hr); + ok(group == (void *)0xdeadbeef, "Got unexpected pointer: %p.\n", group); + + name = SysAllocString(L"testgroupname"); + isolation = 2; + release = Standard; + hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + ok(group == (void *)0xdeadbeef, "Got unexpected pointer: %p.\n", group); + + /* Crash on Windows */ + if (0) + { + ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, NULL, &release, &exists, &group); + ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, NULL, &exists, &group); + ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, NULL, &group); + } + + isolation = LockSetGet; + release = 2; + hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group); + ok(hr == E_INVALIDARG, "Got hr %#x.\n", hr); + ok(group == (void *)0xdeadbeef, "Got unexpected pointer: %p.\n", group); + + isolation = LockMethod; + release = Standard; + hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group); + ok(hr == CONTEXT_E_NOCONTEXT, "Got hr %#x.\n", hr); + ok(!group, "Got unexpected pointer: %p.\n", group); + + isolation = LockSetGet; + release = Standard; + exists = VARIANT_TRUE; + expected_refcount = get_refcount(manager) + 1; + hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!exists, "Got unexpected value %d.\n", exists); + EXPECT_REF(group, 1); + + EXPECT_REF(manager, expected_refcount); + ISharedPropertyGroup_AddRef(group); + EXPECT_REF(manager, expected_refcount); + ISharedPropertyGroup_Release(group); + EXPECT_REF(manager, expected_refcount); + + /* Create an existing group. */ + isolation = LockMethod; + release = Process; + expected_refcount = get_refcount(manager); + hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group1); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(!!exists, "Got unexpected value %d.\n", exists); + ok(isolation == LockSetGet, "Got unexpected value %d.\n", isolation); + ok(release == Standard, "Got unexpected value %d.\n", release); + ok(group == group1, "Got unexpected pointer: %p.\n", group1); + EXPECT_REF(group, 2); + EXPECT_REF(manager, expected_refcount); + ISharedPropertyGroup_Release(group1); + EXPECT_REF(group, 1); + SysFreeString(name); + + /* Process release mode. */ + name = SysAllocString(L"testgroupname2"); + isolation = LockSetGet; + release = Process; + exists = VARIANT_TRUE; + expected_refcount = get_refcount(manager) + 1; + hr = ISharedPropertyGroupManager_CreatePropertyGroup(manager, name, &isolation, &release, &exists, &group1); + ok(hr == S_OK, "Got hr %#x.\n", hr); + ok(isolation == LockSetGet, "Got unexpected value %d.\n", isolation); + ok(release == Process, "Got unexpected value %d.\n", release); + ok(!exists, "Got unexpected value %d.\n", exists); + EXPECT_REF(manager, expected_refcount); + EXPECT_REF(group1, 2); + SysFreeString(name); + + expected_refcount = get_refcount(manager); + ISharedPropertyGroup_Release(group1); + EXPECT_REF(manager, expected_refcount); + expected_refcount = get_refcount(manager) - 1; + ISharedPropertyGroup_Release(group1); + EXPECT_REF(manager, expected_refcount); + + hr = ISharedPropertyGroup_QueryInterface(group, &IID_IDispatch, (void **)&dispatch); + ok(hr == S_OK, "Got hr %#x.\n", hr); + TEST_TYPEINFO(dispatch, test_name_ids, ARRAY_SIZE(test_name_ids), &IID_ISharedPropertyGroup); + IDispatch_Release(dispatch); + + expected_refcount = get_refcount(manager) - 1; + ISharedPropertyGroup_Release(group); + EXPECT_REF(manager, expected_refcount); + + ISharedPropertyGroupManager_Release(manager); +} + START_TEST(property) { CoInitialize(NULL);
test_interfaces(); + test_property_group();
CoUninitialize(); } diff --git a/include/comsvcs.idl b/include/comsvcs.idl index 902c78b05c8..8e64c2db73e 100644 --- a/include/comsvcs.idl +++ b/include/comsvcs.idl @@ -31,6 +31,18 @@ typedef LPOLESTR SRESID; typedef long TIMEINSECS; typedef DWORD_PTR TRANSID;
+typedef enum _LockModes +{ + LockSetGet = 0, + LockMethod = 1, +} LockModes; + +typedef enum _ReleaseModes +{ + Standard = 0, + Process = 1, +} ReleaseModes; + [ uuid(2a005c00-a5de-11cf-9e66-00aa00a3f464), version(1.0)