getRegistryValue 64 bit problem


#1

Hi,
there is a compatibility problem with the PlatformUtilities::getRegistryValue function when trying to access a registry key from a 32 bit application running on a 64 bit Windows OS.
Let’s say we have a key ‘HKLM\SOFTWARE\Company\Application\MyKey’ which can be accessed correctly when we are using PlatformUtilities::getRegistryValue within a 32 bit app on a 32 bit OS or within a 64 bit app on a 64 bit OS. But if we are running a 32 bit app on a 64 bit OS, PlatformUtilities::getRegistryValue will fail to load the key because of Microsofts ‘registry reflection’ mechanism which divides the registry into a 32 bit and a 64 bit part. For further information see:
http://msdn.microsoft.com/en-us/library/ms724072
To make this key accessable for a 32 bit app on a 64 bit OS, we have to add a flag (’[color=#FF0000]KEY_WOW64_64KEY[/color]’) to the RegCreateKeyEx function calls in the findKeyForPath function in juce_win32_PlatformUtils.cpp. This flag has no effect on other combinations but 32 bit app and 64 bit OS.
The calls should look like this:

//...
if (createForWriting)
        {
            if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
                                (KEY_WRITE | KEY_QUERY_VALUE | KEY_WOW64_64KEY), 0, &key, &result) == ERROR_SUCCESS)
                return key;
        }
        else
        {
            if (RegOpenKeyEx (rootKey, name, 0, KEY_READ | KEY_WOW64_64KEY, &key) == ERROR_SUCCESS)
                return key;
        }
//...

Could you please add this flag or add an option to the PlatformUtilities registry functions if the flag should be set or not.
Thanks


#2

Thanks - I’m happy to add that.

I’d never heard of registry reflection before, but it’s got to be one of the stupidest steaming great hacks that I’ve ever heard of…