Browse Source

Added a WOW64 call to WindowsRegistry.

tags/2021-05-28
jules 13 years ago
parent
commit
e61db7da55
2 changed files with 61 additions and 39 deletions
  1. +7
    -0
      modules/juce_core/misc/juce_WindowsRegistry.h
  2. +54
    -39
      modules/juce_core/native/juce_win32_Registry.cpp

+ 7
- 0
modules/juce_core/misc/juce_WindowsRegistry.h View File

@@ -43,6 +43,13 @@ public:
static String getValue (const String& regValuePath, static String getValue (const String& regValuePath,
const String& defaultValue = String::empty); const String& defaultValue = String::empty);
/** Returns a string from the WOW64 registry.
The path is a string for the entire path of a value in the registry,
e.g. "HKEY_CURRENT_USER\Software\foo\bar"
*/
static String getValueWow64 (const String& regValuePath,
const String& defaultValue = String::empty);
/** Reads a binary block from the registry. /** Reads a binary block from the registry.
The path is a string for the entire path of a value in the registry, The path is a string for the entire path of a value in the registry,
e.g. "HKEY_CURRENT_USER\Software\foo\bar" e.g. "HKEY_CURRENT_USER\Software\foo\bar"


+ 54
- 39
modules/juce_core/native/juce_win32_Registry.cpp View File

@@ -25,7 +25,7 @@
struct RegistryKeyWrapper struct RegistryKeyWrapper
{ {
RegistryKeyWrapper (String name, const bool createForWriting)
RegistryKeyWrapper (String name, const bool createForWriting, const DWORD wow64Flags)
: key (0), wideCharValueName (nullptr) : key (0), wideCharValueName (nullptr)
{ {
HKEY rootKey = 0; HKEY rootKey = 0;
@@ -48,9 +48,9 @@ struct RegistryKeyWrapper
if (createForWriting) if (createForWriting)
RegCreateKeyEx (rootKey, wideCharName, 0, 0, REG_OPTION_NON_VOLATILE, RegCreateKeyEx (rootKey, wideCharName, 0, 0, REG_OPTION_NON_VOLATILE,
(KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result);
KEY_WRITE | KEY_QUERY_VALUE | wow64Flags, 0, &key, &result);
else else
RegOpenKeyEx (rootKey, wideCharName, 0, KEY_READ, &key);
RegOpenKeyEx (rootKey, wideCharName, 0, KEY_READ | wow64Flags, &key);
} }
} }
@@ -63,7 +63,7 @@ struct RegistryKeyWrapper
static bool setValue (const String& regValuePath, const DWORD type, static bool setValue (const String& regValuePath, const DWORD type,
const void* data, size_t dataSize) const void* data, size_t dataSize)
{ {
const RegistryKeyWrapper key (regValuePath, true);
const RegistryKeyWrapper key (regValuePath, true, 0);
return key.key != 0 return key.key != 0
&& RegSetValueEx (key.key, key.wideCharValueName, 0, type, && RegSetValueEx (key.key, key.wideCharValueName, 0, type,
@@ -71,52 +71,67 @@ struct RegistryKeyWrapper
(DWORD) dataSize) == ERROR_SUCCESS; (DWORD) dataSize) == ERROR_SUCCESS;
} }
HKEY key;
const wchar_t* wideCharValueName;
String valueName;
JUCE_DECLARE_NON_COPYABLE (RegistryKeyWrapper);
};
uint32 WindowsRegistry::getBinaryValue (const String& regValuePath, MemoryBlock& result)
{
const RegistryKeyWrapper key (regValuePath, false);
if (key.key != 0)
static uint32 getBinaryValue (const String& regValuePath, MemoryBlock& result, DWORD wow64Flags)
{ {
for (unsigned long bufferSize = 1024; ; bufferSize *= 2)
{
result.setSize (bufferSize, false);
DWORD type = REG_NONE;
const RegistryKeyWrapper key (regValuePath, false, wow64Flags);
const LONG err = RegQueryValueEx (key.key, key.wideCharValueName, 0, &type,
(LPBYTE) result.getData(), &bufferSize);
if (err == ERROR_SUCCESS)
if (key.key != 0)
{
for (unsigned long bufferSize = 1024; ; bufferSize *= 2)
{ {
result.setSize (bufferSize, false); result.setSize (bufferSize, false);
return type;
DWORD type = REG_NONE;
const LONG err = RegQueryValueEx (key.key, key.wideCharValueName, 0, &type,
(LPBYTE) result.getData(), &bufferSize);
if (err == ERROR_SUCCESS)
{
result.setSize (bufferSize, false);
return type;
}
if (err != ERROR_MORE_DATA)
break;
} }
}
if (err != ERROR_MORE_DATA)
break;
return REG_NONE;
}
static String getValue (const String& regValuePath, const String& defaultValue, DWORD wow64Flags)
{
MemoryBlock buffer;
switch (getBinaryValue (regValuePath, buffer, wow64Flags))
{
case REG_SZ: return static_cast <const WCHAR*> (buffer.getData());
case REG_DWORD: return String ((int) *reinterpret_cast<const DWORD*> (buffer.getData()));
default: break;
} }
return defaultValue;
} }
return REG_NONE;
HKEY key;
const wchar_t* wideCharValueName;
String valueName;
JUCE_DECLARE_NON_COPYABLE (RegistryKeyWrapper);
};
uint32 WindowsRegistry::getBinaryValue (const String& regValuePath, MemoryBlock& result)
{
return RegistryKeyWrapper::getBinaryValue (regValuePath, result, 0);
} }
String WindowsRegistry::getValue (const String& regValuePath, const String& defaultValue) String WindowsRegistry::getValue (const String& regValuePath, const String& defaultValue)
{ {
MemoryBlock buffer;
switch (getBinaryValue (regValuePath, buffer))
{
case REG_SZ: return static_cast <const WCHAR*> (buffer.getData());
case REG_DWORD: return String ((int) *reinterpret_cast<const DWORD*> (buffer.getData()));
default: break;
}
return RegistryKeyWrapper::getValue (regValuePath, defaultValue, 0);
}
return defaultValue;
String WindowsRegistry::getValueWow64 (const String& regValuePath, const String& defaultValue)
{
return RegistryKeyWrapper::getValue (regValuePath, defaultValue, KEY_WOW64_64KEY);
} }
bool WindowsRegistry::setValue (const String& regValuePath, const String& value) bool WindowsRegistry::setValue (const String& regValuePath, const String& value)
@@ -142,7 +157,7 @@ bool WindowsRegistry::setValue (const String& regValuePath, const MemoryBlock& v
bool WindowsRegistry::valueExists (const String& regValuePath) bool WindowsRegistry::valueExists (const String& regValuePath)
{ {
const RegistryKeyWrapper key (regValuePath, false);
const RegistryKeyWrapper key (regValuePath, false, 0);
if (key.key == 0) if (key.key == 0)
return false; return false;
@@ -159,7 +174,7 @@ bool WindowsRegistry::valueExists (const String& regValuePath)
void WindowsRegistry::deleteValue (const String& regValuePath) void WindowsRegistry::deleteValue (const String& regValuePath)
{ {
const RegistryKeyWrapper key (regValuePath, true);
const RegistryKeyWrapper key (regValuePath, true, 0);
if (key.key != 0) if (key.key != 0)
RegDeleteValue (key.key, key.wideCharValueName); RegDeleteValue (key.key, key.wideCharValueName);
@@ -167,7 +182,7 @@ void WindowsRegistry::deleteValue (const String& regValuePath)
void WindowsRegistry::deleteKey (const String& regKeyPath) void WindowsRegistry::deleteKey (const String& regKeyPath)
{ {
const RegistryKeyWrapper key (regKeyPath, true);
const RegistryKeyWrapper key (regKeyPath, true, 0);
if (key.key != 0) if (key.key != 0)
RegDeleteKey (key.key, key.wideCharValueName); RegDeleteKey (key.key, key.wideCharValueName);


Loading…
Cancel
Save