Needed for Lenovo Ready for Assistant.
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Needed by windows.devices.usb.idl. --- include/windows.foundation.idl | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/include/windows.foundation.idl b/include/windows.foundation.idl index 9be302515a4..46b50f80a53 100644 --- a/include/windows.foundation.idl +++ b/include/windows.foundation.idl @@ -84,8 +84,10 @@ namespace Windows.Foundation { interface Windows.Foundation.EventHandler<IInspectable *>; interface Windows.Foundation.AsyncOperationCompletedHandler<IInspectable *>; interface Windows.Foundation.AsyncOperationCompletedHandler<boolean>; + interface Windows.Foundation.AsyncOperationCompletedHandler<UINT32>; interface Windows.Foundation.IAsyncOperation<IInspectable *>; interface Windows.Foundation.IAsyncOperation<boolean>; + interface Windows.Foundation.IAsyncOperation<UINT32>; interface Windows.Foundation.IReference<BYTE>; interface Windows.Foundation.IReference<INT32>; interface Windows.Foundation.IReference<DOUBLE>;
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Needed by windows.devices.usb.idl. --- include/windows.storage.streams.idl | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/include/windows.storage.streams.idl b/include/windows.storage.streams.idl index bb107b25976..9255fb43ff3 100644 --- a/include/windows.storage.streams.idl +++ b/include/windows.storage.streams.idl @@ -35,6 +35,11 @@ namespace Windows.Storage.Streams { interface IRandomAccessStreamWithContentType; runtimeclass Buffer;
+ declare { + interface Windows.Foundation.AsyncOperationCompletedHandler<Windows.Storage.Streams.IBuffer *>; + interface Windows.Foundation.IAsyncOperation<Windows.Storage.Streams.IBuffer *>; + } + [ contract(Windows.Foundation.UniversalApiContract, 1.0), uuid(905a0fe0-bc53-11df-8c49-001e4fc686da)
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- include/Makefile.in | 1 + include/windows.devices.usb.idl | 170 ++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 include/windows.devices.usb.idl
diff --git a/include/Makefile.in b/include/Makefile.in index b1b582ff4d6..e6c495bafd0 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -813,6 +813,7 @@ SOURCES = \ windows.devices.haptics.idl \ windows.devices.power.idl \ windows.devices.radios.idl \ + windows.devices.usb.idl \ windows.foundation.collections.idl \ windows.foundation.idl \ windows.foundation.metadata.idl \ diff --git a/include/windows.devices.usb.idl b/include/windows.devices.usb.idl new file mode 100644 index 00000000000..98cbfcaa7c4 --- /dev/null +++ b/include/windows.devices.usb.idl @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2023 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 + */ + +#ifdef __WIDL__ +#pragma winrt ns_prefix +#endif + +import "inspectable.idl"; +import "asyncinfo.idl"; +import "eventtoken.idl"; +import "windowscontracts.idl"; +import "windows.foundation.idl"; +import "windows.storage.streams.idl"; + +namespace Windows.Devices.Usb { + interface IUsbDevice; + interface IUsbDeviceClass; + interface IUsbConfiguration; + interface IUsbDeviceDescriptor; + interface IUsbDeviceStatics; + interface IUsbInterface; + interface IUsbSetupPacket; + interface IUsbSetupPacketFactory; + + runtimeclass UsbConfiguration; + runtimeclass UsbDevice; + runtimeclass UsbDeviceClass; + runtimeclass UsbDeviceDescriptor; + runtimeclass UsbInterface; + runtimeclass UsbSetupPacket; + + declare { + interface Windows.Foundation.AsyncOperationCompletedHandler<Windows.Devices.Usb.UsbDevice *>; + interface Windows.Foundation.IAsyncOperation<Windows.Devices.Usb.UsbDevice *>; + } + + [ + contract(Windows.Foundation.UniversalApiContract, 1.0), + exclusiveto(Windows.Devices.Usb.UsbDevice), + uuid(5249b992-c456-44d5-ad5e-24f5a089f63b) + ] + interface IUsbDevice : IInspectable + requires Windows.Foundation.IClosable + { + [overload("SendControlOutTransferAsync")] HRESULT SendControlOutTransferAsync( + [in] Windows.Devices.Usb.UsbSetupPacket *packet, + [in] Windows.Storage.Streams.IBuffer *buffer, + [out, retval] Windows.Foundation.IAsyncOperation<UINT32> **operation + ); + [overload("SendControlOutTransferAsync")] HRESULT SendControlOutTransferAsyncNoBuffer( + [in] Windows.Devices.Usb.UsbSetupPacket *packet, + [out, retval] Windows.Foundation.IAsyncOperation<UINT32> **operation + ); + [overload("SendControlInTransferAsync")] HRESULT SendControlInTransferAsync( + [in] Windows.Devices.Usb.UsbSetupPacket *packet, + [in] Windows.Storage.Streams.IBuffer *buffer, + [out, retval] Windows.Foundation.IAsyncOperation<Windows.Storage.Streams.IBuffer *> **operation + ); + [overload("SendControlInTransferAsync")] HRESULT SendControlInTransferAsyncNoBuffer( + [in] Windows.Devices.Usb.UsbSetupPacket *packet, + [out, retval] Windows.Foundation.IAsyncOperation<Windows.Storage.Streams.IBuffer *> **operation + ); + [propget] HRESULT DefaultInterface([out, retval] Windows.Devices.Usb.UsbInterface **value); + [propget] HRESULT DeviceDescriptor([out, retval] Windows.Devices.Usb.UsbDeviceDescriptor **value); + [propget] HRESULT Configuration([out, retval] Windows.Devices.Usb.UsbConfiguration **value); + } + + [ + contract(Windows.Foundation.UniversalApiContract, 1.0), + exclusiveto(Windows.Devices.Usb.UsbDeviceClass), + uuid(051942f9-845e-47eb-b12a-38f2f617afe7) + ] + interface IUsbDeviceClass : IInspectable + { + [propget] HRESULT ClassCode([out, retval] BYTE *value); + [propput] HRESULT ClassCode([in] BYTE value); + [propget] HRESULT SubclassCode([out, retval] Windows.Foundation.IReference<BYTE> **value); + [propput] HRESULT SubclassCode([in] Windows.Foundation.IReference<BYTE> *value); + [propget] HRESULT ProtocolCode([out, retval] Windows.Foundation.IReference<BYTE> **value); + [propput] HRESULT ProtocolCode([in] Windows.Foundation.IReference<BYTE> *value); + } + + [ + contract(Windows.Foundation.UniversalApiContract, 1.0), + exclusiveto(Windows.Devices.Usb.UsbDevice), + uuid(066b85a2-09b7-4446-8502-6fe6dcaa7309) + ] + interface IUsbDeviceStatics : IInspectable + { + [overload("GetDeviceSelector")] HRESULT GetDeviceSelector([in] UINT32 vendor, [in] UINT32 product, [in] GUID class, [out, retval] HSTRING *value); + [overload("GetDeviceSelector")] HRESULT GetDeviceSelectorGuidOnly([in] GUID class, [out, retval] HSTRING *value); + [overload("GetDeviceSelector")] HRESULT GetDeviceSelectorVidPidOnly([in] UINT32 vendor, [in] UINT32 product, [out, retval] HSTRING *value); + HRESULT GetDeviceClassSelector([in] Windows.Devices.Usb.UsbDeviceClass *class, [out, retval] HSTRING *value); + HRESULT FromIdAsync([in] HSTRING id, [out, retval] Windows.Foundation.IAsyncOperation<Windows.Devices.Usb.UsbDevice *> **operation); + } + + [ + contract(Windows.Foundation.UniversalApiContract, 1.0), + marshaling_behavior(agile) + ] + runtimeclass UsbConfiguration + { + [default] interface Windows.Devices.Usb.IUsbConfiguration; + } + + [ + contract(Windows.Foundation.UniversalApiContract, 1.0), + marshaling_behavior(agile), + static(Windows.Devices.Usb.IUsbDeviceStatics, Windows.Foundation.UniversalApiContract, 1.0) + ] + runtimeclass UsbDevice + { + [default] interface Windows.Devices.Usb.IUsbDevice; + interface Windows.Foundation.IClosable; + } + + [ + activatable(Windows.Foundation.UniversalApiContract, 1.0), + contract(Windows.Foundation.UniversalApiContract, 1.0), + marshaling_behavior(agile) + ] + runtimeclass UsbDeviceClass + { + [default] interface Windows.Devices.Usb.IUsbDeviceClass; + } + + [ + contract(Windows.Foundation.UniversalApiContract, 1.0), + marshaling_behavior(agile) + ] + runtimeclass UsbDeviceDescriptor + { + [default] interface Windows.Devices.Usb.IUsbDeviceDescriptor; + } + + [ + contract(Windows.Foundation.UniversalApiContract, 1.0), + marshaling_behavior(agile) + ] + runtimeclass UsbInterface + { + [default] interface Windows.Devices.Usb.IUsbInterface; + } + + [ + activatable(Windows.Devices.Usb.IUsbSetupPacketFactory, Windows.Foundation.UniversalApiContract, 1.0), + activatable(Windows.Foundation.UniversalApiContract, 1.0), + contract(Windows.Foundation.UniversalApiContract, 1.0), + marshaling_behavior(agile) + ] + runtimeclass UsbSetupPacket + { + [default] interface Windows.Devices.Usb.IUsbSetupPacket; + } +}
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- configure.ac | 2 + dlls/windows.devices.usb/Makefile.in | 9 ++ dlls/windows.devices.usb/classes.idl | 23 ++++ dlls/windows.devices.usb/main.c | 46 +++++++ dlls/windows.devices.usb/private.h | 40 ++++++ dlls/windows.devices.usb/tests/Makefile.in | 5 + dlls/windows.devices.usb/tests/usb.c | 86 +++++++++++++ dlls/windows.devices.usb/usbdevice.c | 116 ++++++++++++++++++ .../windows.devices.usb.spec | 3 + 9 files changed, 330 insertions(+) create mode 100644 dlls/windows.devices.usb/Makefile.in create mode 100644 dlls/windows.devices.usb/classes.idl create mode 100644 dlls/windows.devices.usb/main.c create mode 100644 dlls/windows.devices.usb/private.h create mode 100644 dlls/windows.devices.usb/tests/Makefile.in create mode 100644 dlls/windows.devices.usb/tests/usb.c create mode 100644 dlls/windows.devices.usb/usbdevice.c create mode 100644 dlls/windows.devices.usb/windows.devices.usb.spec
diff --git a/configure.ac b/configure.ac index 87a05fa903d..4150e6ed88c 100644 --- a/configure.ac +++ b/configure.ac @@ -3142,6 +3142,8 @@ WINE_CONFIG_MAKEFILE(dlls/windows.devices.enumeration) WINE_CONFIG_MAKEFILE(dlls/windows.devices.enumeration/tests) WINE_CONFIG_MAKEFILE(dlls/windows.devices.geolocation.geolocator) WINE_CONFIG_MAKEFILE(dlls/windows.devices.geolocation.geolocator/tests) +WINE_CONFIG_MAKEFILE(dlls/windows.devices.usb) +WINE_CONFIG_MAKEFILE(dlls/windows.devices.usb/tests) WINE_CONFIG_MAKEFILE(dlls/windows.gaming.input) WINE_CONFIG_MAKEFILE(dlls/windows.gaming.input/tests) WINE_CONFIG_MAKEFILE(dlls/windows.gaming.ui.gamebar) diff --git a/dlls/windows.devices.usb/Makefile.in b/dlls/windows.devices.usb/Makefile.in new file mode 100644 index 00000000000..d205b8be87d --- /dev/null +++ b/dlls/windows.devices.usb/Makefile.in @@ -0,0 +1,9 @@ +MODULE = windows.devices.usb.dll +IMPORTS = combase + +C_SRCS = \ + main.c \ + usbdevice.c + +IDL_SRCS = \ + classes.idl diff --git a/dlls/windows.devices.usb/classes.idl b/dlls/windows.devices.usb/classes.idl new file mode 100644 index 00000000000..2f614c5b8d2 --- /dev/null +++ b/dlls/windows.devices.usb/classes.idl @@ -0,0 +1,23 @@ +/* + * Runtime Classes for windows.devices.usb.dll + * + * Copyright (C) 2023 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 + +#include "windows.devices.usb.idl" diff --git a/dlls/windows.devices.usb/main.c b/dlls/windows.devices.usb/main.c new file mode 100644 index 00000000000..e7a6bcc1552 --- /dev/null +++ b/dlls/windows.devices.usb/main.c @@ -0,0 +1,46 @@ +/* WinRT Windows.Devices.Usb Implementation + * + * Copyright (C) 2023 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 "initguid.h" +#include "private.h" + +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(usb); + +HRESULT WINAPI DllGetClassObject( REFCLSID clsid, REFIID riid, void **out ) +{ + FIXME( "clsid %s, riid %s, out %p stub!\n", debugstr_guid(clsid), debugstr_guid(riid), out ); + return CLASS_E_CLASSNOTAVAILABLE; +} + +HRESULT WINAPI DllGetActivationFactory( HSTRING classid, IActivationFactory **factory ) +{ + const WCHAR *buffer = WindowsGetStringRawBuffer( classid, NULL ); + + TRACE( "class %s, factory %p.\n", debugstr_hstring(classid), factory ); + + *factory = NULL; + + if (!wcscmp( buffer, RuntimeClass_Windows_Devices_Usb_UsbDevice )) + IActivationFactory_QueryInterface( usbdevice_factory, &IID_IActivationFactory, (void **)factory ); + + if (*factory) return S_OK; + return CLASS_E_CLASSNOTAVAILABLE; +} diff --git a/dlls/windows.devices.usb/private.h b/dlls/windows.devices.usb/private.h new file mode 100644 index 00000000000..0a5ddda6845 --- /dev/null +++ b/dlls/windows.devices.usb/private.h @@ -0,0 +1,40 @@ +/* WinRT Windows.Devices.Usb UsbDevice Implementation + * + * Copyright (C) 2023 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_WINDOWS_DEVICES_USB_PRIVATE_H +#define __WINE_WINDOWS_DEVICES_USB_PRIVATE_H + +#include <stdarg.h> + +#define COBJMACROS +#include "windef.h" +#include "winbase.h" +#include "winstring.h" + +#include "activation.h" + +#define WIDL_using_Windows_Foundation +#define WIDL_using_Windows_Foundation_Collections +#include "windows.foundation.h" +#define WIDL_using_Windows_Devices_Usb +#include "windows.devices.usb.h" + +extern IActivationFactory *usbdevice_factory; + +#endif diff --git a/dlls/windows.devices.usb/tests/Makefile.in b/dlls/windows.devices.usb/tests/Makefile.in new file mode 100644 index 00000000000..1cfecd0488a --- /dev/null +++ b/dlls/windows.devices.usb/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = windows.devices.usb.dll +IMPORTS = combase + +C_SRCS = \ + usb.c diff --git a/dlls/windows.devices.usb/tests/usb.c b/dlls/windows.devices.usb/tests/usb.c new file mode 100644 index 00000000000..9ffcab52881 --- /dev/null +++ b/dlls/windows.devices.usb/tests/usb.c @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2023 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 +#define WIDL_using_Windows_Foundation_Collections +#include "windows.foundation.h" +#define WIDL_using_Windows_Devices_Usb +#include "windows.devices.usb.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_UsbDevicesStatics(void) +{ + static const WCHAR *usbdevice_statics_name = L"Windows.Devices.Usb.UsbDevice"; + IActivationFactory *factory; + HSTRING str; + HRESULT hr; + LONG ref; + + hr = WindowsCreateString( usbdevice_statics_name, wcslen( usbdevice_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( usbdevice_statics_name ) ); + return; + } + + check_interface( factory, &IID_IUnknown ); + check_interface( factory, &IID_IInspectable ); + check_interface( factory, &IID_IAgileObject ); + + ref = IActivationFactory_Release( factory ); + ok( ref == 1, "got ref %ld.\n", ref ); +} + +START_TEST(usb) +{ + HRESULT hr; + + hr = RoInitialize( RO_INIT_MULTITHREADED ); + ok( hr == S_OK, "RoInitialize failed, hr %#lx\n", hr ); + + test_UsbDevicesStatics(); + + RoUninitialize(); +} diff --git a/dlls/windows.devices.usb/usbdevice.c b/dlls/windows.devices.usb/usbdevice.c new file mode 100644 index 00000000000..f22e2e78d2c --- /dev/null +++ b/dlls/windows.devices.usb/usbdevice.c @@ -0,0 +1,116 @@ +/* WinRT Windows.Devices.Usb UsbDevice Implementation + * + * Copyright (C) 2023 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" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(usb); + +struct usbdevice_statics +{ + IActivationFactory IActivationFactory_iface; + LONG ref; +}; + +static inline struct usbdevice_statics *impl_from_IActivationFactory( IActivationFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct usbdevice_statics, IActivationFactory_iface ); +} + +static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) +{ + struct usbdevice_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; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI factory_AddRef( IActivationFactory *iface ) +{ + struct usbdevice_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 usbdevice_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, +}; + +static struct usbdevice_statics usbdevice_statics = +{ + {&factory_vtbl}, + 1, +}; + +IActivationFactory *usbdevice_factory = &usbdevice_statics.IActivationFactory_iface; diff --git a/dlls/windows.devices.usb/windows.devices.usb.spec b/dlls/windows.devices.usb/windows.devices.usb.spec new file mode 100644 index 00000000000..20a8bfa98ea --- /dev/null +++ b/dlls/windows.devices.usb/windows.devices.usb.spec @@ -0,0 +1,3 @@ +@ stdcall -private DllCanUnloadNow() +@ stdcall -private DllGetActivationFactory(ptr ptr) +@ stdcall -private DllGetClassObject(ptr ptr ptr)
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/windows.devices.usb/private.h | 38 ++++++++++++++++++ dlls/windows.devices.usb/tests/usb.c | 6 +++ dlls/windows.devices.usb/usbdevice.c | 60 ++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+)
diff --git a/dlls/windows.devices.usb/private.h b/dlls/windows.devices.usb/private.h index 0a5ddda6845..0364d20ad7e 100644 --- a/dlls/windows.devices.usb/private.h +++ b/dlls/windows.devices.usb/private.h @@ -37,4 +37,42 @@
extern IActivationFactory *usbdevice_factory;
+#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/windows.devices.usb/tests/usb.c b/dlls/windows.devices.usb/tests/usb.c index 9ffcab52881..347cfa29c1c 100644 --- a/dlls/windows.devices.usb/tests/usb.c +++ b/dlls/windows.devices.usb/tests/usb.c @@ -48,6 +48,7 @@ static void check_interface_( unsigned int line, void *obj, const IID *iid ) static void test_UsbDevicesStatics(void) { static const WCHAR *usbdevice_statics_name = L"Windows.Devices.Usb.UsbDevice"; + IUsbDeviceStatics *usbdevice_statics; IActivationFactory *factory; HSTRING str; HRESULT hr; @@ -69,6 +70,11 @@ static void test_UsbDevicesStatics(void) check_interface( factory, &IID_IInspectable ); check_interface( factory, &IID_IAgileObject );
+ hr = IActivationFactory_QueryInterface( factory, &IID_IUsbDeviceStatics, (void **)&usbdevice_statics ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + + ref = IUsbDeviceStatics_Release( usbdevice_statics ); + ok( ref == 2, "got ref %ld.\n", ref ); ref = IActivationFactory_Release( factory ); ok( ref == 1, "got ref %ld.\n", ref ); } diff --git a/dlls/windows.devices.usb/usbdevice.c b/dlls/windows.devices.usb/usbdevice.c index f22e2e78d2c..a43dda26d80 100644 --- a/dlls/windows.devices.usb/usbdevice.c +++ b/dlls/windows.devices.usb/usbdevice.c @@ -25,6 +25,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(usb); struct usbdevice_statics { IActivationFactory IActivationFactory_iface; + IUsbDeviceStatics IUsbDeviceStatics_iface; LONG ref; };
@@ -49,6 +50,13 @@ static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID return S_OK; }
+ if (IsEqualGUID( iid, &IID_IUsbDeviceStatics )) + { + *out = &impl->IUsbDeviceStatics_iface; + IInspectable_AddRef( *out ); + return S_OK; + } + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); *out = NULL; return E_NOINTERFACE; @@ -107,9 +115,61 @@ static const struct IActivationFactoryVtbl factory_vtbl = factory_ActivateInstance, };
+DEFINE_IINSPECTABLE( usbdevice_statics, IUsbDeviceStatics, struct usbdevice_statics, IActivationFactory_iface ) + +static HRESULT WINAPI usbdevice_statics_GetDeviceSelector( IUsbDeviceStatics *iface, UINT32 vendor, + UINT32 product, GUID class, HSTRING *value ) +{ + FIXME( "iface %p, vendor %d, product %d, class %s, value %p stub!\n", iface, vendor, product, debugstr_guid(&class), value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI usbdevice_statics_GetDeviceSelectorGuidOnly( IUsbDeviceStatics *iface, GUID class, HSTRING *value ) +{ + FIXME( "iface %p, class %s, value %p stub!\n", iface, debugstr_guid(&class), value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI usbdevice_statics_GetDeviceSelectorVidPidOnly( IUsbDeviceStatics *iface, UINT32 vendor, + UINT32 product, HSTRING *value ) +{ + FIXME( "iface %p, vendor %d, product %d, value %p stub!\n", iface, vendor, product, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI usbdevice_statics_GetDeviceClassSelector( IUsbDeviceStatics *iface, IUsbDeviceClass *class, HSTRING *value ) +{ + FIXME( "iface %p, class %p, value %p stub!\n", iface, class, value ); + return E_NOTIMPL; +} + +static HRESULT WINAPI usbdevice_statics_FromIdAsync( IUsbDeviceStatics *iface, HSTRING id, IAsyncOperation_UsbDevice **operation ) +{ + FIXME( "iface %p, id %s, operation %p stub!\n", iface, debugstr_hstring(id), operation ); + return E_NOTIMPL; +} + +static const struct IUsbDeviceStaticsVtbl usbdevice_statics_vtbl = +{ + usbdevice_statics_QueryInterface, + usbdevice_statics_AddRef, + usbdevice_statics_Release, + /* IInspectable methods */ + usbdevice_statics_GetIids, + usbdevice_statics_GetRuntimeClassName, + usbdevice_statics_GetTrustLevel, + /* IUsbDeviceStatics methods */ + usbdevice_statics_GetDeviceSelector, + usbdevice_statics_GetDeviceSelectorGuidOnly, + usbdevice_statics_GetDeviceSelectorVidPidOnly, + usbdevice_statics_GetDeviceClassSelector, + usbdevice_statics_FromIdAsync, +}; + static struct usbdevice_statics usbdevice_statics = { {&factory_vtbl}, + {&usbdevice_statics_vtbl}, 1, };
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Needed for Lenovo Ready for Assistant. --- dlls/windows.devices.usb/usbdevice.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
diff --git a/dlls/windows.devices.usb/usbdevice.c b/dlls/windows.devices.usb/usbdevice.c index a43dda26d80..19f03ff547a 100644 --- a/dlls/windows.devices.usb/usbdevice.c +++ b/dlls/windows.devices.usb/usbdevice.c @@ -133,8 +133,31 @@ static HRESULT WINAPI usbdevice_statics_GetDeviceSelectorGuidOnly( IUsbDeviceSta static HRESULT WINAPI usbdevice_statics_GetDeviceSelectorVidPidOnly( IUsbDeviceStatics *iface, UINT32 vendor, UINT32 product, HSTRING *value ) { - FIXME( "iface %p, vendor %d, product %d, value %p stub!\n", iface, vendor, product, value ); - return E_NOTIMPL; + static const WCHAR *prefix = L"System.Devices.InterfaceClassGuid:="{DEE824EF-729B-4A0E-9C14-B7117D33A817}"" + L" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True" + L" AND System.DeviceInterface.WinUsb.UsbVendorId:="; + static const WCHAR *suffix = L" AND System.DeviceInterface.WinUsb.UsbProductId:="; + WCHAR *buffer; + int length; + HRESULT hr; + + TRACE( "iface %p, vendor %d, product %d, value %p.\n", iface, vendor, product, value ); + + if (!value) return E_INVALIDARG; + + length = _snwprintf( NULL, 0, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product ); + if (length < 0) return E_FAIL; + + buffer = (WCHAR *)malloc( (length + 1) * sizeof(WCHAR) ); + if (!buffer) return E_OUTOFMEMORY; + + _snwprintf( buffer, length + 1, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product ); + if (FAILED( hr = WindowsCreateString( buffer, length, value ) )) goto done; + + TRACE( "Returning value = %s\n", debugstr_hstring(*value) ); +done: + free( buffer ); + return hr; }
static HRESULT WINAPI usbdevice_statics_GetDeviceClassSelector( IUsbDeviceStatics *iface, IUsbDeviceClass *class, HSTRING *value )
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/windows.devices.usb/tests/usb.c | 56 +++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-)
diff --git a/dlls/windows.devices.usb/tests/usb.c b/dlls/windows.devices.usb/tests/usb.c index 347cfa29c1c..1899c24e95f 100644 --- a/dlls/windows.devices.usb/tests/usb.c +++ b/dlls/windows.devices.usb/tests/usb.c @@ -45,13 +45,40 @@ static void check_interface_( unsigned int line, void *obj, const IID *iid ) IUnknown_Release( unk ); }
+static HRESULT wine_GetDeviceSelectorVidPidOnly( UINT32 vendor, UINT32 product, HSTRING *value ) +{ + static const WCHAR *prefix = L"System.Devices.InterfaceClassGuid:="{DEE824EF-729B-4A0E-9C14-B7117D33A817}"" + L" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True" + L" AND System.DeviceInterface.WinUsb.UsbVendorId:="; + static const WCHAR *suffix = L" AND System.DeviceInterface.WinUsb.UsbProductId:="; + WCHAR *buffer; + int length; + HRESULT hr; + + if (!value) return E_INVALIDARG; + + length = _snwprintf( NULL, 0, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product ); + if (length < 0) return E_FAIL; + + buffer = (WCHAR *)malloc( (length + 1) * sizeof(WCHAR) ); + if (!buffer) return E_OUTOFMEMORY; + + _snwprintf( buffer, length + 1, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product ); + hr = WindowsCreateString( buffer, length, value ); + + free( buffer ); + return hr; +} + static void test_UsbDevicesStatics(void) { static const WCHAR *usbdevice_statics_name = L"Windows.Devices.Usb.UsbDevice"; IUsbDeviceStatics *usbdevice_statics; IActivationFactory *factory; - HSTRING str; + UINT32 vendor, product; + HSTRING str, wine_str; HRESULT hr; + INT32 res; LONG ref;
hr = WindowsCreateString( usbdevice_statics_name, wcslen( usbdevice_statics_name ), &str ); @@ -73,6 +100,33 @@ static void test_UsbDevicesStatics(void) hr = IActivationFactory_QueryInterface( factory, &IID_IUsbDeviceStatics, (void **)&usbdevice_statics ); ok( hr == S_OK, "got hr %#lx.\n", hr );
+ hr = IUsbDeviceStatics_GetDeviceSelectorVidPidOnly( usbdevice_statics, 5, 10, NULL ); + ok( hr == E_INVALIDARG, "got hr %#lx.\n", hr ); + + vendor = 20; + product = 23; + hr = IUsbDeviceStatics_GetDeviceSelectorVidPidOnly( usbdevice_statics, vendor, product, &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = wine_GetDeviceSelectorVidPidOnly( vendor, product, &wine_str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = WindowsCompareStringOrdinal( str, wine_str, &res ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + ok( !res, "got string %s.\n", debugstr_hstring(str) ); + WindowsDeleteString( str ); + WindowsDeleteString( wine_str ); + + vendor = 4294967195; /* Vendor = -101 */ + product = -1294967195; + hr = IUsbDeviceStatics_GetDeviceSelectorVidPidOnly( usbdevice_statics, vendor, product, &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = wine_GetDeviceSelectorVidPidOnly( vendor, product, &wine_str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = WindowsCompareStringOrdinal( str, wine_str, &res ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + ok( !res, "got string %s.\n", debugstr_hstring(str) ); + WindowsDeleteString( str ); + WindowsDeleteString( wine_str ); + ref = IUsbDeviceStatics_Release( usbdevice_statics ); ok( ref == 2, "got ref %ld.\n", ref ); ref = IActivationFactory_Release( factory );
Rémi Bernon (@rbernon) commented about include/windows.devices.usb.idl:
- runtimeclass UsbSetupPacket;
- declare {
interface Windows.Foundation.AsyncOperationCompletedHandler<Windows.Devices.Usb.UsbDevice *>;
interface Windows.Foundation.IAsyncOperation<Windows.Devices.Usb.UsbDevice *>;
- }
- [
contract(Windows.Foundation.UniversalApiContract, 1.0),
exclusiveto(Windows.Devices.Usb.UsbDevice),
uuid(5249b992-c456-44d5-ad5e-24f5a089f63b)
- ]
- interface IUsbDevice : IInspectable
requires Windows.Foundation.IClosable
- {
[overload("SendControlOutTransferAsync")] HRESULT SendControlOutTransferAsync(
```suggestion:-0+0 [overload("SendControlOutTransferAsync")] HRESULT SendControlOutTransferAsync( ```
Same for the other long functions with attributes.
Rémi Bernon (@rbernon) commented about dlls/windows.devices.usb/usbdevice.c:
{
- FIXME( "iface %p, vendor %d, product %d, value %p stub!\n", iface, vendor, product, value );
- return E_NOTIMPL;
- static const WCHAR *prefix = L"System.Devices.InterfaceClassGuid:="{DEE824EF-729B-4A0E-9C14-B7117D33A817}""
L" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True"
L" AND System.DeviceInterface.WinUsb.UsbVendorId:=";
- static const WCHAR *suffix = L" AND System.DeviceInterface.WinUsb.UsbProductId:=";
- WCHAR *buffer;
- int length;
- HRESULT hr;
- TRACE( "iface %p, vendor %d, product %d, value %p.\n", iface, vendor, product, value );
- if (!value) return E_INVALIDARG;
- length = _snwprintf( NULL, 0, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product );
```suggestion:-0+0 length = swprintf( NULL, 0, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product ); ```
Same for the other call below and in the tests.
Rémi Bernon (@rbernon) commented about dlls/windows.devices.usb/usbdevice.c:
static HRESULT WINAPI usbdevice_statics_GetDeviceSelectorVidPidOnly( IUsbDeviceStatics *iface, UINT32 vendor, UINT32 product, HSTRING *value ) {
- FIXME( "iface %p, vendor %d, product %d, value %p stub!\n", iface, vendor, product, value );
- return E_NOTIMPL;
- static const WCHAR *prefix = L"System.Devices.InterfaceClassGuid:="{DEE824EF-729B-4A0E-9C14-B7117D33A817}""
L" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True"
L" AND System.DeviceInterface.WinUsb.UsbVendorId:=";
- static const WCHAR *suffix = L" AND System.DeviceInterface.WinUsb.UsbProductId:=";
```suggestion:-3+0 static const WCHAR *format = L"System.Devices.InterfaceClassGuid:="{DEE824EF-729B-4A0E-9C14-B7117D33A817}"" L" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True" L" AND System.DeviceInterface.WinUsb.UsbVendorId:=%d" L" AND System.DeviceInterface.WinUsb.UsbProductId:=%d"; ```
Rémi Bernon (@rbernon) commented about dlls/windows.devices.usb/usbdevice.c:
- static const WCHAR *prefix = L"System.Devices.InterfaceClassGuid:="{DEE824EF-729B-4A0E-9C14-B7117D33A817}""
L" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True"
L" AND System.DeviceInterface.WinUsb.UsbVendorId:=";
- static const WCHAR *suffix = L" AND System.DeviceInterface.WinUsb.UsbProductId:=";
- WCHAR *buffer;
- int length;
- HRESULT hr;
- TRACE( "iface %p, vendor %d, product %d, value %p.\n", iface, vendor, product, value );
- if (!value) return E_INVALIDARG;
- length = _snwprintf( NULL, 0, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product );
- if (length < 0) return E_FAIL;
- buffer = (WCHAR *)malloc( (length + 1) * sizeof(WCHAR) );
You could probably use a static buffer with a large enough fixed size as the format string is known and as %d has a fixed maximum size, which would save the trouble of the allocation and having to pre-compute the length.
Rémi Bernon (@rbernon) commented about dlls/windows.devices.usb/tests/usb.c:
- HRESULT hr;
- if (!value) return E_INVALIDARG;
- length = _snwprintf( NULL, 0, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product );
- if (length < 0) return E_FAIL;
- buffer = (WCHAR *)malloc( (length + 1) * sizeof(WCHAR) );
- if (!buffer) return E_OUTOFMEMORY;
- _snwprintf( buffer, length + 1, L"%ls%d%ls%d", prefix, (INT32)vendor, suffix, (INT32)product );
- hr = WindowsCreateString( buffer, length, value );
- free( buffer );
- return hr;
+}
With the suggested changes in the previous commit I think this should be reduced down to a simple swprintf to a temp static buffer, I'm not sure it deserves a helper.
I understand the idea of checking against the exact Wine implementation, but I think that in general we're interested in the results, not how they are computed. So, copying Wine implementation into tests is probably not a good habit.