Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if the computer is 32-bit or 64-bit?

Tags:

x86

x86-64

vba

How do you determine if the computer you are on is a 32-bit machine or a 64-bit machine?

I need this done in vba preferrably.

like image 318
if_zero_equals_one Avatar asked Dec 22 '22 13:12

if_zero_equals_one


1 Answers

@Wouter Simon's answer is sort of on the right track, but really incomplete. It is missing a couple of Declare statements as well as some kind of explanation.

Therefore I believe it's worth presenting a more complete and working version here.

Private Declare Function GetProcAddress Lib "kernel32" _
    (ByVal hModule As Long, _
    ByVal lpProcName As String) As Long

Private Declare Function GetModuleHandle Lib "kernel32" _
    Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long '()

Private Declare Function GetCurrentProcess Lib "kernel32" () As Long

Private Declare Function IsWow64Process Lib "kernel32" _
    (ByVal hProcess As Long, ByRef Wow64Process As Long) As Long

Sub CheckWhetherIts64()

    Dim Its64 As Long
    Dim handle As Long

    handle = GetProcAddress(GetModuleHandle("kernel32"), _
                   "IsWow64Process")

    If handle > 0 Then ' IsWow64Process function exists
        ' Now use the function to determine if
        ' we are running under Wow64

        IsWow64Process GetCurrentProcess(), Its64
    End If
    If Its64 = 1 Then
        MsgBox "it's a 64 bit process."
    End If
End Sub

Caveat:

For compatibility with operating systems that do not support this function, call GetProcAddress to detect whether IsWow64Process is implemented in Kernel32.dll. If GetProcAddress succeeds, it is safe to call this function. Otherwise, WOW64 is not present. Note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows because the Kernel32.dll in current versions of 32-bit Windows also contains this function.

http://msdn.microsoft.com/en-us/library/ms684139%28v=vs.85%29.aspx

like image 90
Jean-François Corbett Avatar answered Dec 26 '22 12:12

Jean-François Corbett