From abc0c3c129c3ba956463ad4e1522abdc91db4d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Thu, 23 Nov 2023 12:02:50 +0100 Subject: [PATCH] twinapi.appcore: Stub Windows.System.UserProfile.AdvertisingManager factory. --- dlls/twinapi.appcore/Makefile.in | 1 + dlls/twinapi.appcore/advertising_manager.c | 143 +++++++++++++++++++++ dlls/twinapi.appcore/classes.idl | 2 + dlls/twinapi.appcore/main.c | 2 + dlls/twinapi.appcore/private.h | 1 + dlls/twinapi.appcore/tests/twinapi.c | 47 ++++++- dlls/windows.globalization/classes.idl | 1 + include/windows.system.userprofile.idl | 4 + 8 files changed, 196 insertions(+), 5 deletions(-) create mode 100644 dlls/twinapi.appcore/advertising_manager.c diff --git a/dlls/twinapi.appcore/Makefile.in b/dlls/twinapi.appcore/Makefile.in index c115182d948..bdec3df54fa 100644 --- a/dlls/twinapi.appcore/Makefile.in +++ b/dlls/twinapi.appcore/Makefile.in @@ -3,6 +3,7 @@ MODULE = twinapi.appcore.dll IMPORTS = combase advapi32 SOURCES = \ + advertising_manager.c \ analytics_info.c \ classes.idl \ client_device_information.c \ diff --git a/dlls/twinapi.appcore/advertising_manager.c b/dlls/twinapi.appcore/advertising_manager.c new file mode 100644 index 00000000000..a61a57c01fa --- /dev/null +++ b/dlls/twinapi.appcore/advertising_manager.c @@ -0,0 +1,143 @@ +/* WinRT Windows.Globalization implementation + * + * Copyright 2021 RĂ©mi Bernon for CodeWeavers + * + * 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 + */ + +#include "private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(twinapi); + +struct factory +{ + IActivationFactory IActivationFactory_iface; + IAdvertisingManagerStatics IAdvertisingManagerStatics_iface; + LONG ref; +}; + +static inline struct factory *impl_from_IActivationFactory( IActivationFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct factory, IActivationFactory_iface ); +} + +static HRESULT WINAPI activation_factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) +{ + struct factory *impl = impl_from_IActivationFactory( iface ); + + TRACE( "iface %p, iid %s, out %p stub!\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IActivationFactory )) + { + IActivationFactory_AddRef( (*out = &impl->IActivationFactory_iface) ); + return S_OK; + } + + if (IsEqualGUID( iid, &IID_IAdvertisingManagerStatics )) + { + IAdvertisingManagerStatics_AddRef( (*out = &impl->IAdvertisingManagerStatics_iface) ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI activation_factory_AddRef( IActivationFactory *iface ) +{ + struct factory *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI activation_factory_Release( IActivationFactory *iface ) +{ + struct factory *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +} + +static HRESULT WINAPI activation_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 activation_factory_GetRuntimeClassName( IActivationFactory *iface, HSTRING *class_name ) +{ + FIXME( "iface %p, class_name %p stub!\n", iface, class_name ); + return E_NOTIMPL; +} + +static HRESULT WINAPI activation_factory_GetTrustLevel( IActivationFactory *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI activation_factory_ActivateInstance( IActivationFactory *iface, IInspectable **instance ) +{ + FIXME( "iface %p, instance %p stub!\n", iface, instance ); + return E_NOTIMPL; +} + +static const struct IActivationFactoryVtbl activation_factory_vtbl = +{ + activation_factory_QueryInterface, + activation_factory_AddRef, + activation_factory_Release, + /* IInspectable methods */ + activation_factory_GetIids, + activation_factory_GetRuntimeClassName, + activation_factory_GetTrustLevel, + /* IActivationFactory methods */ + activation_factory_ActivateInstance, +}; + +DEFINE_IINSPECTABLE( statics, IAdvertisingManagerStatics, struct factory, IActivationFactory_iface ) + +static HRESULT WINAPI statics_get_AdvertisingId( IAdvertisingManagerStatics *iface, HSTRING *out ) +{ + FIXME( "iface %p, out %p stub!\n", iface, out ); + return E_NOTIMPL; +} + +static const struct IAdvertisingManagerStaticsVtbl statics_vtbl = +{ + statics_QueryInterface, + statics_AddRef, + statics_Release, + /* IInspectable methods */ + statics_GetIids, + statics_GetRuntimeClassName, + statics_GetTrustLevel, + /* IAdvertisingManagerStatics methods */ + statics_get_AdvertisingId, +}; + +static struct factory factory = +{ + {&activation_factory_vtbl}, + {&statics_vtbl}, + 1, +}; + +IActivationFactory *advertising_manager_factory = &factory.IActivationFactory_iface; diff --git a/dlls/twinapi.appcore/classes.idl b/dlls/twinapi.appcore/classes.idl index 3d31fb530b3..8a57c8bcaeb 100644 --- a/dlls/twinapi.appcore/classes.idl +++ b/dlls/twinapi.appcore/classes.idl @@ -30,5 +30,7 @@ import "windows.foundation.idl"; import "windows.globalization.idl"; #define DO_NO_IMPORTS +#define _TWINAPI_APPCORE #include "windows.security.exchangeactivesyncprovisioning.idl" #include "windows.system.profile.idl" +#include "windows.system.userprofile.idl" diff --git a/dlls/twinapi.appcore/main.c b/dlls/twinapi.appcore/main.c index 21bcb18f8fb..5d97963af19 100644 --- a/dlls/twinapi.appcore/main.c +++ b/dlls/twinapi.appcore/main.c @@ -73,6 +73,8 @@ HRESULT WINAPI DllGetActivationFactory( HSTRING classid, IActivationFactory **fa IActivationFactory_QueryInterface( client_device_information_factory, &IID_IActivationFactory, (void **)factory ); else if (!wcscmp( buffer, RuntimeClass_Windows_System_Profile_AnalyticsInfo )) IActivationFactory_QueryInterface( analytics_info_factory, &IID_IActivationFactory, (void **)factory ); + else if (!wcscmp( buffer, RuntimeClass_Windows_System_UserProfile_AdvertisingManager )) + IActivationFactory_QueryInterface( advertising_manager_factory, &IID_IActivationFactory, (void **)factory ); if (*factory) return S_OK; return CLASS_E_CLASSNOTAVAILABLE; diff --git a/dlls/twinapi.appcore/private.h b/dlls/twinapi.appcore/private.h index 949609058ff..7063962e2b4 100644 --- a/dlls/twinapi.appcore/private.h +++ b/dlls/twinapi.appcore/private.h @@ -43,6 +43,7 @@ extern IActivationFactory *client_device_information_factory; extern IActivationFactory *analytics_info_factory; +extern IActivationFactory *advertising_manager_factory; #define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \ static inline impl_type *impl_from( iface_type *iface ) \ diff --git a/dlls/twinapi.appcore/tests/twinapi.c b/dlls/twinapi.appcore/tests/twinapi.c index 17c572e0f3a..e5251475e57 100644 --- a/dlls/twinapi.appcore/tests/twinapi.c +++ b/dlls/twinapi.appcore/tests/twinapi.c @@ -40,16 +40,18 @@ #include "wine/test.h" -#define check_interface( a, b, c ) check_interface_( __LINE__, a, b, c ) -static void check_interface_( unsigned int line, void *iface_ptr, REFIID iid, BOOL supported ) +#define check_interface( a, b, c ) check_interface_( __LINE__, a, b, c, FALSE ) +static void check_interface_( unsigned int line, void *iface_ptr, REFIID iid, BOOL supported, BOOL is_broken ) { + HRESULT hr, expected_hr, broken_hr; IUnknown *iface = iface_ptr; - HRESULT hr, expected; IUnknown *unk; - expected = supported ? S_OK : E_NOINTERFACE; + expected_hr = supported ? S_OK : E_NOINTERFACE; + broken_hr = supported ? E_NOINTERFACE : S_OK; hr = IUnknown_QueryInterface( iface, iid, (void **)&unk ); - ok_ (__FILE__, line)( hr == expected, "got hr %#lx, expected %#lx.\n", hr, expected ); + ok_(__FILE__, line)( hr == expected_hr || broken( is_broken && hr == broken_hr ), + "got hr %#lx, expected %#lx.\n", hr, expected_hr ); if (SUCCEEDED(hr)) IUnknown_Release( unk ); } @@ -190,6 +192,40 @@ static void test_AnalyticsVersionInfo(void) ok( ref == 1, "got ref %ld.\n", ref ); } +static void test_AdvertisingManager(void) +{ + static const WCHAR *class_name = RuntimeClass_Windows_System_UserProfile_AdvertisingManager; + IAdvertisingManagerStatics *advertising_manager_statics; + IActivationFactory *factory; + HSTRING str; + HRESULT hr; + LONG ref; + + hr = WindowsCreateString( class_name, wcslen( class_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( class_name ) ); + return; + } + + check_interface( factory, &IID_IUnknown, TRUE ); + check_interface( factory, &IID_IInspectable, TRUE ); + check_interface_( __LINE__, factory, &IID_IAgileObject, TRUE, TRUE ); + + hr = IActivationFactory_QueryInterface( factory, &IID_IAdvertisingManagerStatics, (void **)&advertising_manager_statics ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + + ref = IAdvertisingManagerStatics_Release( advertising_manager_statics ); + ok( ref == 2, "got ref %ld.\n", ref ); + ref = IActivationFactory_Release( factory ); + ok( ref == 1, "got ref %ld.\n", ref ); +} + START_TEST(twinapi) { HRESULT hr; @@ -199,6 +235,7 @@ START_TEST(twinapi) test_EasClientDeviceInformation(); test_AnalyticsVersionInfo(); + test_AdvertisingManager(); RoUninitialize(); } diff --git a/dlls/windows.globalization/classes.idl b/dlls/windows.globalization/classes.idl index ded6b7572e8..b8db4cdfeb2 100644 --- a/dlls/windows.globalization/classes.idl +++ b/dlls/windows.globalization/classes.idl @@ -31,5 +31,6 @@ import "windowscontracts.idl"; import "windows.foundation.idl"; #define DO_NO_IMPORTS +#define _WINDOWS_GLOBALIZATION #include "windows.globalization.idl" #include "windows.system.userprofile.idl" diff --git a/include/windows.system.userprofile.idl b/include/windows.system.userprofile.idl index 672f520c37a..756302d4887 100644 --- a/include/windows.system.userprofile.idl +++ b/include/windows.system.userprofile.idl @@ -64,6 +64,7 @@ namespace Windows.System.UserProfile { [propget] HRESULT AdvertisingId([out, retval] HSTRING *value); } +#ifndef _TWINAPI_APPCORE [ contract(Windows.Foundation.UniversalApiContract, 1.0), marshaling_behavior(agile), @@ -74,7 +75,9 @@ namespace Windows.System.UserProfile { runtimeclass GlobalizationPreferences { } +#endif +#ifndef _WINDOWS_GLOBALIZATION [ contract(Windows.Foundation.UniversalApiContract, 1.0), marshaling_behavior(standard), @@ -84,5 +87,6 @@ namespace Windows.System.UserProfile { runtimeclass AdvertisingManager { } +#endif }