From 42c814cca4340ab17afe799e338b67d7e051f6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Mon, 24 Nov 2014 15:30:33 +0100 Subject: [PATCH] enabled WinRegistryKey and WinRegistryConfiguration for WinCE --- Util/src/WinRegistryConfiguration.cpp | 13 +++--- Util/src/WinRegistryKey.cpp | 51 ++++++++++++--------- Util/testsuite/src/WinConfigurationTest.cpp | 6 --- Util/testsuite/src/WinRegistryTest.cpp | 6 --- Util/testsuite/src/WindowsTestSuite.cpp | 4 -- 5 files changed, 37 insertions(+), 43 deletions(-) diff --git a/Util/src/WinRegistryConfiguration.cpp b/Util/src/WinRegistryConfiguration.cpp index 25f1d73b3..ca1c0d546 100644 --- a/Util/src/WinRegistryConfiguration.cpp +++ b/Util/src/WinRegistryConfiguration.cpp @@ -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) diff --git a/Util/src/WinRegistryKey.cpp b/Util/src/WinRegistryKey.cpp index b0e6a54b5..31b118220 100644 --- a/Util/src/WinRegistryKey.cpp +++ b/Util/src/WinRegistryKey.cpp @@ -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 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 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 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 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) diff --git a/Util/testsuite/src/WinConfigurationTest.cpp b/Util/testsuite/src/WinConfigurationTest.cpp index adcac8635..fcf0b4513 100644 --- a/Util/testsuite/src/WinConfigurationTest.cpp +++ b/Util/testsuite/src/WinConfigurationTest.cpp @@ -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 \ No newline at end of file diff --git a/Util/testsuite/src/WinRegistryTest.cpp b/Util/testsuite/src/WinRegistryTest.cpp index 6d1c38243..b4537243c 100644 --- a/Util/testsuite/src/WinRegistryTest.cpp +++ b/Util/testsuite/src/WinRegistryTest.cpp @@ -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 \ No newline at end of file diff --git a/Util/testsuite/src/WindowsTestSuite.cpp b/Util/testsuite/src/WindowsTestSuite.cpp index ecccbf1f4..b5968f1c0 100644 --- a/Util/testsuite/src/WindowsTestSuite.cpp +++ b/Util/testsuite/src/WindowsTestSuite.cpp @@ -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; }