From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- configure.ac | 1 + dlls/coremessaging/Makefile.in | 4 +- dlls/coremessaging/classes.idl | 24 ++++ dlls/coremessaging/coremessaging.spec | 2 +- dlls/coremessaging/main.c | 141 ++++++++++++++++++++++- dlls/coremessaging/private.h | 79 +++++++++++++ dlls/coremessaging/tests/Makefile.in | 5 + dlls/coremessaging/tests/coremessaging.c | 90 +++++++++++++++ include/windows.system.idl | 2 + 9 files changed, 345 insertions(+), 3 deletions(-) create mode 100644 dlls/coremessaging/classes.idl create mode 100644 dlls/coremessaging/private.h create mode 100644 dlls/coremessaging/tests/Makefile.in create mode 100644 dlls/coremessaging/tests/coremessaging.c
diff --git a/configure.ac b/configure.ac index d1d07bc8f37..06da342bd4f 100644 --- a/configure.ac +++ b/configure.ac @@ -2495,6 +2495,7 @@ WINE_CONFIG_MAKEFILE(dlls/concrt140) WINE_CONFIG_MAKEFILE(dlls/concrt140/tests) WINE_CONFIG_MAKEFILE(dlls/connect) WINE_CONFIG_MAKEFILE(dlls/coremessaging) +WINE_CONFIG_MAKEFILE(dlls/coremessaging/tests) WINE_CONFIG_MAKEFILE(dlls/credui) WINE_CONFIG_MAKEFILE(dlls/credui/tests) WINE_CONFIG_MAKEFILE(dlls/crtdll) diff --git a/dlls/coremessaging/Makefile.in b/dlls/coremessaging/Makefile.in index 0aa0fc43a9b..049d9d7e0a3 100644 --- a/dlls/coremessaging/Makefile.in +++ b/dlls/coremessaging/Makefile.in @@ -1,4 +1,6 @@ -MODULE = coremessaging.dll +MODULE = coremessaging.dll +IMPORTS = combase
SOURCES = \ + classes.idl \ main.c diff --git a/dlls/coremessaging/classes.idl b/dlls/coremessaging/classes.idl new file mode 100644 index 00000000000..a7509d2a658 --- /dev/null +++ b/dlls/coremessaging/classes.idl @@ -0,0 +1,24 @@ +/* + * Runtime Classes for coremessaging.dll + * + * Copyright (C) 2025 Mohamad Al-Jaf + * + * 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 + */ + +#pragma makedep register + +#define _CORE_MESSAGING +#include "windows.system.idl" diff --git a/dlls/coremessaging/coremessaging.spec b/dlls/coremessaging/coremessaging.spec index 58f2be2dc8e..fb98c802077 100644 --- a/dlls/coremessaging/coremessaging.spec +++ b/dlls/coremessaging/coremessaging.spec @@ -18,7 +18,7 @@ @ stdcall CreateDispatcherQueueController(long long long ptr) @ stub CreateDispatcherQueueForCurrentThread @ stdcall -private DllCanUnloadNow() -@ stub DllGetActivationFactory +@ stdcall -private DllGetActivationFactory(ptr ptr) @ stub DllGetClassObject @ stub GetDispatcherQueueForCurrentThread @ stub MsgBlobCreateShared diff --git a/dlls/coremessaging/main.c b/dlls/coremessaging/main.c index 4944f28a49a..5bb4a99ee57 100644 --- a/dlls/coremessaging/main.c +++ b/dlls/coremessaging/main.c @@ -17,11 +17,150 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#include "initguid.h" +#include "private.h" #include "dispatcherqueue.h" -#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(messaging);
+struct dispatcher_queue_controller_statics +{ + IActivationFactory IActivationFactory_iface; + IDispatcherQueueControllerStatics IDispatcherQueueControllerStatics_iface; + LONG ref; +}; + +static inline struct dispatcher_queue_controller_statics *impl_from_IActivationFactory( IActivationFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct dispatcher_queue_controller_statics, IActivationFactory_iface ); +} + +static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) +{ + struct dispatcher_queue_controller_statics *impl = impl_from_IActivationFactory( iface ); + + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IActivationFactory )) + { + *out = &impl->IActivationFactory_iface; + IInspectable_AddRef( *out ); + return S_OK; + } + + if (IsEqualGUID( iid, &IID_IDispatcherQueueControllerStatics )) + { + *out = &impl->IDispatcherQueueControllerStatics_iface; + IInspectable_AddRef( *out ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI factory_AddRef( IActivationFactory *iface ) +{ + struct dispatcher_queue_controller_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p increasing ref to %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI factory_Release( IActivationFactory *iface ) +{ + struct dispatcher_queue_controller_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p decreasing ref to %lu.\n", iface, ref ); + return ref; +} + +static HRESULT WINAPI factory_GetIids( IActivationFactory *iface, ULONG *iid_count, IID **iids ) +{ + FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); + return E_NOTIMPL; +} + +static HRESULT WINAPI factory_GetRuntimeClassName( IActivationFactory *iface, HSTRING *class_name ) +{ + FIXME( "iface %p, class_name %p stub!\n", iface, class_name ); + return E_NOTIMPL; +} + +static HRESULT WINAPI factory_GetTrustLevel( IActivationFactory *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI factory_ActivateInstance( IActivationFactory *iface, IInspectable **instance ) +{ + FIXME( "iface %p, instance %p stub!\n", iface, instance ); + return E_NOTIMPL; +} + +static const struct IActivationFactoryVtbl factory_vtbl = +{ + factory_QueryInterface, + factory_AddRef, + factory_Release, + /* IInspectable methods */ + factory_GetIids, + factory_GetRuntimeClassName, + factory_GetTrustLevel, + /* IActivationFactory methods */ + factory_ActivateInstance, +}; + +DEFINE_IINSPECTABLE( dispatcher_queue_controller_statics, IDispatcherQueueControllerStatics, struct dispatcher_queue_controller_statics, IActivationFactory_iface ) + +static HRESULT WINAPI dispatcher_queue_controller_statics_CreateOnDedicatedThread( IDispatcherQueueControllerStatics *iface, IDispatcherQueueController **result ) +{ + FIXME( "iface %p, result %p stub!\n", iface, result ); + return E_NOTIMPL; +} + +static const struct IDispatcherQueueControllerStaticsVtbl dispatcher_queue_controller_statics_vtbl = +{ + dispatcher_queue_controller_statics_QueryInterface, + dispatcher_queue_controller_statics_AddRef, + dispatcher_queue_controller_statics_Release, + /* IInspectable methods */ + dispatcher_queue_controller_statics_GetIids, + dispatcher_queue_controller_statics_GetRuntimeClassName, + dispatcher_queue_controller_statics_GetTrustLevel, + /* IDispatcherQueueControllerStatics methods */ + dispatcher_queue_controller_statics_CreateOnDedicatedThread, +}; + +static struct dispatcher_queue_controller_statics dispatcher_queue_controller_statics = +{ + {&factory_vtbl}, + {&dispatcher_queue_controller_statics_vtbl}, + 1, +}; + +static IActivationFactory *dispatcher_queue_controller_factory = &dispatcher_queue_controller_statics.IActivationFactory_iface; + +HRESULT WINAPI DllGetActivationFactory( HSTRING classid, IActivationFactory **factory ) +{ + const WCHAR *name = WindowsGetStringRawBuffer( classid, NULL ); + + TRACE( "classid %s, factory %p.\n", debugstr_hstring( classid ), factory ); + + *factory = NULL; + + if (!wcscmp( name, RuntimeClass_Windows_System_DispatcherQueueController )) + IActivationFactory_QueryInterface( dispatcher_queue_controller_factory, &IID_IActivationFactory, (void **)factory ); + + if (*factory) return S_OK; + return CLASS_E_CLASSNOTAVAILABLE; +} + HRESULT WINAPI CreateDispatcherQueueController( DispatcherQueueOptions options, PDISPATCHERQUEUECONTROLLER *queue_controller ) { FIXME( "options.dwSize = %lu, options.threadType = %d, options.apartmentType = %d, queue_controller %p stub!\n", diff --git a/dlls/coremessaging/private.h b/dlls/coremessaging/private.h new file mode 100644 index 00000000000..09567dedc1c --- /dev/null +++ b/dlls/coremessaging/private.h @@ -0,0 +1,79 @@ +/* WinRT coremessaging.dll Implementation + * + * Copyright (C) 2025 Mohamad Al-Jaf + * + * 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 + */ + +#ifndef __WINE_CORE_MESSAGING_PRIVATE_H +#define __WINE_CORE_MESSAGING_PRIVATE_H + +#include <stdarg.h> +#include <stddef.h> + +#define COBJMACROS +#include "windef.h" +#include "winbase.h" +#include "winstring.h" + +#include "activation.h" +#include "roapi.h" + +#include "wine/debug.h" + +#define WIDL_using_Windows_Foundation +#include "windows.foundation.h" +#define WIDL_using_Windows_System +#include "windows.system.h" + +#define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \ + static inline impl_type *impl_from( iface_type *iface ) \ + { \ + return CONTAINING_RECORD( iface, impl_type, iface_mem ); \ + } \ + static HRESULT WINAPI pfx##_QueryInterface( iface_type *iface, REFIID iid, void **out ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_QueryInterface( (IInspectable *)(expr), iid, out ); \ + } \ + static ULONG WINAPI pfx##_AddRef( iface_type *iface ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_AddRef( (IInspectable *)(expr) ); \ + } \ + static ULONG WINAPI pfx##_Release( iface_type *iface ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_Release( (IInspectable *)(expr) ); \ + } \ + static HRESULT WINAPI pfx##_GetIids( iface_type *iface, ULONG *iid_count, IID **iids ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_GetIids( (IInspectable *)(expr), iid_count, iids ); \ + } \ + static HRESULT WINAPI pfx##_GetRuntimeClassName( iface_type *iface, HSTRING *class_name ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_GetRuntimeClassName( (IInspectable *)(expr), class_name ); \ + } \ + static HRESULT WINAPI pfx##_GetTrustLevel( iface_type *iface, TrustLevel *trust_level ) \ + { \ + impl_type *impl = impl_from( iface ); \ + return IInspectable_GetTrustLevel( (IInspectable *)(expr), trust_level ); \ + } +#define DEFINE_IINSPECTABLE( pfx, iface_type, impl_type, base_iface ) \ + DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from_##iface_type, iface_type##_iface, &impl->base_iface ) + +#endif diff --git a/dlls/coremessaging/tests/Makefile.in b/dlls/coremessaging/tests/Makefile.in new file mode 100644 index 00000000000..b048cbe204e --- /dev/null +++ b/dlls/coremessaging/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = coremessaging.dll +IMPORTS = combase + +SOURCES = \ + coremessaging.c diff --git a/dlls/coremessaging/tests/coremessaging.c b/dlls/coremessaging/tests/coremessaging.c new file mode 100644 index 00000000000..83d00b6261f --- /dev/null +++ b/dlls/coremessaging/tests/coremessaging.c @@ -0,0 +1,90 @@ +/* + * Copyright (C) 2025 Mohamad Al-Jaf + * + * 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 + */ +#define COBJMACROS +#include "initguid.h" +#include <stdarg.h> + +#include "windef.h" +#include "winbase.h" +#include "winstring.h" + +#include "roapi.h" + +#define WIDL_using_Windows_Foundation +#include "windows.foundation.h" +#define WIDL_using_Windows_System +#include "windows.system.h" + +#include "wine/test.h" + +#define check_interface( obj, iid ) check_interface_( __LINE__, obj, iid ) +static void check_interface_( unsigned int line, void *obj, const IID *iid ) +{ + IUnknown *iface = obj; + IUnknown *unk; + HRESULT hr; + + hr = IUnknown_QueryInterface( iface, iid, (void **)&unk ); + ok_(__FILE__, line)( hr == S_OK, "got hr %#lx.\n", hr ); + IUnknown_Release( unk ); +} + +static void test_DispatcherQueueController_Statics(void) +{ + static const WCHAR *dispatcher_queue_controller_statics_name = L"Windows.System.DispatcherQueueController"; + IDispatcherQueueControllerStatics *dispatcher_queue_controller_statics = (void *)0xdeadbeef; + IActivationFactory *factory = (void *)0xdeadbeef; + HSTRING str = NULL; + HRESULT hr; + LONG ref; + + hr = WindowsCreateString( dispatcher_queue_controller_statics_name, wcslen( dispatcher_queue_controller_statics_name ), &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory ); + WindowsDeleteString( str ); + ok( hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG), "got hr %#lx.\n", hr ); + if (hr == REGDB_E_CLASSNOTREG) + { + win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( dispatcher_queue_controller_statics_name ) ); + return; + } + + check_interface( factory, &IID_IUnknown ); + check_interface( factory, &IID_IInspectable ); + check_interface( factory, &IID_IAgileObject ); + + hr = IActivationFactory_QueryInterface( factory, &IID_IDispatcherQueueControllerStatics, (void **)&dispatcher_queue_controller_statics ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + + ref = IDispatcherQueueControllerStatics_Release( dispatcher_queue_controller_statics ); + ok( ref == 2, "got ref %ld.\n", ref ); + ref = IActivationFactory_Release( factory ); + ok( ref == 1, "got ref %ld.\n", ref ); +} + +START_TEST(coremessaging) +{ + HRESULT hr; + + hr = RoInitialize( RO_INIT_MULTITHREADED ); + ok( hr == S_OK, "RoInitialize failed, hr %#lx\n", hr ); + + test_DispatcherQueueController_Statics(); + + RoUninitialize(); +} diff --git a/include/windows.system.idl b/include/windows.system.idl index 3a349edd4f8..152d4b6d901 100644 --- a/include/windows.system.idl +++ b/include/windows.system.idl @@ -462,6 +462,7 @@ namespace Windows.System [default] interface Windows.System.IDispatcherQueueTimer; }
+#ifndef _CORE_MESSAGING [ contract(Windows.Foundation.UniversalApiContract, 1.0), marshaling_behavior(agile), @@ -472,6 +473,7 @@ namespace Windows.System { [default] interface Windows.System.IUser; } +#endif
[ contract(Windows.Foundation.UniversalApiContract, 1.0),