From: Vibhav Pant vibhavp@gmail.com
--- dlls/windows.devices.enumeration/Makefile.in | 1 + .../windows.devices.enumeration/information.c | 201 ++++++++++++++++++ dlls/windows.devices.enumeration/main.c | 31 ++- dlls/windows.devices.enumeration/private.h | 2 + .../tests/devices.c | 2 +- 5 files changed, 231 insertions(+), 6 deletions(-) create mode 100644 dlls/windows.devices.enumeration/information.c
diff --git a/dlls/windows.devices.enumeration/Makefile.in b/dlls/windows.devices.enumeration/Makefile.in index e6c1ef8ddfe..062a914e322 100644 --- a/dlls/windows.devices.enumeration/Makefile.in +++ b/dlls/windows.devices.enumeration/Makefile.in @@ -8,4 +8,5 @@ SOURCES = \ classes.idl \ collection.c \ event_handlers.c \ + information.c \ main.c \ diff --git a/dlls/windows.devices.enumeration/information.c b/dlls/windows.devices.enumeration/information.c new file mode 100644 index 00000000000..afff96c9894 --- /dev/null +++ b/dlls/windows.devices.enumeration/information.c @@ -0,0 +1,201 @@ +/* DeviceInformation implementation. + * + * Copyright 2025 Vibhav Pant + * + * 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 <roapi.h> + +#include <wine/debug.h> +#include <wine/rbtree.h> + +WINE_DEFAULT_DEBUG_CHANNEL(enumeration); + +/* DeviceInformation implementation for objects with kind DeviceInformationKind_DeviceInterface. */ +struct devinfo_DeviceInterface +{ + IDeviceInformation IDeviceInformation_iface; + LONG ref; +}; + +static inline struct devinfo_DeviceInterface *impl_DeviceInterface_from_IDeviceInformation( IDeviceInformation *iface ) +{ + return CONTAINING_RECORD( iface, struct devinfo_DeviceInterface, IDeviceInformation_iface ); +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_QueryInterface( IDeviceInformation *iface, REFIID iid, + void **out ) +{ + TRACE( "(%p, %s, %p)\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IDeviceInformation )) + { + IUnknown_AddRef( iface ); + *out = iface; + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG STDMETHODCALLTYPE devinfo_DeviceInterface_AddRef( IDeviceInformation *iface ) +{ + struct devinfo_DeviceInterface *impl; + + TRACE( "(%p)\n", iface ); + + impl = impl_DeviceInterface_from_IDeviceInformation( iface ); + return InterlockedIncrement( &impl->ref ); +} + +static ULONG STDMETHODCALLTYPE devinfo_DeviceInterface_Release( IDeviceInformation *iface ) +{ + struct devinfo_DeviceInterface *impl; + ULONG ref; + + TRACE( "(%p)\n", iface ); + + impl = impl_DeviceInterface_from_IDeviceInformation( iface ); + ref = InterlockedDecrement( &impl->ref ); + if (!ref) + free( impl ); + + return ref; +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_GetIids( IDeviceInformation *iface, + ULONG *iid_count, IID **iids ) +{ + FIXME( "(%p, %p, %p) stub!\n", iface, iid_count, iids ); + return E_NOTIMPL; +} + +static HRESULT WINAPI devinfo_DeviceInterface_GetRuntimeClassName( IDeviceInformation *iface, HSTRING *class_name ) +{ + const static WCHAR *name = RuntimeClass_Windows_Devices_Enumeration_DeviceInformation; + + TRACE( "(%p, %p)\n", iface, class_name ); + + return WindowsCreateString( name, wcslen( name ), class_name ); +} + +static HRESULT STDMETHODCALLTYPE device_information_GetTrustLevel( + IDeviceInformation *iface, TrustLevel *trust_level) +{ + FIXME("(%p, %p) stub!\n", iface, trust_level); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_get_Id( IDeviceInformation *iface, HSTRING *id ) +{ + FIXME( "(%p, %p) stub!\n", iface, id ); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_get_Name( IDeviceInformation *iface, HSTRING *name ) +{ + FIXME( "(%p, %p) stub!\n", iface, name ); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_get_IsEnabled( IDeviceInformation *iface, boolean *value ) +{ + FIXME( "(%p, %p) stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_IsDefault( IDeviceInformation *iface, boolean *value ) +{ + FIXME( "(%p, %p) stub!\n", iface, value ); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_get_EnclosureLocation( IDeviceInformation *iface, + IEnclosureLocation **location ) +{ + FIXME( "(%p, %p) stub!\n", iface, location ); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_get_Properties( IDeviceInformation *iface, + IMapView_HSTRING_IInspectable **properties ) +{ + FIXME( "(%p, %p) stub!\n", iface, properties ); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_Update( IDeviceInformation *iface, + IDeviceInformationUpdate *update ) +{ + FIXME( "(%p, %p) stub!\n", iface, update ); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE devinfo_DeviceInterface_GetThumbnailAsync( IDeviceInformation *iface, + IAsyncOperation_DeviceThumbnail **async ) +{ + FIXME( "(%p, %p) stub!\n", iface, async ); + return E_NOTIMPL; +} + +static HRESULT STDMETHODCALLTYPE +devinfo_DeviceInterface_GetGlyphThumbnailAsync( IDeviceInformation *iface, IAsyncOperation_DeviceThumbnail **async ) +{ + FIXME( "(%p, %p) stub!\n", iface, async ); + return E_NOTIMPL; +} + +static const struct IDeviceInformationVtbl devinfo_DeviceInterface_vtbl = { + /* IUnknown */ + devinfo_DeviceInterface_QueryInterface, + devinfo_DeviceInterface_AddRef, + devinfo_DeviceInterface_Release, + /* IInspectable */ + devinfo_DeviceInterface_GetIids, + devinfo_DeviceInterface_GetRuntimeClassName, + device_information_GetTrustLevel, + /* IDeviceInformation */ + devinfo_DeviceInterface_get_Id, + devinfo_DeviceInterface_get_Name, + devinfo_DeviceInterface_get_IsEnabled, + devinfo_DeviceInterface_IsDefault, + devinfo_DeviceInterface_get_EnclosureLocation, + devinfo_DeviceInterface_get_Properties, + devinfo_DeviceInterface_Update, + devinfo_DeviceInterface_GetThumbnailAsync, + devinfo_DeviceInterface_GetGlyphThumbnailAsync, +}; + +HRESULT deviceinformation_iface_create( IDeviceInformation **info ) +{ + struct devinfo_DeviceInterface *impl; + + impl = calloc( 1, sizeof( *impl ) ); + if (!impl) + return E_OUTOFMEMORY; + + impl->IDeviceInformation_iface.lpVtbl = &devinfo_DeviceInterface_vtbl; + impl->ref = 1; + *info = &impl->IDeviceInformation_iface; + return S_OK; +} diff --git a/dlls/windows.devices.enumeration/main.c b/dlls/windows.devices.enumeration/main.c index 0e34fafe3af..4ea1555c8fc 100644 --- a/dlls/windows.devices.enumeration/main.c +++ b/dlls/windows.devices.enumeration/main.c @@ -342,18 +342,39 @@ static HRESULT WINAPI findall_async( IUnknown *invoker, IUnknown *param, PROPVAR .iterable = &IID_IIterable_DeviceInformation, .iterator = &IID_IIterator_DeviceInformation, }; - HRESULT hr; IVectorView_DeviceInformation *view; + IDeviceInformation *device; + IVector_IInspectable *vector; + HRESULT hr = S_OK;
FIXME( "invoker %p, param %p, result %p semi-stub!\n", invoker, param, result );
- hr = vector_create( &iids, (void *)&view ); + hr = deviceinformation_iface_create( &device ); + if (FAILED( hr )) + return hr; + + hr = vector_create( &iids, (void *)&vector ); + if (FAILED( hr )) + { + IDeviceInformation_Release( device ); + return hr; + }
- if (SUCCEEDED( hr )) + hr = IVector_IInspectable_Append( vector, (IInspectable *)device ); + IDeviceInformation_Release( device ); + if (FAILED( hr )) { - result->vt = VT_UNKNOWN; - result->punkVal = (IUnknown *)view; + IVector_IInspectable_Release( vector ); + return hr; } + + hr = IVector_IInspectable_GetView( vector, (void *)&view ); + IVector_IInspectable_Release( vector ); + if (FAILED( hr )) + return hr; + + result->vt = VT_UNKNOWN; + result->punkVal = (IUnknown *)view; return hr; }
diff --git a/dlls/windows.devices.enumeration/private.h b/dlls/windows.devices.enumeration/private.h index f9e4f571a97..802163a2027 100644 --- a/dlls/windows.devices.enumeration/private.h +++ b/dlls/windows.devices.enumeration/private.h @@ -59,6 +59,8 @@ extern HRESULT async_operation_device_info_collection_result_create( IUnknown *invoker, IUnknown *param, async_operation_callback callback, IAsyncOperation_DeviceInformationCollection **out ); extern HRESULT vector_create( const struct vector_iids *iids, void **out ); +extern HRESULT deviceinformation_iface_create( IDeviceInformation **info ); + #define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \ static inline impl_type *impl_from( iface_type *iface ) \ { \ diff --git a/dlls/windows.devices.enumeration/tests/devices.c b/dlls/windows.devices.enumeration/tests/devices.c index e8b34e84ae3..64733cc5096 100644 --- a/dlls/windows.devices.enumeration/tests/devices.c +++ b/dlls/windows.devices.enumeration/tests/devices.c @@ -483,7 +483,7 @@ static void test_DeviceInformation( void ) UINT32 idx = 0, size = 0;
hr = IVectorView_DeviceInformation_get_Size( info_collection, &size ); - todo_wine ok( hr == S_OK, "got %#lx\n", hr ); + ok( hr == S_OK, "got %#lx\n", hr ); for (idx = 0; idx < size ;idx++) { IDeviceInformation *info;