From: Rémi Bernon <rbernon@codeweavers.com> --- dlls/cfgmgr32/cfgmgr32.c | 10 -------- dlls/cfgmgr32/cfgmgr32_private.h | 10 ++++++++ dlls/cfgmgr32/devobject.c | 44 +++++++++++++++----------------- 3 files changed, 30 insertions(+), 34 deletions(-) diff --git a/dlls/cfgmgr32/cfgmgr32.c b/dlls/cfgmgr32/cfgmgr32.c index af03d245559..651e873a81b 100644 --- a/dlls/cfgmgr32/cfgmgr32.c +++ b/dlls/cfgmgr32/cfgmgr32.c @@ -120,16 +120,6 @@ static LSTATUS open_device_classes_key( HKEY root, const WCHAR *key, REGSAM acce return open_key( root, path, access, open, hkey ); } -struct property -{ - BOOL ansi; - DEVPROPKEY key; - DEVPROPTYPE *type; - DWORD *reg_type; - void *buffer; - DWORD *size; -}; - static LSTATUS init_property( struct property *prop, const DEVPROPKEY *key, DEVPROPTYPE *type, void *buffer, DWORD *size ) { if (!key) return ERROR_INVALID_PARAMETER; diff --git a/dlls/cfgmgr32/cfgmgr32_private.h b/dlls/cfgmgr32/cfgmgr32_private.h index 0aad9a3f247..118be9c1d0d 100644 --- a/dlls/cfgmgr32/cfgmgr32_private.h +++ b/dlls/cfgmgr32/cfgmgr32_private.h @@ -49,3 +49,13 @@ static inline const char *debugstr_DEVPROPCOMPKEY( const DEVPROPCOMPKEY *key ) return wine_dbg_sprintf( "{%s, %d, %s}", debugstr_DEVPROPKEY( &key->Key ), key->Store, debugstr_w( key->LocaleName ) ); } + +struct property +{ + BOOL ansi; + DEVPROPKEY key; + DEVPROPTYPE *type; + DWORD *reg_type; + void *buffer; + DWORD *size; +}; diff --git a/dlls/cfgmgr32/devobject.c b/dlls/cfgmgr32/devobject.c index 72a84448f70..1a13dd9d525 100644 --- a/dlls/cfgmgr32/devobject.c +++ b/dlls/cfgmgr32/devobject.c @@ -332,6 +332,17 @@ static BOOL devprop_filters_validate( const DEVPROP_FILTER_EXPRESSION *filters, return TRUE; } +static HRESULT dev_get_device_interface_property( HDEVINFO set, SP_DEVICE_INTERFACE_DATA *iface_data, struct property *prop ) +{ + if (SetupDiGetDeviceInterfacePropertyW( set, iface_data, &prop->key, prop->type, NULL, 0, prop->size, 0 )) return S_OK; + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return S_OK; + + if (!(prop->buffer = malloc( *prop->size ))) return E_OUTOFMEMORY; + if (SetupDiGetDeviceInterfacePropertyW( set, iface_data, &prop->key, prop->type, prop->buffer, *prop->size, prop->size, 0 )) return S_OK; + free( prop->buffer ); + return HRESULT_FROM_WIN32( GetLastError() ); +} + static HRESULT get_property_compare_keys( const DEVPROPKEY *keys, ULONG keys_len, const DEVPROPCOMPKEY **comp_keys, ULONG *comp_keys_len ) { if (!(*comp_keys_len = keys_len)) return S_OK; @@ -361,38 +372,23 @@ static HRESULT dev_object_iface_get_props( HDEVINFO set, SP_DEVICE_INTERFACE_DAT DEVPROPERTY *properties, ULONG *properties_len ) { HRESULT hr = S_OK; - DWORD i = 0; + DWORD i; for (i = 0; i < keys_len; i++) { - const DEVPROPKEY *key = &keys[i].Key; - DWORD req = 0, size; + DWORD size = 0; DEVPROPTYPE type; - BYTE *buf; - - if (SetupDiGetDeviceInterfacePropertyW( set, iface_data, key, &type, NULL, 0, &req, 0 ) - || GetLastError() != ERROR_INSUFFICIENT_BUFFER) + struct property prop = { - devproperty_init( properties + i, key, DEVPROP_TYPE_EMPTY, 0, NULL ); - continue; - } + .key = keys[i].Key, + .type = &type, + .size = &size, + }; - size = req; - if (!(buf = calloc( 1, size ))) - { - hr = E_OUTOFMEMORY; - goto done; - } - if (!SetupDiGetDeviceInterfacePropertyW( set, iface_data, key, &type, buf, size, &req, 0 )) - { - hr = HRESULT_FROM_WIN32( GetLastError() ); - free( buf ); - goto done; - } - devproperty_init( properties + i, key, type, size, buf ); + if (FAILED(hr = dev_get_device_interface_property( set, iface_data, &prop ))) break; + devproperty_init( properties + i, &prop.key, *prop.type, *prop.size, prop.buffer ); } -done: *properties_len = i; return hr; } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10173