获取Window是32位还是64位系统
程序员文章站
2022-06-14 23:01:30
...
Windows常用的两个获取系统信息的API:
void WINAPI GetNativeSystemInfo(
_Out_ LPSYSTEM_INFO lpSystemInfo
);
void WINAPI GetSystemInfo(
_Out_ LPSYSTEM_INFO lpSystemInfo
);
lpSystemInfo :指向一个供函数返回信息的SYSTEM_INFO结构体。
SYSTEM_INFO结构体定义如下:
typedef struct _SYSTEM_INFO
{
union
{
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
};
};
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO;[1]
SYSTEM_INFO结构体参数说明:
wProcessorArchitecture: Word; {处理器的体系结构}
wReserved: Word; {保留}
dwPageSize: DWORD; {分页大小}
lpMinimumApplicationAddress: Pointer;{最小寻址空间}
lpMaximumApplicationAddress: Pointer;{最大寻址空间}
dwActiveProcessorMask: DWORD; {处理器掩码; 0..31 表示不同的处理器}
dwNumberOfProcessors: DWORD; {处理器数目}
dwProcessorType: DWORD; {处理器类型}
dwAllocationGranularity: DWORD; {虚拟内存空间的粒度}
wProcessorLevel: Word; {处理器等级}
wProcessorRevision: Word); {处理器版本}
注意:GetSystemInfo支持的最低客户端/服务器
Minimum supported client
Windows 2000 Professional [desktop apps | Windows Store apps]
Minimum supported server
Windows 2000 Server [desktop apps | Windows Store apps]
GetNativeSystemInfo支持的最低客户端/服务器
Minimum supported client
Windows XP [desktop apps | Windows Store apps]
Minimum supported server
Windows Server 2003 [desktop apps | Windows Store apps]
因此在使用的过程中我们要注意平台的处理。
typedef void (WINAPI *LPFN_PGNSI)(LPSYSTEM_INFO);
int Is64BitSystem()
{
SYSTEM_INFO si;
int is64bit = 0;
HINSTANCE handle;
LPFN_PGNSI func;
SYSTEM_INFO * sip;
handle = LoadLibraryA("kernel32.dll");
if (handle)
{
func = (LPFN_PGNSI ) GetProcAddress(handle,"GetNativeSystemInfo");
if (func)
{
func(&si);
}
else
{
GetSystemInfo(&si);
}
FreeLibrary(handle);
}
else
{
GetSystemInfo(&si);
}
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
//64 位操作系统
is64bit = 1;
}
else
{
// 32 位操作系统
is64bit = 0;
}
return is64bit ;
}
上一篇: webpack 在配置中区分是dev还是build
下一篇: activity window
推荐阅读