Is this code adequate to test for a 64-bit processor, or is there a better solution?
[code] #If TargetWin32 then // If on windows 32-bit and 64-bit
Dim S as string
If isWOW64 = true Then
Self.BackColor = &c252AFF 'Blue
'me.Caption = "64"
S = "This is a 64-Bit Windows OS"
else
Self.BackColor = &c1EB126 'Green
'me.Caption = "32"
S = "This is a 32-Bit Windows OS"
end if
#If Targetx86 then
'Self.BackColor = &c1EB126 'Green
S = S + chr(13) + "This computer is operating on a 32-bit processor"
#else
'Self.BackColor = &c252AFF 'Blue
S = S + chr(13) + "This computer is operating on a 64-bit processor"
#EndIf
'msgbox S
EditField1.text = OS + chr(13) + S
#IF are compile time for starters… they have no affect after your app is compiled
Targetx86 only indicates it is a x86 compatible processors, of which there are 32bit versions
[quote=379923:@Dave S]#IF are compile time for starters… they have no affect after your app is compiled
Targetx86 only indicates it is a x86 compatible processors, of which there are 32bit versions
So, No I don’t think that will work
also… what is “isWOW64”?[/quote]
True. If it’s a 32-bit app running on a 64-bit processor, Target64Bit doesn’t tell you that.
Ive described it in two articles in xDev 14.3 and 14.4. While there are many ways to get the information, some can provide wrong answers under certain circumstances. But in a nutshell on how to do it correctly (Xojo isnt by the way):
One methods is, of course, to read in the Windows registry the value for the key HARDWARE\DESCRIPTION\System\CentralProcessor. But the much more powerful one is WMIC: The Windows Management Instrumentation Command-line.
wmic COMPUTERSYSTEM get NumberOfProcessors
To get the number of Cores and and Logical processors you use:
wmic CPU get NumberOfCores, NumberOfLogicalProcessors
Dim S as string
#If TargetWindows then // If on windows
#If Target64bit
Self.BackColor = &c252AFF 'Blue
'me.Caption = "64"
S = "This is a 64-Bit Windows OS"
S = S + chr(13) + "This computer is operating on a 64-bit processor"
#elseif Target32Bit
Self.BackColor = &c1EB126 'Green
'me.Caption = "32"
S = "This is a 32-Bit Windows OS"
S = S + chr(13) + "This computer is operating on a 32-bit processor"
#else
Self.BackColor = &cFF0000 'Red
S = "This is Windows on something we dont recognize"
#endif
EditField1.text = S
#Endif
Protected Function Is64BitOS() As Boolean
Dim theResult As Boolean
theResult = False
#If TargetWin32 Then
#If Target64Bit Then
'this is a 64 bit app so the operating system must be 64 bit
theResult = True
#Else
Soft Declare Function IsWow64Process Lib "Kernel32" (handle As Integer, ByRef result As Boolean) As Integer
Dim value As Boolean
If System.IsFunctionAvailable("IsWow64Process", "Kernel32") = True Then
If IsWow64Process(ProcessManagement.GetCurrentProcessID, value) > 0 Then
theResult = value
End If
End If
#EndIf
#Else
'not windows so just say it is 64 bit
theResult = True
#EndIf
Return theResult
End Function
This code should tell you if MS-Windows is 64 bit or not.
NOTE. The code is currently returning true for other platforms as we only care about Macs and they will be 64 bit.