setupapi: Check registered device duplicate in SetupDiCreateDeviceInfo().
Signed-off-by: Zhiyi Zhang <zzhang@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
7876234e3a
commit
1fa7782c08
|
@ -1510,6 +1510,8 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO devinfo, const WCHAR *name, const
|
||||||
{
|
{
|
||||||
WCHAR id[MAX_DEVICE_ID_LEN];
|
WCHAR id[MAX_DEVICE_ID_LEN];
|
||||||
struct DeviceInfoSet *set;
|
struct DeviceInfoSet *set;
|
||||||
|
HKEY enum_hkey;
|
||||||
|
HKEY instance_hkey;
|
||||||
struct device *device;
|
struct device *device;
|
||||||
|
|
||||||
TRACE("devinfo %p, name %s, class %s, description %s, hwnd %p, flags %#x, device_data %p.\n",
|
TRACE("devinfo %p, name %s, class %s, description %s, hwnd %p, flags %#x, device_data %p.\n",
|
||||||
|
@ -1570,6 +1572,18 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO devinfo, const WCHAR *name, const
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* Check if instance is already in registry */
|
||||||
|
RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_READ, NULL, &enum_hkey, NULL);
|
||||||
|
if (!RegOpenKeyExW(enum_hkey, name, 0, KEY_READ, &instance_hkey))
|
||||||
|
{
|
||||||
|
RegCloseKey(instance_hkey);
|
||||||
|
RegCloseKey(enum_hkey);
|
||||||
|
SetLastError(ERROR_DEVINST_ALREADY_EXISTS);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
RegCloseKey(enum_hkey);
|
||||||
|
|
||||||
|
/* Check if instance is already in set */
|
||||||
strcpyW(id, name);
|
strcpyW(id, name);
|
||||||
LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry)
|
LIST_FOR_EACH_ENTRY(device, &set->devices, struct device, entry)
|
||||||
{
|
{
|
||||||
|
|
|
@ -358,9 +358,9 @@ static void test_device_info(void)
|
||||||
|
|
||||||
set = SetupDiCreateDeviceInfoList(&guid, NULL);
|
set = SetupDiCreateDeviceInfoList(&guid, NULL);
|
||||||
ret = SetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid, NULL, NULL, 0, &device);
|
ret = SetupDiCreateDeviceInfoA(set, "Root\\LEGACY_BOGUS\\0000", &guid, NULL, NULL, 0, &device);
|
||||||
todo_wine ok(!ret, "Expect failure\n");
|
ok(!ret, "Expect failure\n");
|
||||||
todo_wine ok(GetLastError() == ERROR_DEVINST_ALREADY_EXISTS, "Got error %#x\n", GetLastError());
|
ok(GetLastError() == ERROR_DEVINST_ALREADY_EXISTS, "Got error %#x\n", GetLastError());
|
||||||
todo_wine check_device_info(set, 0, NULL, NULL);
|
check_device_info(set, 0, NULL, NULL);
|
||||||
SetupDiDestroyDeviceInfoList(set);
|
SetupDiDestroyDeviceInfoList(set);
|
||||||
|
|
||||||
set = SetupDiGetClassDevsA(&guid, NULL, NULL, 0);
|
set = SetupDiGetClassDevsA(&guid, NULL, NULL, 0);
|
||||||
|
|
Loading…
Reference in New Issue