setupapi: Create the registry value if it doesn't exist in append_multi_sz_value().

This commit is contained in:
Zebediah Figura 2023-02-06 19:43:08 -06:00 committed by Alexandre Julliard
parent 0ab56b88df
commit 38e36e8fda
2 changed files with 24 additions and 8 deletions

View file

@ -233,8 +233,27 @@ static bool append_multi_sz_value( HKEY hkey, const WCHAR *value, const WCHAR *s
{ {
DWORD size, type, total; DWORD size, type, total;
WCHAR *buffer, *p; WCHAR *buffer, *p;
LONG ret;
if ((ret = RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )))
{
if (ret != ERROR_FILE_NOT_FOUND)
{
ERR( "failed to query value %s, error %lu\n", debugstr_w(value), ret );
SetLastError( ret );
return false;
}
if ((ret = RegSetValueExW( hkey, value, 0, REG_MULTI_SZ, (BYTE *)strings, str_size * sizeof(WCHAR) )))
{
ERR( "failed to set value %s, error %lu\n", debugstr_w(value), ret );
SetLastError( ret );
return false;
}
return true;
}
if (RegQueryValueExW( hkey, value, NULL, &type, NULL, &size )) return true;
if (type != REG_MULTI_SZ) if (type != REG_MULTI_SZ)
{ {
WARN( "value %s exists but has wrong type %#lx\n", debugstr_w(value), type ); WARN( "value %s exists but has wrong type %#lx\n", debugstr_w(value), type );

View file

@ -2332,13 +2332,10 @@ static void test_append_reg(void)
ok(!l, "Got error %lu.\n", l); ok(!l, "Got error %lu.\n", l);
size = sizeof(value); size = sizeof(value);
l = RegQueryValueExA(key, "value", NULL, &type, (BYTE *)value, &size); l = RegQueryValueExA(key, "value", NULL, &type, (BYTE *)value, &size);
todo_wine ok(!l, "Got error %lu.\n", l); ok(!l, "Got error %lu.\n", l);
if (!l) ok(type == REG_MULTI_SZ, "Got type %#lx.\n", type);
{ ok(size == sizeof("data\0"), "Got size %lu.\n", size);
ok(type == REG_MULTI_SZ, "Got type %#lx.\n", type); ok(!memcmp(value, "data\0", size), "Got data %s.\n", debugstr_an(value, size));
ok(size == sizeof("data\0"), "Got size %lu.\n", size);
ok(!memcmp(value, "data\0", size), "Got data %s.\n", debugstr_an(value, size));
}
/* Key exists and already has a value. */ /* Key exists and already has a value. */