Commit 1fa7782c authored by Zhiyi Zhang's avatar Zhiyi Zhang Committed by Alexandre Julliard

setupapi: Check registered device duplicate in SetupDiCreateDeviceInfo().

parent 7876234e
...@@ -1510,6 +1510,8 @@ BOOL WINAPI SetupDiCreateDeviceInfoW(HDEVINFO devinfo, const WCHAR *name, const ...@@ -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 ...@@ -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) ...@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment