{"id":36553,"date":"2005-02-01T07:00:00","date_gmt":"2005-02-01T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/02\/01\/how-to-detect-programmatically-whether-you-are-running-on-64-bit-windows\/"},"modified":"2005-02-01T07:00:00","modified_gmt":"2005-02-01T07:00:00","slug":"how-to-detect-programmatically-whether-you-are-running-on-64-bit-windows","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050201-00\/?p=36553","title":{"rendered":"How to detect programmatically whether you are running on 64-bit Windows"},"content":{"rendered":"<p>\nTo detect programmatically whether your 32-bit program is running\non 64-bit Windows, you can use the IsWow64Process function.\n<\/p>\n<p>\nDo not do\nas some people do and\n<a HREF=\"http:\/\/geekswithblogs.net\/khanna\/archive\/2004\/07\/14\/8374.aspx\">\nhard-code the list of 64-bit processors<\/a>.\nYou&#8217;d think that after the hard-coded list of 64-bit processors\nchanged the first time (when x64 was added to ia64), people would have\nlearned their lesson.\n<\/p>\n<p>\nBut how do you detect programmatically from your 64-bit process\nwhether you are running on 64-bit Windows?  Easy.\n<\/p>\n<pre>\nBOOL Is64BitProcessRunningOn64BitWindows()\n{\n return TRUE;\n}\n<\/pre>\n<p>\nThe fact that your 64-bit program is running at all\nmeans that you are running on 64-bit Windows!\nIf it were a 32-bit machine, your program wouldn&#8217;t be\nable to run.\n<\/p>\n<p>\nIt&#8217;s like asking the question, &#8220;Is the power on?&#8221;\nIf there were no power, your program wouldn&#8217;t be able to ask the question.\n<\/p>\n<p>\nOf course, if you want a single source code base that can be\ncompiled both as a 32-bit program and as a 64-bit program,\nyou have a tiny amount of work to do.\n<\/p>\n<pre>\nBOOL Is64BitWindows()\n{\n#if defined(_WIN64)\n return TRUE;  \/\/ 64-bit programs run only on Win64\n#elif defined(_WIN32)\n \/\/ 32-bit programs run on both 32-bit and 64-bit Windows\n \/\/ so must sniff\n BOOL f64 = FALSE;\n return IsWow64Process(GetCurrentProcess(), &amp;f64) &amp;&amp; f64;\n#else\n return FALSE; \/\/ Win64 does not support Win16\n#endif\n}\n<\/pre>\n<p>\nI threw in a branch for 16-bit programs if you&#8217;re crazy enough\nto be still writing 16-bit Windows programs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To detect programmatically whether your 32-bit program is running on 64-bit Windows, you can use the IsWow64Process function. Do not do as some people do and hard-code the list of 64-bit processors. You&#8217;d think that after the hard-coded list of 64-bit processors changed the first time (when x64 was added to ia64), people would have [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-36553","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>To detect programmatically whether your 32-bit program is running on 64-bit Windows, you can use the IsWow64Process function. Do not do as some people do and hard-code the list of 64-bit processors. You&#8217;d think that after the hard-coded list of 64-bit processors changed the first time (when x64 was added to ia64), people would have [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/36553","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=36553"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/36553\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=36553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=36553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=36553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}