正确的方法检查Windows是否64位,在运行时? (C ++) [英] Correct way to check if Windows is 64 bit or not, on runtime? (C++)

查看:87
本文介绍了正确的方法检查Windows是否64位,在运行时? (C ++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  bool Win64bit =(sizeof(int *)== 8)? 1:0; 

我需要这个,所以我的应用程序可以正常使用Windows注册表功能(或者我需要?)。 / p>

这是我做的对吗?

解决方案

在他的博客中提供了 http://blogs.msdn.com/oldnewthing/archive/2005 /02/01/364563.aspx

  BOOL Is64BitWindows()
{
#if defined(_WIN64)
return TRUE; // 64位程序只在Win64上运行
#elif defined(_WIN32)
// 32位程序在32位和64位Windows上运行
//所以必须嗅探
BOOL f64 = FALSE;
return IsWow64Process(GetCurrentProcess(),& f64)&& f64;
#else
return FALSE; // Win64不支持Win16
#endif
}


bool Win64bit = (sizeof(int*) == 8) ? 1 : 0;

I need this so my app can use Windows registry functions properly (or do i need?).

So am i doing it right ?

解决方案

Here's what Raymond Chen suggests in his blog at http://blogs.msdn.com/oldnewthing/archive/2005/02/01/364563.aspx:

BOOL Is64BitWindows()
{
#if defined(_WIN64)
    return TRUE;  // 64-bit programs run only on Win64
#elif defined(_WIN32)
    // 32-bit programs run on both 32-bit and 64-bit Windows
    // so must sniff
    BOOL f64 = FALSE;
    return IsWow64Process(GetCurrentProcess(), &f64) && f64;
#else
    return FALSE; // Win64 does not support Win16
#endif
}

这篇关于正确的方法检查Windows是否64位,在运行时? (C ++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆