Je veux détecter si le système d'exploitation Windows actuel est 32 bits ou 64 bits. Comment y parvenir en C++ ? Je ne veux pas de type de processeur Je veux le type de bit du système d'exploitation. En effet, vous pouvez installer un système d'exploitation 32 bits sur un processeur 64 bits.
Réponses
Trop de publicités?La fonction à appeler est IsWow64Process
ou IsWow64Process2
. Il indique à votre application 32 bits si elle s'exécute sur un Windows 64 bits.
Si le programme est compilé pour 64 bits, il le saura déjà.
Si votre code est en 64 bits et en cours d'exécution, alors Windows est en 64 bits - rien à vérifier. Si votre processus est 32 bits, appelez IsWow64Process()
- les processus 32 bits s'exécutent dans WOW64 sur Windows 64 bits et sans WOW64 sinon.
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
}
vous pouvez utiliser IsWow64Process si votre application est une application 32 bits, s'il est vrai que vous utilisez un système d'exploitation x64, sinon c'est 32 bits