Commit 8c12672b authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

setupapi: Handle error translation in SetupDiCreateDevRegKey().

parent 922bc932
...@@ -542,25 +542,24 @@ static LONG open_driver_key(struct device *device, REGSAM access, HKEY *key) ...@@ -542,25 +542,24 @@ static LONG open_driver_key(struct device *device, REGSAM access, HKEY *key)
return l; return l;
} }
static HKEY create_driver_key(struct device *device) static LONG create_driver_key(struct device *device, HKEY *key)
{ {
static const WCHAR formatW[] = {'%','0','4','u',0}; static const WCHAR formatW[] = {'%','0','4','u',0};
static const WCHAR slash[] = { '\\',0 }; static const WCHAR slash[] = { '\\',0 };
HKEY class_key, key;
unsigned int i = 0; unsigned int i = 0;
WCHAR path[50]; WCHAR path[50];
HKEY class_key;
DWORD dispos; DWORD dispos;
LONG l; LONG l;
if (!open_driver_key(device, KEY_READ | KEY_WRITE, &key)) if (!open_driver_key(device, KEY_READ | KEY_WRITE, key))
return key; return ERROR_SUCCESS;
if ((l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ControlClass, 0, NULL, 0, if ((l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, ControlClass, 0, NULL, 0,
KEY_CREATE_SUB_KEY, NULL, &class_key, NULL))) KEY_CREATE_SUB_KEY, NULL, &class_key, NULL)))
{ {
ERR("Failed to open driver class root key, error %u.\n", l); ERR("Failed to open driver class root key, error %u.\n", l);
SetLastError(l); return l;
return INVALID_HANDLE_VALUE;
} }
SETUPDI_GuidToString(&device->class, path); SETUPDI_GuidToString(&device->class, path);
...@@ -570,20 +569,19 @@ static HKEY create_driver_key(struct device *device) ...@@ -570,20 +569,19 @@ static HKEY create_driver_key(struct device *device)
for (;;) for (;;)
{ {
sprintfW(path + 39, formatW, i++); sprintfW(path + 39, formatW, i++);
if ((l = RegCreateKeyExW(class_key, path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &key, &dispos))) if ((l = RegCreateKeyExW(class_key, path, 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, key, &dispos)))
break; break;
else if (dispos == REG_CREATED_NEW_KEY) else if (dispos == REG_CREATED_NEW_KEY)
{ {
RegSetValueExW(device->key, Driver, 0, REG_SZ, (BYTE *)path, strlenW(path) * sizeof(WCHAR)); RegSetValueExW(device->key, Driver, 0, REG_SZ, (BYTE *)path, strlenW(path) * sizeof(WCHAR));
RegCloseKey(class_key); RegCloseKey(class_key);
return key; return ERROR_SUCCESS;
} }
RegCloseKey(key); RegCloseKey(*key);
} }
ERR("Failed to create driver key, error %u.\n", l); ERR("Failed to create driver key, error %u.\n", l);
RegCloseKey(class_key); RegCloseKey(class_key);
SetLastError(l); return l;
return INVALID_HANDLE_VALUE;
} }
static LONG delete_driver_key(struct device *device) static LONG delete_driver_key(struct device *device)
...@@ -1449,23 +1447,21 @@ HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_da ...@@ -1449,23 +1447,21 @@ HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_da
switch (KeyType) switch (KeyType)
{ {
case DIREG_DEV: case DIREG_DEV:
if ((l = RegCreateKeyExW(device->key, DeviceParameters, 0, NULL, 0, l = RegCreateKeyExW(device->key, DeviceParameters, 0, NULL, 0,
KEY_READ | KEY_WRITE, NULL, &key, NULL))) KEY_READ | KEY_WRITE, NULL, &key, NULL);
{
key = INVALID_HANDLE_VALUE;
}
SetLastError(l);
break; break;
case DIREG_DRV: case DIREG_DRV:
key = create_driver_key(device); l = create_driver_key(device, &key);
break; break;
default: default:
WARN("unknown KeyType %d\n", KeyType); FIXME("Unhandled type %#x.\n", KeyType);
l = ERROR_CALL_NOT_IMPLEMENTED;
} }
if (InfHandle) if (InfHandle)
SetupInstallFromInfSectionW(NULL, InfHandle, InfSectionName, SPINST_ALL, SetupInstallFromInfSectionW(NULL, InfHandle, InfSectionName, SPINST_ALL,
NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, devinfo, device_data); NULL, NULL, SP_COPY_NEWER_ONLY, NULL, NULL, devinfo, device_data);
return key; SetLastError(l);
return l ? INVALID_HANDLE_VALUE : key;
} }
/*********************************************************************** /***********************************************************************
......
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