1,涉及API
GetNativeSystemInfo 原型:
void WINAPI GetNativeSystemInfo(
_Out_ LPSYSTEM_INFO lpSystemInfo
);
这个函数在kernel32.dll中。
SYSTEM_INFO 结构:
typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId; // 已废弃的成员,保留这个成员是为了向以前版本的Windows NT保持兼容
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, *LPSYSTEM_INFO;
2,使用
判断系统是否为64位系统的函数:
BOOL Is64BitSystem()
{
SYSTEM_INFO si;
FUN_GetNativeSystemInfo pfn = (FUN_GetNativeSystemInfo)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo");
if (pfn)
{
pfn(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
return TRUE;
}
}
return FALSE;
}
当然,目前不是64位,应该可以说就是32位系统了,可以直接写出获取系统位数的函数:
int GetSystemBits()
{
SYSTEM_INFO si;
FUN_GetNativeSystemInfo pfn = (FUN_GetNativeSystemInfo)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo");
if (pfn)
{
pfn(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
{
return 64;
}
}
return 32;
}