atl: Add support for binary values in IRegistrar.

This commit is contained in:
Damjan Jovanovic 2010-11-24 11:10:13 +02:00 committed by Alexandre Julliard
parent d2a221d2b5
commit cd4b9c1127
2 changed files with 52 additions and 0 deletions

View File

@ -299,6 +299,41 @@ static HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOO
}
break;
}
case 'b': {
BYTE *bytes;
DWORD count;
DWORD i;
hres = get_word(&iter, buf);
if(FAILED(hres))
break;
count = (lstrlenW(buf->str) + 1) / 2;
bytes = HeapAlloc(GetProcessHeap(), 0, count);
if(bytes == NULL) {
hres = E_OUTOFMEMORY;
break;
}
for(i = 0; i < count && buf->str[2*i]; i++) {
WCHAR digits[3];
if(!isxdigitW(buf->str[2*i]) || !isxdigitW(buf->str[2*i + 1])) {
hres = E_FAIL;
break;
}
digits[0] = buf->str[2*i];
digits[1] = buf->str[2*i + 1];
digits[2] = 0;
bytes[i] = (BYTE) strtoulW(digits, NULL, 16);
}
if(SUCCEEDED(hres)) {
lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_BINARY,
bytes, count);
if(lres != ERROR_SUCCESS) {
WARN("Could not set value of key: 0x%08x\n", lres);
hres = HRESULT_FROM_WIN32(lres);
}
}
HeapFree(GetProcessHeap(), 0, bytes);
break;
}
default:
WARN("Wrong resource type: %s\n", debugstr_w(buf->str));
hres = DISP_E_EXCEPTION;

View File

@ -47,6 +47,8 @@ static const char textA[] =
" val 'dword_unquoted_dec' = d 1 \n"
" val 'dword_quoted_hex' = d '0xA' \n"
" val 'dword_unquoted_hex' = d 0xA \n"
" val 'binary_quoted' = b 'deadbeef' \n"
" val 'binary_unquoted' = b deadbeef \n"
" } \n"
"}";
@ -72,6 +74,7 @@ static void test_registrar(void)
DWORD size;
LONG lret;
HKEY key;
BYTE bytes[4];
MultiByteToWideChar(CP_ACP, 0, textA, -1, textW, count);
hr = IRegistrar_StringRegister(registrar, textW);
@ -100,6 +103,20 @@ static void test_registrar(void)
ok(lret == ERROR_SUCCESS, "RegQueryValueExA failed, error %d\n", lret);
ok(dword == 1, "quoted dec is not supposed to be %d\n", dword);
size = 4;
lret = RegQueryValueExA(key, "binary_quoted", NULL, NULL, bytes, &size);
ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret);
ok(bytes[0] = 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
"binary quoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
size = 4;
lret = RegQueryValueExA(key, "binary_unquoted", NULL, NULL, bytes, &size);
ok(lret == ERROR_SUCCESS, "RegQueryValueA, failed, error %d\n", lret);
ok(bytes[0] = 0xde && bytes[1] == 0xad && bytes[2] == 0xbe && bytes[3] == 0xef,
"binary unquoted value was not preserved (it's 0x%02X%02X%02X%02X)\n",
0xff & bytes[0], 0xff & bytes[1], 0xff & bytes[2], 0xff & bytes[3]);
hr = IRegistrar_StringUnregister(registrar, textW);
ok(SUCCEEDED(hr), "IRegistar_StringUnregister failed, hr = 0x%08X\n", hr);
RegCloseKey(key);