At runtime, how can I find out if I am on WinXP +? win32

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); //comes out as a platform string. wide on XP
    if (retval != 0)
        return defaultValue;
    if (num_bytes > 0)
    {
        assert(out_type == REG_SZ);
        BOOST_STATIC_ASSERT(sizeof(TCHAR)==2); //what if someone runs my code on an older system?
        return TString(reinterpret_cast<wchar_t*>(&out_bytes[0]), num_bytes/2); //assumes windows XP (wide string)
    }

    return TEXT("");
}
+3
source share
3 answers

It's not a problem. Windows has been Unicode's native operating system for the past 17 years, long before XP was released. David Cutler's children, NT 3.1, have been Unicode from day one.

, Window 9x, API, UTF-16 8- . TCHAR .

+4
+1

, , , API- Unicode, , , . , .

I added a compile-time statement to force build a build error, if we compile on a platform without a widescreen (pre XP or pre 2000 or something else), the build will fail. If there was no statement, it would still fail, but more mysteriously.

+1
source

Source: https://habr.com/ru/post/1754472/


All Articles