{"id":3900,"date":"2014-03-30T06:18:22","date_gmt":"2014-03-30T06:18:22","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/at-runtime-how-can-i-tell-if-im-on-winxp-win32-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:18:22","modified_gmt":"2014-03-30T06:18:22","slug":"at-runtime-how-can-i-tell-if-im-on-winxp-win32-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/at-runtime-how-can-i-tell-if-im-on-winxp-win32-collection-of-common-programming-errors\/","title":{"rendered":"at runtime, how can I tell if I&#39;m on WinXP+? win32-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m making some win32 string API calls and am assuming that the strings come out as wide strings, which is valid on XP and newer. How can I assert this? Is this a runtime check or a compile-time check?<\/p>\n<p>Am I doing it wrong? Here&#8217;s an example:<\/p>\n<pre><code>typedef std::basic_string TString;\ninline TString queryRegStringValue(HKEY key, const TString&amp; subkey, \n        const TString defaultValue = TEXT(\"\"))\n{\n    std::vector out_bytes(256);\n    DWORD num_bytes = out_bytes.size();\n    DWORD out_type;\n    long retval = RegQueryValueEx(key, subkey.c_str(), 0, &amp;out_type, \n        reinterpret_cast(&amp;out_bytes[0]), &amp;num_bytes); \/\/comes out as a platform string. wide on XP\n    if (retval != 0)\n        return defaultValue;\n    if (num_bytes &gt; 0)\n    {\n        assert(out_type == REG_SZ);\n        BOOST_STATIC_ASSERT(sizeof(TCHAR)==2); \/\/what if someone runs my code on an older system?\n        return TString(reinterpret_cast(&amp;out_bytes[0]), num_bytes\/2); \/\/assumes windows XP (wide string)\n    }\n\n    return TEXT(\"\");\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m making some win32 string API calls and am assuming that the strings come out as wide strings, which is valid on XP and newer. How can I assert this? Is this a runtime check or a compile-time check? Am I doing it wrong? Here&#8217;s an example: typedef std::basic_string TString; inline TString queryRegStringValue(HKEY key, const [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3900","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3900"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3900\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}