检查处理器是 32 位还是 64 位 [英] Checking processor is 32 bit or 64 bit

查看:38
本文介绍了检查处理器是 32 位还是 64 位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当处理器被认为是 32 位还是 64 位时?我想检查 PC 是 32 位还是 64 位处理器.那么如何在 vb6 代码中检查它呢?当我在研究它时,我发现我应该检查 SYSTEM_INFO.当我根据它检查时,我的 Windows 8 pc 返回为 32 位.但是当我检查计算机属性时,它显示基于 x64 的处理器.这是代码的一部分

When a processor is considered 32 bit or 64 bit? I want to check whether a PC is having 32 bit or 64 bit processor. So how can i check it in a vb6 code? While i was researching about it i got that i should check wProcessorArchitecture in SYSTEM_INFO. When i check according to it my windows 8 pc is returned as 32 bit.But when i check in computer properties it shows x64 based processor. here is a part of code

Option Explicit

Private Type SYSTEM_INFO
 wProcessorArchitecture        As Integer
 wReserved                     As Integer
 dwPageSize                    As Long
 lpMinimumApplicationAddress   As Long
 lpMaximumApplicationAddress   As Long
 dwActiveProcessorMask         As Long
 dwNumberOfProcessors          As Long
 dwProcessorType               As Long
 dwAllocationGranularity       As Long
 wProcessorLevel               As Integer
 wProcessorRevision            As Integer
End Type

Private Declare Sub GetNativeSystemInfo Lib "kernel32" (lpSystemInfo As SYSTEM_INFO)

'Constants for GetSystemInfo and GetNativeSystemInfo API functions (SYSTEM_INFO structure)
Private Const PROCESSOR_ARCHITECTURE_AMD64      As Long = 9         'x64 (AMD or Intel)
Private Const PROCESSOR_ARCHITECTURE_IA64       As Long = 6         'Intel Itanium Processor Family (IPF)
Private Const PROCESSOR_ARCHITECTURE_INTEL      As Long = 0         'x86
Private Const PROCESSOR_ARCHITECTURE_UNKNOWN    As Long = &HFFFF&   'Unknown architecture



Public Function IsOS64Bit() As Boolean
On Error GoTo ProcError

Dim typ_si      As SYSTEM_INFO

Call GetNativeSystemInfo(typ_si)
If (typ_si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64) Or (typ_si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64) Then
    IsOS64Bit = True
    MsgBox "64 bit"

Else
    IsOS64Bit = False
    MsgBox "32 bit"
     MsgBox typ_si.wProcessorArchitecture
End If

ProcClean:
Debug.Print "Exiting Function m_OS64.IsOS64Bit()"
Exit Function

ProcError:
If Err.Number <> 0 Then
    Debug.Print "An error occured in m_OS64.IsOS64Bit()"
    Debug.Print Err.Number & ": " & Err.Description
    Resume ProcClean
End If
End Function

Private Sub Command1_Click()
Call IsOS64Bit
End Sub

推荐答案

GetNativeSystemInfo 不返回处理器的架构.相反,它返回操作系统的架构.IE.在 32 位版本的 Windows 中调用它时总是得到32 位".

GetNativeSystemInfo does NOT return architecture of a processor. Instead it returns architecture of operating system. I.e. you always get "32 bit" when calling it in 32-bit version of Windows.

来自您在问题中引用的 MSDN 文章:

From MSDN article you referenced in the question:

wProcessorArchitecture

已安装操作系统的处理器架构.此成员可以是以下值之一.

The processor architecture of the installed operating system. This member can be one of the following values.

有关如何确定 CPU 架构的信息,请参阅此问题:检查操作系统和处理器是 32 位还是 64 位?

See this question for info on how to determine architecture of CPU: check OS and processor is 32 bit or 64 bit?

这篇关于检查处理器是 32 位还是 64 位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆