信不信由你,我的安装程序太旧了,它没有选择检测64位版本的Windows.
是否有Windows DLL调用或(甚至更好)一个环境变量,可以为Windows XP和Windows Vista提供该信息?
一种可能的解决方
我看到维基百科声称64位版本的Windows XP和Windows Vista都有一个独特的环境变量:%ProgramW6432%所以我猜测在32位Windows上它是空的.
此变量指向Program Files目录,该目录存储Windows和其他所有已安装的程序.英语系统的默认设置是C:\Program Files.在64位版本的Windows(XP,2003,Vista)中,还有%ProgramFiles(x86)%默认值C:\Program Files (x86)和%ProgramW6432%默认值C:\Program Files.在%ProgramFiles%本身取决于请求该环境变量中的进程是否为本身的32位或64位(这是由Windows的上-Windows 64位重定向引起的).
我使用这一小段代码来了解我的Windows是32位还是64位:
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
static int is64bitOS()
{
SYSTEM_INFO si;
GetSystemInfo(&si);
if((si.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_IA64)||(si.wProcessorArchitecture & PROCESSOR_ARCHITECTURE_AMD64)==64)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
printf("%d\n", is64bitOS());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我购买并安装了64位版本的Windows 7 - 但是,上面的代码显示0表示我的操作系统是32位...如何处理它?
好吧,我的其他方法,基本上不能正常工作......在我的64位Windows 7上我只看到32位..
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
int getArchType1()
{
SYSTEM_INFO sysInfo;
GetSystemInfo(&sysInfo);
switch(sysInfo.wProcessorArchitecture)
{
case 6:
return 64;
case 9:
return 64;
case 0:
return 32;
default:
return -1;
}
}
static char *getArchType2() …Run Code Online (Sandbox Code Playgroud)