【系统信息获取】2,获取操作系统位数

1,涉及API


GetNativeSystemInfo 原型:

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. void WINAPI GetNativeSystemInfo(  
  2.   _Out_  LPSYSTEM_INFO lpSystemInfo  
  3. );  

这个函数在kernel32.dll中。


SYSTEM_INFO 结构:

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. typedef struct _SYSTEM_INFO {  
  2.     union {  
  3.         DWORD dwOemId;                  // 已废弃的成员,保留这个成员是为了向以前版本的Windows NT保持兼容  
  4.         struct {  
  5.             WORD wProcessorArchitecture;    //指定系统中的中央处理器的体系结构  
  6.             WORD wReserved;  
  7.         };  
  8.     };  
  9.     DWORD dwPageSize;  
  10.     LPVOID lpMinimumApplicationAddress;  
  11.     LPVOID lpMaximumApplicationAddress;  
  12.     DWORD_PTR dwActiveProcessorMask;  
  13.     DWORD dwNumberOfProcessors;  
  14.     DWORD dwProcessorType;  
  15.     DWORD dwAllocationGranularity;  
  16.     WORD wProcessorLevel;  
  17.     WORD wProcessorRevision;  
  18. } SYSTEM_INFO, *LPSYSTEM_INFO;  


2,使用


判断系统是否为64位系统的函数:

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. BOOL Is64BitSystem()  
  2. {  
  3.     SYSTEM_INFO si;  
  4.     FUN_GetNativeSystemInfo pfn = (FUN_GetNativeSystemInfo)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo");  
  5.     if (pfn)  
  6.     {  
  7.         pfn(&si);  
  8.           
  9.         if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||      
  10.             si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )  
  11.         {  
  12.             return TRUE;  
  13.         }  
  14.     }  
  15.     return FALSE;     
  16. }  

当然,目前不是64位,应该可以说就是32位系统了,可以直接写出获取系统位数的函数:

[cpp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. int GetSystemBits()  
  2. {  
  3.     SYSTEM_INFO si;  
  4.     FUN_GetNativeSystemInfo pfn = (FUN_GetNativeSystemInfo)GetProcAddress(GetModuleHandle("kernel32.dll"), "GetNativeSystemInfo");  
  5.     if (pfn)  
  6.     {  
  7.         pfn(&si);  
  8.           
  9.         if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||      
  10.             si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )  
  11.         {  
  12.             return 64;  
  13.         }  
  14.     }  
  15.     return 32;    
  16. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值