| 1897 | |
| 1898 | |
| 1899 | inline 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 | |
| 1954 | inline RegExpected<std::vector<BYTE>> |
nothing calls this directly
no test coverage detected