bool Win64bit = (sizeof(int*) == 8) ? 1 : 0;
我需要这样做才能使我的应用程序正确地使用Windows注册表功能(或者我需要这样做吗?)。
那么,我现在的做法正确吗?
bool Win64bit = (sizeof(int*) == 8) ? 1 : 0;
我需要这样做才能使我的应用程序正确地使用Windows注册表功能(或者我需要这样做吗?)。
那么,我现在的做法正确吗?
以下是 Raymond Chen 在他的博客中建议的内容:https://devblogs.microsoft.com/oldnewthing/20050201-00/?p=36553
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
}
sizeof(int*)
已经在编译时固定,一旦编译完成,无论在哪个平台上运行,检查结果都是相同的。v++ platform == 64-bit => sizeof(int*) == 8 => use 64-bit API
AND
( windows platform == 64-bit => 64-bit API works
OR
windows platform == 32-bit => program does not run )
如果你以32位模式编译程序,程序将正确使用32位API,在64位Windows平台上的32位兼容模式下工作,并且显然可在32位平台上工作。
v++ platform == 32-bit => sizeof(int*) == 4 => use 32-bit API
AND
( windows platform == 64-bit => 32-bit API works using compatibility mode
OR
windows platform == 32-bit => 32-bit API works )
sizeof(void*)==4
)。sizeof(void*)==8
成立。在这种情况下,无需调用IsWow64Process
。 - Alexander GesslerIsWow64Process
是否存在作为一种检测位数的方法。你还需要调用它。 - Andreas Haferburg