MCPcopy Create free account
hub / github.com/chrxh/alien / TryGetMultiStringValue

Method TryGetMultiStringValue

external/WinReg/WinReg.hpp:1899–1951  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1897
1898
1899inline RegExpected<std::vector<std::wstring>>
1900 RegKey::TryGetMultiStringValue(const std::wstring& valueName) const
1901{
1902 _ASSERTE(IsValid());
1903
1904 using RegValueType = std::vector<std::wstring>;
1905
1906 // Request the size of the multi-string, in bytes
1907 DWORD dataSize = 0;
1908 constexpr DWORD flags = RRF_RT_REG_MULTI_SZ;
1909 LSTATUS retCode = ::RegGetValueW(
1910 m_hKey,
1911 nullptr, // no subkey
1912 valueName.c_str(),
1913 flags,
1914 nullptr, // type not required
1915 nullptr, // output buffer not needed now
1916 &dataSize
1917 );
1918 if (retCode != ERROR_SUCCESS)
1919 {
1920 return detail::MakeRegExpectedWithError<RegValueType>(retCode);
1921 }
1922
1923 // Allocate room for the result multi-string.
1924 // Note that dataSize is in bytes, but our vector<wchar_t>::resize method requires size
1925 // to be expressed in wchar_ts.
1926 std::vector<wchar_t> data(dataSize / sizeof(wchar_t), L' ');
1927
1928 // Read the multi-string from the registry into the vector object
1929 retCode = ::RegGetValueW(
1930 m_hKey,
1931 nullptr, // no subkey
1932 valueName.c_str(),
1933 flags,
1934 nullptr, // no type required
1935 data.data(), // output buffer
1936 &dataSize
1937 );
1938 if (retCode != ERROR_SUCCESS)
1939 {
1940 return detail::MakeRegExpectedWithError<RegValueType>(retCode);
1941 }
1942
1943 // Resize vector to the actual size returned by GetRegValue.
1944 // Note that the vector is a vector of wchar_ts, instead the size returned by GetRegValue
1945 // is in bytes, so we have to scale from bytes to wchar_t count.
1946 data.resize(dataSize / sizeof(wchar_t));
1947
1948 // Convert the double-null-terminated string structure to a vector<wstring>,
1949 // and return that back to the caller
1950 return RegExpected<RegValueType>{ detail::ParseMultiString(data) };
1951}
1952
1953
1954inline RegExpected<std::vector<BYTE>>

Callers

nothing calls this directly

Calls 2

ParseMultiStringFunction · 0.85
resizeMethod · 0.80

Tested by

no test coverage detected