0

何时将处理器视为 32 位或 64 位?我想检查 PC 是 32 位还是 64 位处理器。那么如何在 vb6 代码中检查它呢?当我研究它时,我知道我应该检查SYSTEM_INFO中的 wProcessorArchitecture 。当我根据它检查时,我的 Windows 8 电脑返回为 32 位。但是当我检查计算机属性时,它显示基于 x64 的处理器。这是代码的一部分

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
4

1 回答 1

0

GetNativeSystemInfo不返回处理器的体系结构。相反,它返回操作系统的体系结构。即,在 32 位版本的 Windows 中调用它时,您总是得到“32 位”。

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

w处理器架构

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

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

于 2013-04-05T18:55:50.530 回答