Use SetupDiGetDeviceInterfacePropertyW to retrieve interface property values.
-- v2: cfgmgr32/test: Add additional tests for CM_Get_Device_Interface_PropertyW. cfgmgr32: Implement CM_Get_Device_Interface_PropertyW for all property keys.
From: Vibhav Pant vibhavp@gmail.com
--- dlls/cfgmgr32/main.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)
diff --git a/dlls/cfgmgr32/main.c b/dlls/cfgmgr32/main.c index fbff2c2fbf9..590966268fa 100644 --- a/dlls/cfgmgr32/main.c +++ b/dlls/cfgmgr32/main.c @@ -255,7 +255,6 @@ CONFIGRET WINAPI CM_Get_Device_Interface_PropertyW( LPCWSTR device_interface, co ULONG *property_buffer_size, ULONG flags ) { SP_DEVICE_INTERFACE_DATA iface = {sizeof(iface)}; - SP_DEVINFO_DATA device = { sizeof(device) }; HDEVINFO set; DWORD err; BOOL ret; @@ -268,12 +267,6 @@ CONFIGRET WINAPI CM_Get_Device_Interface_PropertyW( LPCWSTR device_interface, co if (*property_buffer_size && !property_buffer) return CR_INVALID_POINTER; if (flags) return CR_INVALID_FLAG;
- if (memcmp( property_key, &DEVPKEY_Device_InstanceId, sizeof(*property_key) )) - { - FIXME( "property %s\%lx.\n", debugstr_guid( &property_key->fmtid ), property_key->pid ); - return CR_NO_SUCH_VALUE; - } - set = SetupDiCreateDeviceInfoListExW( NULL, NULL, NULL, NULL ); if (set == INVALID_HANDLE_VALUE) return CR_OUT_OF_MEMORY; if (!SetupDiOpenDeviceInterfaceW( set, device_interface, 0, &iface )) @@ -282,17 +275,20 @@ CONFIGRET WINAPI CM_Get_Device_Interface_PropertyW( LPCWSTR device_interface, co TRACE( "No interface %s, err %lu.\n", debugstr_w( device_interface ), GetLastError()); return CR_NO_SUCH_DEVICE_INTERFACE; } - if (!SetupDiEnumDeviceInfo( set, 0, &device )) + + ret = SetupDiGetDeviceInterfacePropertyW( set, &iface, property_key, property_type, property_buffer, + *property_buffer_size, property_buffer_size, 0 ); + err = ret ? 0 : GetLastError(); + SetupDiDestroyDeviceInfoList( set ); + switch (err) { - SetupDiDestroyDeviceInfoList( set ); + case ERROR_SUCCESS: + return CR_SUCCESS; + case ERROR_INSUFFICIENT_BUFFER: + return CR_BUFFER_SMALL; + case ERROR_NOT_FOUND: + return CR_NO_SUCH_VALUE; + default: return CR_FAILURE; } - ret = SetupDiGetDeviceInstanceIdW( set, &device, (WCHAR *)property_buffer, *property_buffer_size / sizeof(WCHAR), - property_buffer_size ); - err = ret ? 0 : GetLastError(); - SetupDiDestroyDeviceInfoList( set ); - *property_type = DEVPROP_TYPE_STRING; - *property_buffer_size *= sizeof(WCHAR); - if (!err) return CR_SUCCESS; - return err == ERROR_INSUFFICIENT_BUFFER ? CR_BUFFER_SMALL : CR_FAILURE; }
From: Vibhav Pant vibhavp@gmail.com
--- dlls/cfgmgr32/tests/cfgmgr32.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/dlls/cfgmgr32/tests/cfgmgr32.c b/dlls/cfgmgr32/tests/cfgmgr32.c index 95f64698733..df477d2098e 100644 --- a/dlls/cfgmgr32/tests/cfgmgr32.c +++ b/dlls/cfgmgr32/tests/cfgmgr32.c @@ -370,6 +370,7 @@ static void test_CM_Get_Device_Interface_List(void) SP_DEVICE_INTERFACE_DETAIL_DATA_W *iface_data; SP_DEVINFO_DATA device = { sizeof(device) }; WCHAR instance_id[256], expected_id[256]; + DEVPROPKEY zero_key = {{0}, 0}; unsigned int count, count2; char *buffera, *pa; WCHAR *buffer, *p; @@ -415,6 +416,8 @@ static void test_CM_Get_Device_Interface_List(void) p = buffer; while (*p) { + DEVPROP_BOOLEAN val = DEVPROP_FALSE; + set = SetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL); ok(set != INVALID_HANDLE_VALUE, "got %p.\n", set); bret = SetupDiOpenDeviceInterfaceW(set, p, 0, &iface); @@ -466,6 +469,18 @@ static void test_CM_Get_Device_Interface_List(void) ok(!ret, "got %#lx.\n", ret); ok(type == DEVPROP_TYPE_STRING, "got type %#lx.\n", type); ok(!wcsicmp(instance_id, expected_id), "got %s, expected %s.\n", debugstr_w(instance_id), debugstr_w(expected_id)); + + type = 0xdeadbeef; + size = sizeof(val); + ret = CM_Get_Device_Interface_PropertyW(p, &DEVPKEY_DeviceInterface_Enabled, &type, (BYTE *)&val, &size, 0); + ok(!ret, "got %#lx.\n", ret); + ok(type == DEVPROP_TYPE_BOOLEAN, "got type %#lx.\n", type); + ok(size == sizeof(val), "got size %lu.\n", size); + ok(val == DEVPROP_TRUE, "got val %d.\n", val); + + size = 0; + ret = CM_Get_Device_Interface_PropertyW(p, &zero_key, &type, NULL, &size, 0); + ok(ret == CR_NO_SUCH_VALUE, "got %#lx.\n", ret); p += wcslen(p) + 1; ++count; }
This looks pretty trivial, but it would be nice to have a test for it.
I have added additional tests with a non-existent `DEVPROPKEY` value and `DEVPKEY_Interface_Enabled`.
I'd suggest to add a trivial test for SetupDiGetDeviceInterfacePropertyW() with nonexistent property checking error code and then fix 'err =' in a way it returns CR_NO_SUCH_VALUE (probably, depending on the test) and CR_FAILURE for all the other errors.
Addressed in the latest revision, thanks.
This merge request was approved by Paul Gofman.