std::wstring GetString()

in src/VSIXBootstrapper.Shared/RegistryKey.h [60:86]


    std::wstring GetString(_In_opt_ LPCWSTR wszValue) const
    {
        DWORD cch = 0;
        DWORD dwType = 0;

        auto err = _Traits::RegistryKeyQueryValue(m_hk, wszValue, NULL, &dwType, NULL, &cch);
        if (err)
        {
            throw win32_error(err);
        }

        if (REG_SZ != dwType)
        {
            throw win32_error(ERROR_INVALID_DATATYPE);
        }

        std::wstring value;
        value.resize((cch - sizeof(wchar_t)) / sizeof(wchar_t));

        err = _Traits::RegistryKeyQueryValue(m_hk, wszValue, NULL, NULL, (LPBYTE)&value[0], &cch);
        if (err)
        {
            throw win32_error(err);
        }

        return value;
    }