getRegistryValue DWORD


Hi all…
I’ve a problem reading a DWORD value from the registry.
I’m using the static function getRegistryValue that returns a juce::String.
The value in the registry is a DWORD and the possible values are “0” or “1”.
I can’t figure out how to cast the String to int.
When the value in the registry is “0” the function seems to returnsan empty string. When “1” it returns a strange string…
I tried a lot of conversion and casting but nothing…

Help needed!



You can use String::getIntValue () or String::getLargeIntValue () to convert juce Strings to Integers. Not sure why you aren’t getting the correct values.

Have you checked if the entry is there in the register ?


Sounds like a bug - the juce registry stuff is only really designed to handle strings.

I’ve not even tried compiling this, but maybe try a fix like this:

[code]const String PlatformUtilities::getRegistryValue (const String& regValuePath,
const String& defaultValue)
String valueName, result (defaultValue);
HKEY k = findKeyForPath (regValuePath, false, valueName);

if (k != 0)
    WCHAR buffer [2048];
    unsigned long bufferSize = sizeof (buffer);
    DWORD type = REG_SZ;

    if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
        if (type == REG_SZ)
            result = buffer;
        else if (type == REG_DWORD)
            result = (int) *(DWORD*) buffer;

    RegCloseKey (k);

return result;




Thank you all for your quick answers…
The code that you, Jules, posted solved the problem (I had only to add a String casting to the result assignement)…

result = (String)(int) *(DWORD*) buffer;

But now I’m having problems overriding this value whit setRegistryValue…

Reading your words and the code of the two methods I understand that those methods was really intended to handle just string, so maybe that’s why I cannot override the value!

Waiting for your news… i will try to find an hack to do my task!



Ah, well you’re probably better off using your own code if you’re doing anything more specific than just writing a string.


Thanks vishvesh, thanks jules…