Merge pull request #476 from discnl/fix-registry-delete-key

Fix deletion of registry keys from alternate registry view.

This didn't work due to a bug in code dynamically loading RegDeleteKeyEx().
This commit is contained in:
VZ 2017-05-22 00:14:20 +02:00 committed by GitHub
commit aebd8c728b
2 changed files with 24 additions and 4 deletions

View File

@ -757,11 +757,10 @@ bool wxRegKey::DeleteSelf()
#if wxUSE_DYNLIB_CLASS
wxDynamicLibrary dllAdvapi32(wxT("advapi32"));
// Minimum supported OS for RegDeleteKeyEx: Vista, XP Pro x64, Win Server 2008, Win Server 2003 SP1
if(dllAdvapi32.HasSymbol(wxT("RegDeleteKeyEx")))
{
typedef LONG (WINAPI *RegDeleteKeyEx_t)(HKEY, LPCTSTR, REGSAM, DWORD);
wxDYNLIB_FUNCTION(RegDeleteKeyEx_t, RegDeleteKeyEx, dllAdvapi32);
RegDeleteKeyEx_t wxDL_INIT_FUNC_AW(pfn, RegDeleteKeyEx, dllAdvapi32);
if (pfnRegDeleteKeyEx)
{
m_dwLastError = (*pfnRegDeleteKeyEx)((HKEY) m_hRootKey, m_strKey.t_str(),
GetMSWViewFlags(m_viewMode),
0); // This parameter is reserved and must be zero.

View File

@ -35,6 +35,7 @@ public:
private:
CPPUNIT_TEST_SUITE( RegConfigTestCase );
CPPUNIT_TEST( ReadWrite );
CPPUNIT_TEST( DeleteRegistryKeyFromRedirectedView );
CPPUNIT_TEST_SUITE_END();
void ReadWrite();
@ -80,5 +81,25 @@ void RegConfigTestCase::ReadWrite()
delete config;
}
void RegConfigTestCase::DeleteRegistryKeyFromRedirectedView()
{
if ( !wxIsPlatform64Bit() )
{
// Test needs WoW64.
return;
}
// Test inside a key that's known to be redirected and is in HKCU so that
// admin rights are not required (unlike with HKLM).
wxRegKey key(wxRegKey::HKCU, "SOFTWARE\\Classes\\CLSID\\wxWidgetsTestKey",
sizeof(void *) == 4
? wxRegKey::WOW64ViewMode_64
: wxRegKey::WOW64ViewMode_32);
CPPUNIT_ASSERT( key.Create() );
CPPUNIT_ASSERT( key.DeleteSelf() );
CPPUNIT_ASSERT( !key.Exists() );
}
#endif // wxUSE_CONFIG && wxUSE_REGKEY