Needed for ISystemIdentificationInfo::get_Id().
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Needed for ISystemIdentificationInfo::get_Id(). --- dlls/wintypes/Makefile.in | 1 + dlls/wintypes/buffer.c | 145 +++++++++++++++++++++++++++++++++ dlls/wintypes/main.c | 2 + dlls/wintypes/private.h | 1 + dlls/wintypes/tests/wintypes.c | 49 +++++++++++ 5 files changed, 198 insertions(+) create mode 100644 dlls/wintypes/buffer.c
diff --git a/dlls/wintypes/Makefile.in b/dlls/wintypes/Makefile.in index 840f47abd17..a512d3fec63 100644 --- a/dlls/wintypes/Makefile.in +++ b/dlls/wintypes/Makefile.in @@ -3,6 +3,7 @@ IMPORTLIB = wintypes IMPORTS = combase
SOURCES = \ + buffer.c \ classes.idl \ main.c \ storage.c \ diff --git a/dlls/wintypes/buffer.c b/dlls/wintypes/buffer.c new file mode 100644 index 00000000000..90682db8531 --- /dev/null +++ b/dlls/wintypes/buffer.c @@ -0,0 +1,145 @@ +/* WinRT Windows.Storage.Streams.Buffer 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 + */ + +#include "private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(wintypes); + +struct buffer_statics +{ + IActivationFactory IActivationFactory_iface; + IBufferFactory IBufferFactory_iface; + LONG ref; +}; + +static inline struct buffer_statics *impl_from_IActivationFactory( IActivationFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct buffer_statics, IActivationFactory_iface ); +} + +static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) +{ + struct buffer_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_IBufferFactory )) + { + *out = &impl->IBufferFactory_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 buffer_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p increasing refcount to %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI factory_Release( IActivationFactory *iface ) +{ + struct buffer_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p decreasing refcount 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( buffer_statics, IBufferFactory, struct buffer_statics, IActivationFactory_iface ) + +static HRESULT WINAPI buffer_statics_Create( IBufferFactory *iface, UINT32 capacity, IBuffer **value ) +{ + FIXME( "iface %p, capacity %u, value %p stub!\n", iface, capacity, value ); + return E_NOTIMPL; +} + +static const struct IBufferFactoryVtbl buffer_statics_vtbl = +{ + buffer_statics_QueryInterface, + buffer_statics_AddRef, + buffer_statics_Release, + /* IInspectable methods */ + buffer_statics_GetIids, + buffer_statics_GetRuntimeClassName, + buffer_statics_GetTrustLevel, + /* IBufferFactory methods */ + buffer_statics_Create, +}; + +static struct buffer_statics buffer_statics = +{ + {&factory_vtbl}, + {&buffer_statics_vtbl}, + 1, +}; + +IActivationFactory *buffer_activation_factory = &buffer_statics.IActivationFactory_iface; diff --git a/dlls/wintypes/main.c b/dlls/wintypes/main.c index 79540cac3ee..e5ed6d3b335 100644 --- a/dlls/wintypes/main.c +++ b/dlls/wintypes/main.c @@ -1304,6 +1304,8 @@ HRESULT WINAPI DllGetActivationFactory(HSTRING classid, IActivationFactory **fac IActivationFactory_AddRef((*factory = &api_information_statics.IActivationFactory_iface)); if (!wcscmp(buffer, L"Windows.Foundation.PropertyValue")) IActivationFactory_AddRef((*factory = &property_value_statics.IActivationFactory_iface)); + if (!wcscmp(buffer, L"Windows.Storage.Streams.Buffer")) + IActivationFactory_AddRef((*factory = buffer_activation_factory)); if (!wcscmp(buffer, L"Windows.Storage.Streams.DataWriter")) IActivationFactory_AddRef((*factory = data_writer_activation_factory));
diff --git a/dlls/wintypes/private.h b/dlls/wintypes/private.h index f422df64ade..f8d8b4e2eef 100644 --- a/dlls/wintypes/private.h +++ b/dlls/wintypes/private.h @@ -39,3 +39,4 @@ #include "wintypes_private.h"
extern IActivationFactory *data_writer_activation_factory; +extern IActivationFactory *buffer_activation_factory; diff --git a/dlls/wintypes/tests/wintypes.c b/dlls/wintypes/tests/wintypes.c index 295a62ef874..90bd32513f8 100644 --- a/dlls/wintypes/tests/wintypes.c +++ b/dlls/wintypes/tests/wintypes.c @@ -134,6 +134,54 @@ static void test_interfaces(void) RoUninitialize(); }
+static void test_IBufferStatics(void) +{ + static const WCHAR *class_name = L"Windows.Storage.Streams.Buffer"; + IBufferFactory *buffer_factory = NULL; + IActivationFactory *factory = NULL; + IBuffer *buffer = NULL; + HSTRING str; + HRESULT hr; + + hr = RoInitialize(RO_INIT_MULTITHREADED); + ok(hr == S_OK, "RoInitialize failed, hr %#lx.\n", hr); + + hr = WindowsCreateString(class_name, wcslen(class_name), &str); + ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr); + + hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory); + ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG), "RoGetActivationFactory failed, hr %#lx.\n", hr); + WindowsDeleteString(str); + if (hr == REGDB_E_CLASSNOTREG) + { + win_skip("%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w(class_name)); + RoUninitialize(); + return; + } + + check_interface(factory, &IID_IUnknown, TRUE); + check_interface(factory, &IID_IInspectable, TRUE); + check_interface(factory, &IID_IAgileObject, TRUE); + + hr = IActivationFactory_QueryInterface(factory, &IID_IBufferFactory, (void **)&buffer_factory); + ok(hr == S_OK, "QueryInterface IID_IBufferFactory failed, hr %#lx.\n", hr); + + if (0) /* Crash on Windows */ + { + hr = IBufferFactory_Create(buffer_factory, 0, NULL); + ok(hr == E_INVALIDARG, "IBufferFactory_Create failed, hr %#lx.\n", hr); + } + + hr = IBufferFactory_Create(buffer_factory, 0, &buffer); + todo_wine + ok(hr == S_OK, "IBufferFactory_Create failed, hr %#lx.\n", hr); + if (hr == S_OK) IBuffer_Release(buffer); + + IBufferFactory_Release(buffer_factory); + IActivationFactory_Release(factory); + RoUninitialize(); +} + static void test_IApiInformationStatics(void) { static const struct @@ -1065,6 +1113,7 @@ START_TEST(wintypes)
test_interfaces(); test_IApiInformationStatics(); + test_IBufferStatics(); test_IPropertyValueStatics(); test_RoParseTypeName(); test_RoResolveNamespace();