From: Jactry Zeng jzeng@codeweavers.com
--- dlls/wintypes/Makefile.in | 1 + dlls/wintypes/classes.idl | 1 + dlls/wintypes/main.c | 19 +----- dlls/wintypes/private.h | 39 +++++++++++ dlls/wintypes/storage.c | 118 +++++++++++++++++++++++++++++++++ dlls/wintypes/tests/wintypes.c | 38 +++++++++++ 6 files changed, 200 insertions(+), 16 deletions(-) create mode 100644 dlls/wintypes/private.h create mode 100644 dlls/wintypes/storage.c
diff --git a/dlls/wintypes/Makefile.in b/dlls/wintypes/Makefile.in index b8958cdcd15..840f47abd17 100644 --- a/dlls/wintypes/Makefile.in +++ b/dlls/wintypes/Makefile.in @@ -5,4 +5,5 @@ IMPORTS = combase SOURCES = \ classes.idl \ main.c \ + storage.c \ wintypes_private.idl diff --git a/dlls/wintypes/classes.idl b/dlls/wintypes/classes.idl index 116c764fe6e..648eafddc16 100644 --- a/dlls/wintypes/classes.idl +++ b/dlls/wintypes/classes.idl @@ -28,3 +28,4 @@ #define _WINTYPES #include "windows.foundation.idl" #include "windows.foundation.metadata.idl" +#include "windows.storage.streams.idl" diff --git a/dlls/wintypes/main.c b/dlls/wintypes/main.c index 3fc82c9693d..79540cac3ee 100644 --- a/dlls/wintypes/main.c +++ b/dlls/wintypes/main.c @@ -16,23 +16,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
-#include <stdarg.h> - -#define COBJMACROS #include "initguid.h" -#include "windef.h" -#include "winbase.h" -#include "winstring.h" -#include "wine/debug.h" -#include "objbase.h" - -#include "activation.h" -#include "rometadataresolution.h" - -#define WIDL_using_Windows_Foundation -#define WIDL_using_Windows_Foundation_Metadata -#include "windows.foundation.metadata.h" -#include "wintypes_private.h" +#include "private.h"
WINE_DEFAULT_DEBUG_CHANNEL(wintypes);
@@ -1319,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.DataWriter")) + IActivationFactory_AddRef((*factory = data_writer_activation_factory));
if (*factory) return S_OK; return CLASS_E_CLASSNOTAVAILABLE; diff --git a/dlls/wintypes/private.h b/dlls/wintypes/private.h new file mode 100644 index 00000000000..34b69e61b82 --- /dev/null +++ b/dlls/wintypes/private.h @@ -0,0 +1,39 @@ +/* + * Copyright 2022-2024 Zhiyi Zhang for CodeWeavers + * Copyright 2025 Jactry Zeng 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 <stdarg.h> + +#define COBJMACROS +#include "windef.h" +#include "winbase.h" +#include "winstring.h" +#include "wine/debug.h" +#include "objbase.h" + +#include "activation.h" +#include "rometadataresolution.h" + +#define WIDL_using_Windows_Foundation +#define WIDL_using_Windows_Foundation_Metadata +#include "windows.foundation.metadata.h" +#define WIDL_using_Windows_Storage_Streams +#include "windows.storage.streams.h" +#include "wintypes_private.h" + +extern IActivationFactory *data_writer_activation_factory; diff --git a/dlls/wintypes/storage.c b/dlls/wintypes/storage.c new file mode 100644 index 00000000000..b09d8036abc --- /dev/null +++ b/dlls/wintypes/storage.c @@ -0,0 +1,118 @@ +/* + * Copyright 2022-2024 Zhiyi Zhang for CodeWeavers + * Copyright 2025 Jactry Zeng 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(wintypes); + +struct data_writer +{ + IActivationFactory IActivationFactory_iface; + LONG ref; +}; + +static inline struct data_writer *impl_data_writer_from_IActivationFactory(IActivationFactory *iface) +{ + return CONTAINING_RECORD(iface, struct data_writer, IActivationFactory_iface); +} + +static HRESULT STDMETHODCALLTYPE data_writer_activation_factory_QueryInterface(IActivationFactory *iface, REFIID iid, + void **out) +{ + 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)) + { + IUnknown_AddRef(iface); + *out = iface; + return S_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG STDMETHODCALLTYPE data_writer_activation_factory_AddRef(IActivationFactory *iface) +{ + struct data_writer *impl = impl_data_writer_from_IActivationFactory(iface); + ULONG ref = InterlockedIncrement(&impl->ref); + TRACE("iface %p, ref %lu.\n", iface, ref); + return ref; +} + +static ULONG STDMETHODCALLTYPE data_writer_activation_factory_Release(IActivationFactory *iface) +{ + struct data_writer *impl = impl_data_writer_from_IActivationFactory(iface); + ULONG ref = InterlockedDecrement(&impl->ref); + TRACE("iface %p, ref %lu.\n", iface, ref); + return ref; +} + +static HRESULT STDMETHODCALLTYPE data_writer_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 STDMETHODCALLTYPE data_writer_activation_factory_GetRuntimeClassName(IActivationFactory *iface, + HSTRING *class_name) +{ + FIXME("iface %p, class_name %p stub!\n", iface, class_name); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE data_writer_activation_factory_GetTrustLevel(IActivationFactory *iface, + TrustLevel *trust_level) +{ + FIXME("iface %p, trust_level %p stub!\n", iface, trust_level); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE data_writer_activation_factory_ActivateInstance(IActivationFactory *iface, + IInspectable **instance) +{ + FIXME("iface %p, instance %p stub!\n", iface, instance); + return E_NOTIMPL; +} + +static const struct IActivationFactoryVtbl data_writer_activation_factory_vtbl = +{ + data_writer_activation_factory_QueryInterface, + data_writer_activation_factory_AddRef, + data_writer_activation_factory_Release, + /* IInspectable methods */ + data_writer_activation_factory_GetIids, + data_writer_activation_factory_GetRuntimeClassName, + data_writer_activation_factory_GetTrustLevel, + /* IActivationFactory methods */ + data_writer_activation_factory_ActivateInstance, +}; + +struct data_writer data_writer = +{ + {&data_writer_activation_factory_vtbl}, + 1 +}; + +IActivationFactory *data_writer_activation_factory = &data_writer.IActivationFactory_iface; diff --git a/dlls/wintypes/tests/wintypes.c b/dlls/wintypes/tests/wintypes.c index 28f87b1c512..3c46cca1c68 100644 --- a/dlls/wintypes/tests/wintypes.c +++ b/dlls/wintypes/tests/wintypes.c @@ -32,6 +32,9 @@ #include "windows.foundation.metadata.h" #include "wintypes_test.h"
+#define WIDL_using_Windows_Storage_Streams +#include "windows.storage.streams.h" + #include "wine/test.h"
static BOOL is_wow64; @@ -54,6 +57,7 @@ static void test_interfaces(void) { static WCHAR class_name[1024]; IActivationFactory *factory; + IUnknown *unk; HSTRING str; HRESULT hr;
@@ -93,6 +97,40 @@ static void test_interfaces(void) IActivationFactory_Release(factory); WindowsDeleteString(str);
+ wcscpy(class_name, L"Windows.Storage.Streams.DataWriter"); + hr = WindowsCreateString(class_name, wcslen(class_name), &str); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + check_interface(factory, &IID_IUnknown, TRUE); + check_interface(factory, &IID_IInspectable, TRUE); + check_interface(factory, &IID_IAgileObject, TRUE); + check_interface(factory, &IID_IActivationFactory, TRUE); + todo_wine check_interface(factory, &IID_IDataWriterFactory, TRUE); + check_interface(factory, &IID_IRandomAccessStreamReferenceStatics, FALSE); + check_interface(factory, &IID_IApiInformationStatics, FALSE); + check_interface(factory, &IID_IPropertyValueStatics, FALSE); + IActivationFactory_Release(factory); + WindowsDeleteString(str); + + wcscpy(class_name, L"Windows.Storage.Streams.RandomAccessStreamReference"); + hr = WindowsCreateString(class_name, wcslen(class_name), &str); + ok(hr == S_OK, "Got hr %#lx.\n", hr); + hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory); + todo_wine ok(hr == S_OK, "Got hr %#lx.\n", hr); + check_interface(factory, &IID_IUnknown, TRUE); + check_interface(factory, &IID_IInspectable, TRUE); + hr = IActivationFactory_QueryInterface(factory, &IID_IAgileObject, (void **)&unk); + ok(hr == S_OK || broken(hr == E_NOINTERFACE) /* pre win10 v1809 */, "Got hr %#lx.\n", hr); + if (SUCCEEDED(hr)) IUnknown_Release(unk); + check_interface(factory, &IID_IActivationFactory, TRUE); + check_interface(factory, &IID_IDataWriterFactory, FALSE); + todo_wine check_interface(factory, &IID_IRandomAccessStreamReferenceStatics, TRUE); + check_interface(factory, &IID_IApiInformationStatics, FALSE); + check_interface(factory, &IID_IPropertyValueStatics, FALSE); + IActivationFactory_Release(factory); + WindowsDeleteString(str); + RoUninitialize(); }