enabled WinRegistryKey and WinRegistryConfiguration for WinCE

This commit is contained in:
Günter Obiltschnig
2014-11-24 15:30:33 +01:00
parent 5f8d7ef994
commit 42c814cca4
5 changed files with 37 additions and 43 deletions

View File

@@ -14,9 +14,6 @@
//
#if !defined(_WIN32_WCE)
#include "Poco/Util/WinRegistryConfiguration.h"
#include "Poco/Util/WinRegistryKey.h"
#include "Poco/NumberFormatter.h"
@@ -100,12 +97,19 @@ void WinRegistryConfiguration::enumerate(const std::string& key, Keys& range) co
if (fullPath.empty())
{
// return all root level keys
#if defined(_WIN32_WCE)
range.push_back("HKEY_CLASSES_ROOT");
range.push_back("HKEY_CURRENT_CONFIG");
range.push_back("HKEY_CURRENT_USER");
range.push_back("HKEY_LOCAL_MACHINE");
range.push_back("HKEY_PERFORMANCE_DATA");
range.push_back("HKEY_USERS");
#else
range.push_back("HKEY_CLASSES_ROOT");
range.push_back("HKEY_CURRENT_USER");
range.push_back("HKEY_LOCAL_MACHINE");
range.push_back("HKEY_USERS");
#endif
}
else
{
@@ -140,6 +144,3 @@ std::string WinRegistryConfiguration::convertToRegFormat(const std::string& key,
} } // namespace Poco::Util
#endif // !defined(_WIN32_WCE)

View File

@@ -14,9 +14,6 @@
//
#if !defined(_WIN32_WCE)
#include "Poco/Util/WinRegistryKey.h"
#include "Poco/Exception.h"
#include "Poco/Buffer.h"
@@ -176,17 +173,20 @@ std::string WinRegistryKey::getStringExpand(const std::string& name)
if (size > 0)
{
DWORD len = size/2;
wchar_t* buffer = new wchar_t[len + 1];
RegQueryValueExW(_hKey, uname.c_str(), NULL, NULL, (BYTE*) buffer, &size);
Poco::Buffer<wchar_t> buffer(len + 1);
RegQueryValueExW(_hKey, uname.c_str(), NULL, NULL, (BYTE*) buffer.begin(), &size);
buffer[len] = 0;
#if !defined(_WIN32_WCE)
wchar_t temp;
DWORD expSize = ExpandEnvironmentStringsW(buffer, &temp, 1);
wchar_t* expBuffer = new wchar_t[expSize];
ExpandEnvironmentStringsW(buffer, expBuffer, expSize);
DWORD expSize = ExpandEnvironmentStringsW(buffer.begin(), &temp, 1);
Poco::Buffer<wchar_t> expBuffer(expSize);
ExpandEnvironmentStringsW(buffer.begin(), expBuffer.begin(), expSize);
std::string result;
UnicodeConverter::toUTF8(expBuffer, result);
delete [] buffer;
delete [] expBuffer;
UnicodeConverter::toUTF8(expBuffer.begin(), result);
#else
std::string result;
UnicodeConverter::toUTF8(buffer.begin(), result);
#endif
return result;
}
#else
@@ -194,16 +194,14 @@ std::string WinRegistryKey::getStringExpand(const std::string& name)
throw NotFoundException(key(name));
if (size > 0)
{
char* buffer = new char[size + 1];
RegQueryValueExA(_hKey, name.c_str(), NULL, NULL, (BYTE*) buffer, &size);
Poco::Buffer<char> Buffer(size + 1);
RegQueryValueExA(_hKey, name.c_str(), NULL, NULL, (BYTE*) Buffer.begin(), &size);
buffer[size] = 0;
char temp;
DWORD expSize = ExpandEnvironmentStringsA(buffer, &temp, 1);
char* expBuffer = new char[expSize];
ExpandEnvironmentStringsA(buffer, expBuffer, expSize);
std::string result(expBuffer);
delete [] buffer;
delete [] expBuffer;
Poco::Buffer<char> expBuffer(expSize);
ExpandEnvironmentStringsA(Buffer.begin(), expBuffer.begin(), expSize);
std::string result(expBuffer.begin());
return result;
}
#endif
@@ -291,8 +289,10 @@ int WinRegistryKey::getInt(const std::string& name)
return data;
}
#if defined(POCO_HAVE_INT64)
void WinRegistryKey::setInt64(const std::string& name, Poco::Int64 value)
{
open();
@@ -325,8 +325,10 @@ Poco::Int64 WinRegistryKey::getInt64(const std::string& name)
return data;
}
#endif // POCO_HAVE_INT64
void WinRegistryKey::deleteValue(const std::string& name)
{
open();
@@ -364,6 +366,7 @@ void WinRegistryKey::deleteKey()
std::wstring usubKey;
Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
#if !defined(_WIN32_WCE)
typedef LONG (WINAPI *RegDeleteKeyExWFunc)(HKEY hKey, const wchar_t* lpSubKey, REGSAM samDesired, DWORD Reserved);
if (_extraSam != 0)
{
@@ -379,6 +382,7 @@ void WinRegistryKey::deleteKey()
}
}
}
#endif
if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
throw NotFoundException(key());
#else
@@ -520,16 +524,20 @@ std::string WinRegistryKey::key() const
std::string result;
if (_hRootKey == HKEY_CLASSES_ROOT)
result = "HKEY_CLASSES_ROOT";
#if defined(HKEY_CURRENT_CONFIG)
else if (_hRootKey == HKEY_CURRENT_CONFIG)
result = "HKEY_CURRENT_CONFIG";
#endif
else if (_hRootKey == HKEY_CURRENT_USER)
result = "HKEY_CURRENT_USER";
else if (_hRootKey == HKEY_LOCAL_MACHINE)
result = "HKEY_LOCAL_MACHINE";
else if (_hRootKey == HKEY_USERS)
result = "HKEY_USERS";
#if defined(HKEY_PERFORMANCE_DATA)
else if (_hRootKey == HKEY_PERFORMANCE_DATA)
result = "HKEY_PERFORMANCE_DATA";
#endif
else
result = "(UNKNOWN)";
result += '\\';
@@ -554,16 +562,20 @@ HKEY WinRegistryKey::handleFor(const std::string& rootKey)
{
if (rootKey == "HKEY_CLASSES_ROOT")
return HKEY_CLASSES_ROOT;
#if defined(HKEY_CURRENT_CONFIG)
else if (rootKey == "HKEY_CURRENT_CONFIG")
return HKEY_CURRENT_CONFIG;
#endif
else if (rootKey == "HKEY_CURRENT_USER")
return HKEY_CURRENT_USER;
else if (rootKey == "HKEY_LOCAL_MACHINE")
return HKEY_LOCAL_MACHINE;
else if (rootKey == "HKEY_USERS")
return HKEY_USERS;
#if defined(HKEY_PERFORMANCE_DATA)
else if (rootKey == "HKEY_PERFORMANCE_DATA")
return HKEY_PERFORMANCE_DATA;
#endif
else
throw InvalidArgumentException("Not a valid root key", rootKey);
}
@@ -656,6 +668,3 @@ void WinRegistryKey::values(WinRegistryKey::Values& vals)
} } // namespace Poco::Util
#endif // !defined(_WIN32_WCE)

View File

@@ -10,9 +10,6 @@
//
#if !defined(_WIN32_WCE)
#include "WinConfigurationTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
@@ -149,6 +146,3 @@ CppUnit::Test* WinConfigurationTest::suite()
return pSuite;
}
#endif // _WIN32_WCE

View File

@@ -10,9 +10,6 @@
//
#if !defined(_WIN32_WCE)
#include "WinRegistryTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
@@ -131,6 +128,3 @@ CppUnit::Test* WinRegistryTest::suite()
return pSuite;
}
#endif // _WIN32_WCE

View File

@@ -11,20 +11,16 @@
#include "WindowsTestSuite.h"
#ifndef _WIN32_WCE
#include "WinRegistryTest.h"
#include "WinConfigurationTest.h"
#endif
CppUnit::Test* WindowsTestSuite::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("WindowsTestSuite");
#ifndef _WIN32_WCE
pSuite->addTest(WinRegistryTest::suite());
pSuite->addTest(WinConfigurationTest::suite());
#endif
return pSuite;
}