Needed for Lenovo Ready for Assistant.
-- v3: windows.devices.usb/tests: Add IUsbDeviceStatics::GetDeviceSelectorVidPidOnly() tests. windows.devices.usb: Implement IUsbDeviceStatics::GetDeviceSelectorVidPidOnly(). windows.devices.usb: Add IUsbDeviceStatics stub interface. windows.devices.usb: Add stub DLL. include: Add windows.devices.usb.idl file. include: Add support for IAsyncOperation parameterized type IBuffer. include: Add support for IAsyncOperation UINT32.
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 | 177 ++++++++++++++++++++++++++++++++ 2 files changed, 178 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..40d4312d9de --- /dev/null +++ b/include/windows.devices.usb.idl @@ -0,0 +1,177 @@ +/* + * 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 70138a7566b..a43d3eac387 100644 --- a/configure.ac +++ b/configure.ac @@ -3143,6 +3143,8 @@ WINE_CONFIG_MAKEFILE(dlls/windows.devices.bluetooth) WINE_CONFIG_MAKEFILE(dlls/windows.devices.bluetooth/tests) WINE_CONFIG_MAKEFILE(dlls/windows.devices.enumeration) WINE_CONFIG_MAKEFILE(dlls/windows.devices.enumeration/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..a6ca03f6f17 --- /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( usb_device_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..e650a1d138d --- /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 *usb_device_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..938014ae8fe --- /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 *usb_device_statics_name = L"Windows.Devices.Usb.UsbDevice"; + IActivationFactory *factory; + HSTRING str; + HRESULT hr; + LONG ref; + + hr = WindowsCreateString( usb_device_statics_name, wcslen( usb_device_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( usb_device_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..e137055cf9c --- /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 usb_device_statics +{ + IActivationFactory IActivationFactory_iface; + LONG ref; +}; + +static inline struct usb_device_statics *impl_from_IActivationFactory( IActivationFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct usb_device_statics, IActivationFactory_iface ); +} + +static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) +{ + struct usb_device_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 usb_device_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 usb_device_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 usb_device_statics usb_device_statics = +{ + {&factory_vtbl}, + 1, +}; + +IActivationFactory *usb_device_factory = &usb_device_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 e650a1d138d..ad1af114737 100644 --- a/dlls/windows.devices.usb/private.h +++ b/dlls/windows.devices.usb/private.h @@ -37,4 +37,42 @@
extern IActivationFactory *usb_device_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 938014ae8fe..5e6f3be6d31 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 *usb_device_statics_name = L"Windows.Devices.Usb.UsbDevice"; + IUsbDeviceStatics *usb_device_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 **)&usb_device_statics ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + + ref = IUsbDeviceStatics_Release( usb_device_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 e137055cf9c..62c12d7c3e7 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 usb_device_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( usb_device_statics, IUsbDeviceStatics, struct usb_device_statics, IActivationFactory_iface ) + +static HRESULT WINAPI usb_device_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 usb_device_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 usb_device_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 usb_device_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 usb_device_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 usb_device_statics_vtbl = +{ + usb_device_statics_QueryInterface, + usb_device_statics_AddRef, + usb_device_statics_Release, + /* IInspectable methods */ + usb_device_statics_GetIids, + usb_device_statics_GetRuntimeClassName, + usb_device_statics_GetTrustLevel, + /* IUsbDeviceStatics methods */ + usb_device_statics_GetDeviceSelector, + usb_device_statics_GetDeviceSelectorGuidOnly, + usb_device_statics_GetDeviceSelectorVidPidOnly, + usb_device_statics_GetDeviceClassSelector, + usb_device_statics_FromIdAsync, +}; + static struct usb_device_statics usb_device_statics = { {&factory_vtbl}, + {&usb_device_statics_vtbl}, 1, };
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
Needed for Lenovo Ready for Assistant. --- dlls/windows.devices.usb/usbdevice.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/dlls/windows.devices.usb/usbdevice.c b/dlls/windows.devices.usb/usbdevice.c index 62c12d7c3e7..a42281fbe48 100644 --- a/dlls/windows.devices.usb/usbdevice.c +++ b/dlls/windows.devices.usb/usbdevice.c @@ -133,8 +133,22 @@ static HRESULT WINAPI usb_device_statics_GetDeviceSelectorGuidOnly( IUsbDeviceSt static HRESULT WINAPI usb_device_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 *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"; + WCHAR buffer[254 + 20]; + HRESULT hr; + + TRACE( "iface %p, vendor %d, product %d, value %p.\n", iface, vendor, product, value ); + + if (!value) return E_INVALIDARG; + + swprintf( buffer, ARRAYSIZE(buffer), format, (INT32)vendor, (INT32)product ); + hr = WindowsCreateString( buffer, wcslen(buffer), value ); + + TRACE( "Returning value = %s\n", debugstr_hstring(*value) ); + return hr; }
static HRESULT WINAPI usb_device_statics_GetDeviceClassSelector( IUsbDeviceStatics *iface, IUsbDeviceClass *class, HSTRING *value )
From: Mohamad Al-Jaf mohamadaljaf@gmail.com
--- dlls/windows.devices.usb/tests/usb.c | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/dlls/windows.devices.usb/tests/usb.c b/dlls/windows.devices.usb/tests/usb.c index 5e6f3be6d31..bf6e759e14d 100644 --- a/dlls/windows.devices.usb/tests/usb.c +++ b/dlls/windows.devices.usb/tests/usb.c @@ -47,11 +47,18 @@ static void check_interface_( unsigned int line, void *obj, const IID *iid )
static void test_UsbDevicesStatics(void) { + 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"; static const WCHAR *usb_device_statics_name = L"Windows.Devices.Usb.UsbDevice"; IUsbDeviceStatics *usb_device_statics; IActivationFactory *factory; - HSTRING str; + UINT32 vendor, product; + WCHAR buffer[254 + 20]; + HSTRING str, wine_str; HRESULT hr; + INT32 res; LONG ref;
hr = WindowsCreateString( usb_device_statics_name, wcslen( usb_device_statics_name ), &str ); @@ -73,6 +80,35 @@ static void test_UsbDevicesStatics(void) hr = IActivationFactory_QueryInterface( factory, &IID_IUsbDeviceStatics, (void **)&usb_device_statics ); ok( hr == S_OK, "got hr %#lx.\n", hr );
+ hr = IUsbDeviceStatics_GetDeviceSelectorVidPidOnly( usb_device_statics, 5, 10, NULL ); + ok( hr == E_INVALIDARG, "got hr %#lx.\n", hr ); + + vendor = 20; + product = 23; + hr = IUsbDeviceStatics_GetDeviceSelectorVidPidOnly( usb_device_statics, vendor, product, &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + swprintf( buffer, ARRAYSIZE(buffer), format, (INT32)vendor, (INT32)product ); + hr = WindowsCreateString( buffer, wcslen(buffer), &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( usb_device_statics, vendor, product, &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + swprintf( buffer, ARRAYSIZE(buffer), format, (INT32)vendor, (INT32)product ); + hr = WindowsCreateString( buffer, wcslen(buffer), &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( usb_device_statics ); ok( ref == 2, "got ref %ld.\n", ref ); ref = IActivationFactory_Release( factory );
**v3** - Rebased to resolve merge conflict.
This merge request was approved by Rémi Bernon.