Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=21023 Signed-off-by: Zebediah Figura z.figura12@gmail.com --- dlls/setupapi/devinst.c | 45 +++++++++++++++-------------------- dlls/setupapi/tests/devinst.c | 39 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 26 deletions(-)
diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index e5d008fc83..1fc494617d 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -1426,6 +1426,7 @@ HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_da { struct device *device; HKEY key = INVALID_HANDLE_VALUE; + LONG l;
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d, inf_handle %p, inf_section %s.\n", devinfo, device_data, Scope, HwProfile, KeyType, InfHandle, debugstr_w(InfSectionName)); @@ -1453,7 +1454,12 @@ HKEY WINAPI SetupDiCreateDevRegKeyW(HDEVINFO devinfo, SP_DEVINFO_DATA *device_da switch (KeyType) { case DIREG_DEV: - key = SETUPDI_CreateDevKey(device); + if ((l = RegCreateKeyExW(device->key, DeviceParameters, 0, NULL, 0, + KEY_READ | KEY_WRITE, NULL, &key, NULL))) + { + key = INVALID_HANDLE_VALUE; + } + SetLastError(l); break; case DIREG_DRV: key = create_driver_key(device); @@ -3576,6 +3582,7 @@ HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, { struct device *device; HKEY key = INVALID_HANDLE_VALUE; + LONG l;
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d, access %#x.\n", devinfo, device_data, Scope, HwProfile, KeyType, samDesired); @@ -3604,7 +3611,9 @@ HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, switch (KeyType) { case DIREG_DEV: - key = SETUPDI_OpenDevKey(device, samDesired); + if ((l = RegOpenKeyExW(device->key, DeviceParameters, 0, samDesired, &key))) + key = INVALID_HANDLE_VALUE; + SetLastError(l); break; case DIREG_DRV: key = open_driver_key(device, samDesired); @@ -3615,24 +3624,6 @@ HKEY WINAPI SetupDiOpenDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data, return key; }
-static BOOL SETUPDI_DeleteDevKey(struct device *device) -{ - HKEY enumKey; - BOOL ret = FALSE; - LONG l; - - l = RegCreateKeyExW(HKEY_LOCAL_MACHINE, Enum, 0, NULL, 0, KEY_ALL_ACCESS, - NULL, &enumKey, NULL); - if (!l) - { - ret = RegDeleteTreeW(enumKey, device->instanceId); - RegCloseKey(enumKey); - } - else - SetLastError(l); - return ret; -} - /*********************************************************************** * SetupDiDeleteDevRegKey (SETUPAPI.@) */ @@ -3641,6 +3632,7 @@ BOOL WINAPI SetupDiDeleteDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_dat { struct device *device; BOOL ret = FALSE; + LONG l;
TRACE("devinfo %p, device_data %p, scope %d, profile %d, type %d.\n", devinfo, device_data, Scope, HwProfile, KeyType); @@ -3668,16 +3660,17 @@ BOOL WINAPI SetupDiDeleteDevRegKey(HDEVINFO devinfo, SP_DEVINFO_DATA *device_dat FIXME("unimplemented for scope %d\n", Scope); switch (KeyType) { - case DIREG_DEV: - ret = SETUPDI_DeleteDevKey(device); - break; case DIREG_DRV: ret = delete_driver_key(device); break; case DIREG_BOTH: - ret = SETUPDI_DeleteDevKey(device); - if (ret) - ret = delete_driver_key(device); + if (!(ret = delete_driver_key(device))) + break; + /* fall through */ + case DIREG_DEV: + l = RegDeleteKeyW(device->key, DeviceParameters); + SetLastError(l); + ret = !l; break; default: WARN("unknown KeyType %d\n", KeyType); diff --git a/dlls/setupapi/tests/devinst.c b/dlls/setupapi/tests/devinst.c index d46aa9b120..2657252c03 100644 --- a/dlls/setupapi/tests/devinst.c +++ b/dlls/setupapi/tests/devinst.c @@ -1030,6 +1030,8 @@ static void test_device_iface_detail(void)
static void test_device_key(void) { + static const char params_key_path[] = "System\CurrentControlSet\Enum\Root" + "\LEGACY_BOGUS\0000\Device Parameters"; static const char class_key_path[] = "System\CurrentControlSet\Control\Class" "\{6a55b5a4-3f65-11db-b704-0011955c2bdb}"; static const WCHAR bogus[] = {'S','y','s','t','e','m','\', @@ -1159,6 +1161,43 @@ todo_wine { ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError());
+ key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); + ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); +todo_wine + ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError()); + + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key); + ok(res == ERROR_FILE_NOT_FOUND, "Key should not exist.\n"); + + key = SetupDiCreateDevRegKeyA(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, NULL, NULL); + ok(key != INVALID_HANDLE_VALUE, "Got unexpected error %#x.\n", GetLastError()); + RegCloseKey(key); + + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key); + ok(!res, "Failed to open device key, error %u.\n", res); + res = RegSetValueExA(key, "foo", 0, REG_SZ, (BYTE *)"bar", sizeof("bar")); + ok(!res, "Failed to set value, error %u.\n", res); + RegCloseKey(key); + + key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); + ok(key != INVALID_HANDLE_VALUE, "Got unexpected error %#x.\n", GetLastError()); + size = sizeof(data); + res = RegQueryValueExA(key, "foo", NULL, NULL, (BYTE *)data, &size); + ok(!res, "Failed to get value, error %u.\n", res); + ok(!strcmp(data, "bar"), "Got wrong data %s.\n", data); + RegCloseKey(key); + + ret = SetupDiDeleteDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV); + ok(ret, "Got unexpected error %#x.\n", GetLastError()); + + key = SetupDiOpenDevRegKey(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ); + ok(key == INVALID_HANDLE_VALUE, "Expected failure.\n"); +todo_wine + ok(GetLastError() == ERROR_KEY_DOES_NOT_EXIST, "Got unexpected error %#x.\n", GetLastError()); + + res = RegOpenKeyA(HKEY_LOCAL_MACHINE, params_key_path, &key); + ok(res == ERROR_FILE_NOT_FOUND, "Key should not exist.\n"); + key = SetupDiCreateDevRegKeyW(set, &device, DICS_FLAG_GLOBAL, 0, DIREG_DRV, NULL, NULL); ok(key != INVALID_HANDLE_VALUE, "Failed to create device key, error %#x.\n", GetLastError()); RegCloseKey(key);