1判断操作系统是32位还是64位
//方法I: BOOL IsWow64() { //函数IsWow64Process()用于确定指定进程是否运行在64位操作系统的32环境(Wow64)下 //如果该进程是32位进程,运行在64操作系统,该值为true,否则为false,具体如下: //32bit程序跑在32bit系统下,返回0. //32bit程序跑在64bit系统下,是wow64模式,返回1. //64bit程序跑在64bit系统下,那么不是wow64模式,返回0 BOOL bIsWow64 = FALSE; typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process"); if (NULL != fnIsWow64Process) { fnIsWow64Process(GetCurrentProcess(), &bIsWow64); } return bIsWow64; }
//方法II: BOOL Is64BitOS() { typedef BOOL(WINAPI *LPFN_PGNSI) (LPSYSTEM_INFO); LPFN_PGNSI pGNSI = (LPFN_PGNSI)GetProcAddress(GetModuleHandle(_T("kernel32.dll")), "GetNativeSystemInfo"); if (pGNSI == NULL) { return FALSE; } BOOL bRetVal = FALSE; SYSTEM_INFO si = { 0 }; pGNSI(&si); if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) { bRetVal = TRUE; } return bRetVal; }
时间: 2024-10-10 05:01:40