Checking processor is 32 bit or 64 bit [duplicate]

折月煮酒 提交于 2019-12-12 03:49:11

问题


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

回答1:


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.

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.

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



来源:https://stackoverflow.com/questions/15811006/checking-processor-is-32-bit-or-64-bit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!