Rah*_*hul 46 c++ windows 32bit-64bit
我想检测当前的Windows操作系统是32位还是64位.如何使用C++实现它?我不想要处理器类型我想要OS的位类型.这是因为您可以在64位处理器上安装32位操作系统.
Bo *_*son 45
要调用的函数是IsWow64Process
.它会告诉您的32位应用程序是否在64位Windows上运行.
如果程序编译为64位,它就已经知道了.
sha*_*oth 16
如果您的代码是64位并且正在运行,那么Windows是64位 - 无需检查.如果您的进程是32位调用IsWow64Process()
- 32位进程在64位Windows上以WOW64运行,否则不使用WOW64.
小智 11
bool getWindowsBit(bool & isWindows64bit)
{
#if _WIN64
isWindows64bit = true;
return true;
#elif _WIN32
BOOL isWow64 = FALSE;
//IsWow64Process is not available on all supported versions of Windows.
//Use GetModuleHandle to get a handle to the DLL that contains the function
//and GetProcAddress to get a pointer to the function if available.
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)
GetProcAddress(GetModuleHandle(TEXT("kernel32")),"IsWow64Process");
if(fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(), &isWow64))
return false;
if(isWow64)
isWindows64bit = true;
else
isWindows64bit = false;
return true;
}
else
return false;
#else
assert(0);
return false;
#endif
}
Run Code Online (Sandbox Code Playgroud)
使用GetNativeSystemInfo
功能。它获取一个LPSYSTEM_INFO
参数来获得你想要的东西。
SYSTEM_INFO
结构体:
wProcessorArchitecture
已安装操作系统的处理器架构。
你需要使用GetNativeSystemInfo
.鉴于您希望这可以在32位操作系统上运行,您需要使用LoadLibrary
+ GetProcAddress
以便您可以处理此功能不可用.因此,如果失败,您就知道它是一个32位操作系统.如果没有,SYSTEM_INFO.wProcessorArchitecture
则为您提供真实的处理器类型而不是模拟的处理器类型.
归档时间: |
|
查看次数: |
49928 次 |
最近记录: |