- fixed SF# 3476926: RegDeleteKeyEx not available on Windows XP 32-bit.

This commit is contained in:
Guenter Obiltschnig
2012-01-23 09:22:09 +00:00
parent c068520b5a
commit 9de2496875
4 changed files with 80 additions and 6 deletions

View File

@@ -1,5 +1,11 @@
This is the changelog file for the POCO C++ Libraries.
Release 1.4.3p1 (2012-01-23)
============================
- fixed SF# 3476926: RegDeleteKeyEx not available on Windows XP 32-bit
Release 1.4.3 (2012-01-16)
==========================
@@ -1672,4 +1678,4 @@ building the libraries.
--
$Id: //poco/1.4/dist/CHANGELOG#56 $
$Id: //poco/1.4/dist/CHANGELOG#58 $

View File

@@ -1,7 +1,7 @@
//
// WinRegistryKey.cpp
//
// $Id: //poco/1.4/Util/src/WinRegistryKey.cpp#4 $
// $Id: //poco/1.4/Util/src/WinRegistryKey.cpp#6 $
//
// Library: Util
// Package: Windows
@@ -53,6 +53,32 @@ namespace Poco {
namespace Util {
namespace
{
class AutoHandle
{
public:
AutoHandle(HMODULE h):
_h(h)
{
}
~AutoHandle()
{
FreeLibrary(_h);
}
HMODULE handle()
{
return _h;
}
private:
HMODULE _h;
};
}
WinRegistryKey::WinRegistryKey(const std::string& key, bool readOnly, REGSAM extraSam):
_hKey(0),
_readOnly(readOnly),
@@ -269,13 +295,49 @@ void WinRegistryKey::deleteKey()
WinRegistryKey subRegKey(_hRootKey, subKey);
subRegKey.deleteKey();
}
// NOTE: RegDeleteKeyEx is only available on Windows XP 64-bit SP3, Windows Vista or later.
// We cannot call it directly as this would prevent the code running on Windows XP 32-bit.
// Therefore, if we need to call RegDeleteKeyEx (_extraSam != 0) we need to check for
// its existence in ADVAPI32.DLL and call it indirectly.
#if defined(POCO_WIN32_UTF8)
std::wstring usubKey;
Poco::UnicodeConverter::toUTF16(_subKey, usubKey);
if (RegDeleteKeyExW(_hRootKey, usubKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
typedef LONG (WINAPI *RegDeleteKeyExWFunc)(HKEY hKey, const wchar_t* lpSubKey, REGSAM samDesired, DWORD Reserved);
if (_extraSam != 0)
{
AutoHandle advAPI32(LoadLibraryW(L"ADVAPI32.DLL"));
if (advAPI32.handle())
{
RegDeleteKeyExWFunc pRegDeleteKeyExW = reinterpret_cast<RegDeleteKeyExWFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExW"));
if (pRegDeleteKeyExW)
{
if ((*pRegDeleteKeyExW)(_hRootKey, usubKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
throw NotFoundException(key());
return;
}
}
}
if (RegDeleteKeyW(_hRootKey, usubKey.c_str()) != ERROR_SUCCESS)
throw NotFoundException(key());
#else
if (RegDeleteKeyEx(_hRootKey, _subKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
typedef LONG (WINAPI *RegDeleteKeyExAFunc)(HKEY hKey, const char* lpSubKey, REGSAM samDesired, DWORD Reserved);
if (_extraSam != 0)
{
AutoHandle advAPI32(LoadLibraryA("ADVAPI32.DLL"));
if (advAPI32.handle())
{
RegDeleteKeyExAFunc pRegDeleteKeyExA = reinterpret_cast<RegDeleteKeyExAFunc>(GetProcAddress(advAPI32.handle() , "RegDeleteKeyExA"));
if (pRegDeleteKeyExA)
{
if ((*pRegDeleteKeyExA)(_hRootKey, _subKey.c_str(), _extraSam, 0) != ERROR_SUCCESS)
throw NotFoundException(key());
return;
}
}
}
if (RegDeleteKey(_hRootKey, _subKey.c_str()) != ERROR_SUCCESS)
throw NotFoundException(key());
#endif
}

View File

@@ -1 +1 @@
1.4.3 (2012-01-10)
1.4.3p1 (2012-01-23)

View File

@@ -1,6 +1,13 @@
POCO C++ Libraries Release Notes
AAAIntroduction
!!!Release 1.4.3p1
!!Summary of Changes
- fixed SF# 3476926: RegDeleteKeyEx not available on Windows XP 32-bit.
!!!Release 1.4.3
!!Summary of Changes
@@ -78,7 +85,6 @@ AAAIntroduction
- Poco::format(): an argument that does not match the format
specifier no longer results in a BadCastException. The string [ERRFMT] is
written to the result string instead.
- PageCompiler: added createSession page attribute.
!!!Release 1.4.2p1