#pragma region CPL License /* Nuclex Videl Copyright (C) 2020-2023 Nuclex Development Labs This application is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This application is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this application */ #pragma endregion // CPL License #ifndef NUCLEX_PLATFORM_PLATFORM_WINDOWSREGISTRYAPI_H #define NUCLEX_PLATFORM_PLATFORM_WINDOWSREGISTRYAPI_H #include "Nuclex/Platform/Config.h" #if defined(NUCLEX_PLATFORM_WINDOWS) #include "WindowsApi.h" // for ::HKEY via Windows.h #include // for std::size_t #include // for std::string #include // for std::optional namespace Nuclex { namespace Platform { namespace Platform { // ------------------------------------------------------------------------------------------- // /// Wraps the API used to interface with the registry on Windows systems class WindowsRegistryApi { /// Retrieves a value stored under a registry key as a string /// Handle of the registry key in which the value is stored /// Name of the value in the registry /// Expected size of the value, useful for strings /// The registry value, if it was present public: static std::optional WindowsRegistryApi::QueryStringValue( ::HKEY keyHandle, const std::wstring &valueName, std::size_t sizeHint = 16 ); /// Opens a subkey below the specified parent registry key /// Handle of the parent registry key /// Name of the subkey that will be opened /// /// The handle of the opened registry subkey or a null pointer if the key doesn't exist /// public: static ::HKEY OpenExistingSubKey( ::HKEY parentKeyHandle, const std::wstring &subKeyName ); /// Closes the specified registry key again /// Handle of the registry key that will be closed /// /// Whether to throw an exception when closing the registry key fails /// public: static void CloseKey(::HKEY keyHandle, bool throwOnError = true); }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Platform::Platform #endif // defined(NUCLEX_PLATFORM_WINDOWS) #endif // NUCLEX_PLATFORM_PLATFORM_WINDOWSREGISTRYAPI_H