Hi Jules,
would you consider implementing registry read/write functions for ints and binary data?
On a quick test (except for the QWORD) these functions seem to work:
void WindowsRegistry::setValue (const String& regValuePath, const uint32 value)
{
const RegistryKeyWrapper key (regValuePath, true);
if (key.key != 0)
RegSetValueEx (key.key, key.wideCharValueName, 0, REG_DWORD,
(const BYTE*) (&value),
(DWORD) sizeof(DWORD));
}
void WindowsRegistry::setValue (const String& regValuePath, const uint64 value)
{
const RegistryKeyWrapper key (regValuePath, true);
if (key.key != 0)
RegSetValueEx (key.key, key.wideCharValueName, 0, REG_QWORD,
(const BYTE*) (&value),
(DWORD) sizeof(uint64));
}
void WindowsRegistry::setValue (const String& regValuePath, const MemoryBlock& value)
{
const RegistryKeyWrapper key (regValuePath, true);
if (key.key != 0)
RegSetValueEx (key.key, key.wideCharValueName, 0, REG_BINARY,
(const BYTE*) value.getData(),
(DWORD) value.getSize());
}
uint32 WindowsRegistry::getDataValue (const String& regValuePath, MemoryBlock& value)
{
jassert(value.getSize() == 0);
const RegistryKeyWrapper key (regValuePath, false);
if (key.key != 0)
{
WCHAR buffer [2048];
unsigned long bufferSize = sizeof (buffer);
DWORD type = REG_SZ;
if (RegQueryValueEx (key.key, key.wideCharValueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
{
value.ensureSize(bufferSize, false);
value.copyFrom(buffer, 0, bufferSize);
return type;
}
}
return REG_NONE;
}
There aren’t int-getValue()s, as this can be done via converting the String-getValue() to ints. Also there are further types I ignored. These could be made accesible by using setDataValue (const String& regValuePath, const MemoryBlock& value, uint32 type = REG_BINARY) instead of the given implementation, though I don’t know how to implement this in the header where windows.h isn’t included (which is why the above code uses uint32 instead of DWORD)
Chris