Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions include/wil/registry_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ namespace reg
}

template <>
constexpr DWORD set_value_type<const ::std::wstring>() WI_NOEXCEPT
constexpr DWORD set_value_type<::std::wstring>() WI_NOEXCEPT
{
return REG_SZ;
}
Expand All @@ -1025,13 +1025,13 @@ namespace reg
}

template <>
constexpr DWORD set_value_type<const BSTR>() WI_NOEXCEPT
constexpr DWORD set_value_type<BSTR>() WI_NOEXCEPT
{
return REG_SZ;
}

template <>
constexpr DWORD set_value_type<const ::wil::unique_bstr>() WI_NOEXCEPT
constexpr DWORD set_value_type<::wil::unique_bstr>() WI_NOEXCEPT
{
return REG_SZ;
}
Expand All @@ -1046,7 +1046,7 @@ namespace reg
}

template <>
constexpr DWORD set_value_type<const ::wil::shared_bstr>() WI_NOEXCEPT
constexpr DWORD set_value_type<::wil::shared_bstr>() WI_NOEXCEPT
{
return REG_SZ;
}
Expand All @@ -1060,7 +1060,7 @@ namespace reg
}

template <>
constexpr DWORD set_value_type<const ::wil::unique_cotaskmem_string>() WI_NOEXCEPT
constexpr DWORD set_value_type<::wil::unique_cotaskmem_string>() WI_NOEXCEPT
{
return REG_SZ;
}
Expand All @@ -1074,7 +1074,7 @@ namespace reg
}

template <>
constexpr DWORD set_value_type<const ::wil::shared_cotaskmem_string>() WI_NOEXCEPT
constexpr DWORD set_value_type<::wil::shared_cotaskmem_string>() WI_NOEXCEPT
{
return REG_SZ;
}
Expand Down
37 changes: 37 additions & 0 deletions tests/RegistryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2196,6 +2196,43 @@ TEST_CASE("BasicRegistryTests::string types", "[registry]")
#endif
}

SECTION("strings set_value with std::wstring lvalue: with opened key")
{
wil::unique_hkey hkey;
REQUIRE_SUCCEEDED(wil::reg::create_unique_key_nothrow(HKEY_CURRENT_USER, testSubkey, hkey, wil::reg::key_access::readwrite));

// verify non-const std::wstring lvalue works with set_value (issue #624)
std::wstring stringValue{L"wstring lvalue test"};
wil::reg::set_value(hkey.get(), stringValueName, stringValue);
auto result = wil::reg::get_value<std::wstring>(hkey.get(), stringValueName);
REQUIRE(result == stringValue);

// verify const std::wstring lvalue also works
const std::wstring constStringValue{L"const wstring test"};
wil::reg::set_value(hkey.get(), stringValueName, constStringValue);
result = wil::reg::get_value<std::wstring>(hkey.get(), stringValueName);
REQUIRE(result == constStringValue);

// verify empty std::wstring
std::wstring emptyValue;
wil::reg::set_value(hkey.get(), stringValueName, emptyValue);
result = wil::reg::get_value<std::wstring>(hkey.get(), stringValueName);
REQUIRE(result.empty());
}

SECTION("strings set_value with std::wstring lvalue: with string key")
{
std::wstring stringValue{L"wstring lvalue subkey test"};
wil::reg::set_value(HKEY_CURRENT_USER, testSubkey, stringValueName, stringValue);
auto result = wil::reg::get_value<std::wstring>(HKEY_CURRENT_USER, testSubkey, stringValueName);
REQUIRE(result == stringValue);

const std::wstring constStringValue{L"const wstring subkey test"};
wil::reg::set_value(HKEY_CURRENT_USER, testSubkey, stringValueName, constStringValue);
result = wil::reg::get_value<std::wstring>(HKEY_CURRENT_USER, testSubkey, stringValueName);
REQUIRE(result == constStringValue);
}

#if defined(__cpp_lib_optional)
SECTION("strings set_value_string/try_get_value_string: with open key")
{
Expand Down
Loading