Commit dca175b2 authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

setupapi: Don't use the devnode to allocate driver keys.

The devnode is a local handle, but driver keys should be unique to the device. (Note that MSDN, confusingly, refers to this number as a "device instance ID".) Signed-off-by: 's avatarZebediah Figura <z.figura12@gmail.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent e26f8464
......@@ -527,7 +527,9 @@ static HKEY create_driver_key(struct device *device)
static const WCHAR formatW[] = {'%','0','4','u',0};
static const WCHAR slash[] = { '\\',0 };
HKEY class_key, key;
unsigned int i = 0;
WCHAR path[50];
DWORD dispos;
LONG l;
if ((key = open_driver_key(device, KEY_READ | KEY_WRITE)) != INVALID_HANDLE_VALUE)
......@@ -543,13 +545,21 @@ static HKEY create_driver_key(struct device *device)
SETUPDI_GuidToString(&device->class, path);
strcatW(path, slash);
sprintfW(path + strlenW(path), formatW, device->devnode);
if (!(l = RegCreateKeyExW(class_key, path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &key, NULL)))
/* Allocate a new driver key, by finding the first integer value that's not
* already taken. */
for (;;)
{
sprintfW(path + 39, formatW, i++);
if ((l = RegCreateKeyExW(class_key, path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &key, &dispos)))
break;
else if (dispos == REG_CREATED_NEW_KEY)
{
RegSetValueExW(device->key, Driver, 0, REG_SZ, (BYTE *)path, strlenW(path) * sizeof(WCHAR));
RegCloseKey(class_key);
return key;
}
RegCloseKey(key);
}
ERR("Failed to create driver key, error %u.\n", l);
RegCloseKey(class_key);
SetLastError(l);
......
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