Testing for 64-Bit processor

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

#Endif[/code]

Thanks.

Lennox

#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”?

Why not use:

[code]#if Target64Bit

#Endif[/code]

[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.

what is “isWOW64”?

https://www.google.com/search?client=safari&rls=en&q=isWOW64&nirf=isWOW64process&sa=X&ved=0ahUKEwjBpe-Ipo_aAhVrkuAKHf45D8sQ8BYIJSgB&biw=1502&bih=901

Lennox

Thanks Greg,

I’ll try that.

Lennox

So how can I test if a 64bit processor is installed?

Thanks.

Lennox

if you have WOW64 working… isn’t that your answer?

OK, this is the problem.

I am trying to install OpenCv on my PC with CMake and I get this error…

… : fatal error LNK 1112: module type ‘x64’ conflicts with target machine type ‘x86’

Is that suggesting that my processor is not a 64bit processor

Thanks.

Lennox

[quote=379939:@Lennox Jacob]OK, this is the problem.

I am trying to install OpenCv on my PC with CMake and I get this error…

… : fatal error LNK 1112: module type ‘x64’ conflicts with target machine type ‘x86’

Is that suggesting that my processor is not a 64bit processor

Thanks.

Lennox[/quote]
All that means is that your OS is 32-bit.

I’ve 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 isn’t 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

Thanks Markus, I’ll try that.
Lennox

Thanks Greg, Markus and Dave,

I don’t have that machine right now so later today I’ll check and see what the other errors are.

Thanks again.

Lennox

For example, to get the serial number of hard disks we can simply use:

wmic path win32_physicalmedia get SerialNumber

Now WMIC is based on aliases. We can list the available aliases with:

wmic /?

but if I list the complete output, then this article has run out of space. Instead, lets just mention some aliases that you might find useful:

? OS: Operating System

? BIOS: BIOS management

? COMPUTERSYSTEM: Computer System management

? CPU: Central Processing Unit management

? MEMPHYSICAL: Physical memory management

? NIC: Network Interface Controller management

? DISKDRIVE: Physical disk drive

To get a brief overview of an alias, open CMD and run:

wmic alias list brief

For a full alias overview use:

wmic alias list full

For detecting 64Bit Windows from 32bit app you can use Is64bitWindows function:

http://www.monkeybreadsoftware.net/module-systeminformationmbs.shtml

But most apps don’t need to know that.

It seems to me like you need the bitness of the OS, 32 or 64 bit, instead of the CPU.

I think he wants to know both:

[quote]OK, this is the problem.

I am trying to install OpenCv on my PC with CMake and I get this error…

… : fatal error LNK 1112: module type ‘x64’ conflicts with target machine type ‘x86’

Is that suggesting that my processor is not a 64bit processor

Thanks.

Lennox[/quote]

This code may help:

 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.