I make some calls to the win32 API and assume that the lines come out as wide lines, which are valid for XP and newer. How can I say this? Is it a runtime check or a compile time check?
Am I doing it wrong? Here is an example:
typedef std::basic_string<TCHAR> TString;
inline TString queryRegStringValue(HKEY key, const TString& subkey,
const TString defaultValue = TEXT(""))
{
std::vector<char> out_bytes(256);
DWORD num_bytes = out_bytes.size();
DWORD out_type;
long retval = RegQueryValueEx(key, subkey.c_str(), 0, &out_type,
reinterpret_cast<BYTE*>(&out_bytes[0]), &num_bytes);
if (retval != 0)
return defaultValue;
if (num_bytes > 0)
{
assert(out_type == REG_SZ);
BOOST_STATIC_ASSERT(sizeof(TCHAR)==2);
return TString(reinterpret_cast<wchar_t*>(&out_bytes[0]), num_bytes/2);
}
return TEXT("");
}
source
share