From c59a9ba2b3242df76e2087ce59f8ace73225c2ef Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Feb 2024 15:42:48 +0100 Subject: [PATCH] Refactor RegistryHelper code and project structure - Renamed RegistryHelper.cpp to RegistryInterface.h - Updated include paths in RegistryInterface.h - Added error code handling in RegistryError class - Updated project file paths and namespaces in .vcxproj files --- RegistryHelper.sln | 28 +++----- RegistryHelper/RegistryHelper.h | 50 -------------- .../RegistryHelper.h | 50 +++++++++++++- .../RegistryInterface.vcxproj | 65 +++++++++++-------- .../RegistryInterface.vcxproj.filters | 22 +++++-- 5 files changed, 114 insertions(+), 101 deletions(-) delete mode 100644 RegistryHelper/RegistryHelper.h rename RegistryHelper/RegistryHelper.cpp => RegistryInterface/RegistryHelper.h (89%) rename RegistryHelper/RegistryHelper.vcxproj => RegistryInterface/RegistryInterface.vcxproj (74%) rename RegistryHelper/RegistryHelper.vcxproj.filters => RegistryInterface/RegistryInterface.vcxproj.filters (68%) diff --git a/RegistryHelper.sln b/RegistryHelper.sln index 270200c..9a33ba5 100644 --- a/RegistryHelper.sln +++ b/RegistryHelper.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34526.213 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RegistryHelper", "RegistryHelper\RegistryHelper.vcxproj", "{7144564F-FE5B-4B24-A6A9-C83F18969BBB}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3587BC45-E1D1-4FCE-9F36-D4BD660FB262}" ProjectSection(SolutionItems) = preProject .clang-format = .clang-format @@ -15,7 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Example", "Example\Example.vcxproj", "{FD807556-B9F5-4D19-814A-FE0F51F514E1}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest", "UnitTest\UnitTest.vcxproj", "{D4D6B041-259C-4200-9C05-A482841857DC}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RegistryInterface", "RegistryInterface\RegistryInterface.vcxproj", "{40299226-5106-4793-A43D-9BBB17111B64}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -25,14 +23,6 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7144564F-FE5B-4B24-A6A9-C83F18969BBB}.Debug|x64.ActiveCfg = Debug|x64 - {7144564F-FE5B-4B24-A6A9-C83F18969BBB}.Debug|x64.Build.0 = Debug|x64 - {7144564F-FE5B-4B24-A6A9-C83F18969BBB}.Debug|x86.ActiveCfg = Debug|Win32 - {7144564F-FE5B-4B24-A6A9-C83F18969BBB}.Debug|x86.Build.0 = Debug|Win32 - {7144564F-FE5B-4B24-A6A9-C83F18969BBB}.Release|x64.ActiveCfg = Release|x64 - {7144564F-FE5B-4B24-A6A9-C83F18969BBB}.Release|x64.Build.0 = Release|x64 - {7144564F-FE5B-4B24-A6A9-C83F18969BBB}.Release|x86.ActiveCfg = Release|Win32 - {7144564F-FE5B-4B24-A6A9-C83F18969BBB}.Release|x86.Build.0 = Release|Win32 {FD807556-B9F5-4D19-814A-FE0F51F514E1}.Debug|x64.ActiveCfg = Debug|x64 {FD807556-B9F5-4D19-814A-FE0F51F514E1}.Debug|x64.Build.0 = Debug|x64 {FD807556-B9F5-4D19-814A-FE0F51F514E1}.Debug|x86.ActiveCfg = Debug|Win32 @@ -41,14 +31,14 @@ Global {FD807556-B9F5-4D19-814A-FE0F51F514E1}.Release|x64.Build.0 = Release|x64 {FD807556-B9F5-4D19-814A-FE0F51F514E1}.Release|x86.ActiveCfg = Release|Win32 {FD807556-B9F5-4D19-814A-FE0F51F514E1}.Release|x86.Build.0 = Release|Win32 - {D4D6B041-259C-4200-9C05-A482841857DC}.Debug|x64.ActiveCfg = Debug|x64 - {D4D6B041-259C-4200-9C05-A482841857DC}.Debug|x64.Build.0 = Debug|x64 - {D4D6B041-259C-4200-9C05-A482841857DC}.Debug|x86.ActiveCfg = Debug|Win32 - {D4D6B041-259C-4200-9C05-A482841857DC}.Debug|x86.Build.0 = Debug|Win32 - {D4D6B041-259C-4200-9C05-A482841857DC}.Release|x64.ActiveCfg = Release|x64 - {D4D6B041-259C-4200-9C05-A482841857DC}.Release|x64.Build.0 = Release|x64 - {D4D6B041-259C-4200-9C05-A482841857DC}.Release|x86.ActiveCfg = Release|Win32 - {D4D6B041-259C-4200-9C05-A482841857DC}.Release|x86.Build.0 = Release|Win32 + {40299226-5106-4793-A43D-9BBB17111B64}.Debug|x64.ActiveCfg = Debug|x64 + {40299226-5106-4793-A43D-9BBB17111B64}.Debug|x64.Build.0 = Debug|x64 + {40299226-5106-4793-A43D-9BBB17111B64}.Debug|x86.ActiveCfg = Debug|Win32 + {40299226-5106-4793-A43D-9BBB17111B64}.Debug|x86.Build.0 = Debug|Win32 + {40299226-5106-4793-A43D-9BBB17111B64}.Release|x64.ActiveCfg = Release|x64 + {40299226-5106-4793-A43D-9BBB17111B64}.Release|x64.Build.0 = Release|x64 + {40299226-5106-4793-A43D-9BBB17111B64}.Release|x86.ActiveCfg = Release|Win32 + {40299226-5106-4793-A43D-9BBB17111B64}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/RegistryHelper/RegistryHelper.h b/RegistryHelper/RegistryHelper.h deleted file mode 100644 index 68e8dcf..0000000 --- a/RegistryHelper/RegistryHelper.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -class RegistryError : public std::runtime_error -{ -public: - RegistryError(const char* message, LONG errorCode) - : std::runtime_error{ message } - , m_errorCode{ errorCode } - { - } - - LONG ErrorCode() const noexcept { return m_errorCode; } - -private: - LONG m_errorCode; -}; - -class RegistryHelper -{ -public: - RegistryHelper(); - - DWORD RegGetDword(HKEY hKey, - const std::wstring& subKey, - const std::wstring& value); - - std::wstring RegGetString(HKEY hKey, - const std::wstring& subKey, - const std::wstring& value); - - std::vector RegGetMultiString(HKEY hKey, - const std::wstring& subKey, - const std::wstring& value); - - std::vector> RegEnumSubKeys( - HKEY hKey, - const std::wstring& subKey); - - std::vector> RegEnumValues( - HKEY hKey, - const std::wstring& subKey); - -private: - LONG m_errorCode; // store the last error code -}; diff --git a/RegistryHelper/RegistryHelper.cpp b/RegistryInterface/RegistryHelper.h similarity index 89% rename from RegistryHelper/RegistryHelper.cpp rename to RegistryInterface/RegistryHelper.h index f1aa810..95156ea 100644 --- a/RegistryHelper/RegistryHelper.cpp +++ b/RegistryInterface/RegistryHelper.h @@ -1,6 +1,54 @@ -#include "RegistryHelper.h" +#pragma once +#include #include +#include +#include +#include + +class RegistryError : public std::runtime_error +{ +public: + RegistryError(const std::string& message, DWORD errorCode) + : std::runtime_error(message + " Error Code: " + std::to_string(errorCode)) + , m_errorCode(errorCode) + { + } + + DWORD GetErrorCode() const { return m_errorCode; } + +private: + DWORD m_errorCode; +}; + +class RegistryHelper +{ +public: + RegistryHelper(); + + DWORD RegGetDword(HKEY hKey, + const std::wstring& subKey, + const std::wstring& value); + + std::wstring RegGetString(HKEY hKey, + const std::wstring& subKey, + const std::wstring& value); + + std::vector RegGetMultiString(HKEY hKey, + const std::wstring& subKey, + const std::wstring& value); + + std::vector> RegEnumSubKeys( + HKEY hKey, + const std::wstring& subKey); + + std::vector> RegEnumValues( + HKEY hKey, + const std::wstring& subKey); + +private: + DWORD m_errorCode; +}; // Constructor initializes the error code to ERROR_SUCCESS RegistryHelper::RegistryHelper() diff --git a/RegistryHelper/RegistryHelper.vcxproj b/RegistryInterface/RegistryInterface.vcxproj similarity index 74% rename from RegistryHelper/RegistryHelper.vcxproj rename to RegistryInterface/RegistryInterface.vcxproj index cf9877f..0a5c49e 100644 --- a/RegistryHelper/RegistryHelper.vcxproj +++ b/RegistryInterface/RegistryInterface.vcxproj @@ -18,28 +18,22 @@ x64 - - - - - - 17.0 Win32Proj - {7144564f-fe5b-4b24-a6a9-c83f18969bbb} - RegistryHelper + {40299226-5106-4793-a43d-9bbb17111b64} + RegistryInterface 10.0 - Application + StaticLibrary true v143 Unicode - Application + StaticLibrary false v143 true @@ -76,20 +70,18 @@ - - true - true - Level3 true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) true - stdcpp20 + Use + pch.h - Console + + true @@ -99,12 +91,14 @@ true true true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) true - stdcpp20 + Use + pch.h - Console + + true true true @@ -114,12 +108,14 @@ Level3 true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + _DEBUG;_LIB;%(PreprocessorDefinitions) true - stdcpp20 + Use + pch.h - Console + + true @@ -129,17 +125,34 @@ true true true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + NDEBUG;_LIB;%(PreprocessorDefinitions) true - stdcpp20 + Use + pch.h - Console + + true true true + + + + + + + + Create + Create + Create + Create + + + + diff --git a/RegistryHelper/RegistryHelper.vcxproj.filters b/RegistryInterface/RegistryInterface.vcxproj.filters similarity index 68% rename from RegistryHelper/RegistryHelper.vcxproj.filters rename to RegistryInterface/RegistryInterface.vcxproj.filters index b02af73..533d8fb 100644 --- a/RegistryHelper/RegistryHelper.vcxproj.filters +++ b/RegistryInterface/RegistryInterface.vcxproj.filters @@ -15,13 +15,25 @@ - - Source Files - + + Header Files + + + Header Files + + + Header Files + - + + Source Files + + + Source Files + + Header Files - + \ No newline at end of file