Win 32 or 64?

How can by app tell if it’r running on 32 or 64 bit windows OS?

Thanks,

  • Karen

If it’s path is in the ‘c:\program Files(x86)’ directory then it’s 64 bit windows :slight_smile:

I’m taking about a 32 bit Xojo app that needs to know what it is running on so it can call the right shell app that i package with it. I will include both 32 and 64 bit versions in the app Lib folder so it can work on either but it has to know which one to call

  • Karen

http://stackoverflow.com/questions/601089/detect-whether-current-windows-version-is-32-bit-or-64-bit has some ideas

Do not want to be rude but john bowen’s method is not the best. Just in case of some system not having that directory, you should not do that. And as you are not working with strings and the detection of a 64 bit OS is more flexible, you should write the following code: #If Target64Bit and TargetWin32 'Write 64 bit windows specific code here #Endif

https://documentation.xojo.com/index.php/#If...#Endif

[quote=35898:@Oliver Scott-Brown]Do not want to be rude but john bowen’s method is not the best. Just in case of some system not having that directory, you should not do that. And as you are not working with strings and the detection of a 64 bit OS is more flexible, you should write the following code: #If Target64Bit and TargetWin32 'Write 64 bit windows specific code here #Endif

https://documentation.xojo.com/index.php/#If...#Endif[/quote]
I forgot to say to ignore the ‘32’ at the end of ‘TargetWin32’, it just means the Windows OS.

[quote=35898:@Oliver Scott-Brown]Do not want to be rude but john bowen’s method is not the best. Just in case of some system not having that directory, you should not do that. And as you are not working with strings and the detection of a 64 bit OS is more flexible, you should write the following code: #If Target64Bit and TargetWin32 'Write 64 bit windows specific code here #Endif

https://documentation.xojo.com/index.php/#If...#Endif[/quote]
Also, don’t forget that if you could use this code if you wanted to execute code for when your Windows OS is not 64 bit.[code]
#If TargetWin32 then
'regardless of wether the computer is 64 bit or 32 bit this code won’t be executed unless the app is under Windows
#If Target64Bit then
'Write 64 bit windows specific code here
#Else
'Write 32 bit windows specific code
#Else

#Endif
#Endif
[/code]

Btw, the code I wrote earlier, apoligies, I forgot to end my if statement with ‘then’ because I always use the shift+enter shortcut key to make if statements.

I also forgot to state that you should read this for more information:
https://documentation.xojo.com/index.php/#If...#Endif

The Target constants only tell you information about the running app, not the details about the OS it is running on. So Target64Bit is always False now (regardless of whether you are running on 64-bit Windows) because Xojo apps are 32-bit.

I’ve used this code in the past:

[code]Protected Function IsWin64() As Boolean
#If TargetWin32 Then
Soft Declare Function GetCurrentProcess Lib “kernel32” As Integer
Dim processID As Integer
processID = GetCurrentProcess

Soft Declare Function IsWow64Process Lib "kernel32" (handle As Integer, ByRef result As Boolean) As Integer

If System.IsFunctionAvailable( "IsWow64Process", "Kernel32" ) Then

  Dim value As Boolean
  Call IsWow64Process(processID, value)

  Return value
Else
  Return False
End If

#Else
Return False
#Endif
End Function[/code]

[quote=35898:@Oliver Scott-Brown]Do not want to be rude but john bowen’s method is not the best. Just in case of some system not having that directory, you should not do that. And as you are not working with strings and the detection of a 64 bit OS is more flexible, you should write the following code: #If Target64Bit and TargetWin32 'Write 64 bit windows specific code here #Endif

https://documentation.xojo.com/index.php/#If...#Endif[/quote]
I thought that I read in another post that the Target64bit is not currently used?

Karen’s problem is a little more difficult, the app is obviously 32bit but can be run on 32bit or 64bit versions of the OS. I would look at this and some declares to make it work.

The result from calling IsWow64Process is described as:

A pointer to a value that is set to TRUE if the process is running under WOW64. If the process is running under 32-bit Windows, the value is set to FALSE. If the process is a 64-bit application running under 64-bit Windows, the value is also set to FALSE.

From the above link it looks like like this should work:

if System.EnvironmentVariable("PROGRAMFILES(x86)").trim = "" Then '32 bit else '64 Bit end if

i will try it post results here

on a 32 bit OS it is “” , but i have not tried it yet on a 64 bit os

thanks

  • Karen

You should not rely on the Program Files (X86) folder as an indicator of platform bitness. Use @Paul Lefebvre’s code as it will always be accurate.

Karen, just remember that with IsWow64Process() one day you will get a false when you have a 64bit app running on 64bit Windows :slight_smile: The function is testing if the process is running in WoW64 (Windows on Windows) which is a subsystem for running 32bit apps on the 64bit OS.

Yes, but I don’t think any of us will be worrying about 64 bit Xojo apps for quite some time yet :frowning:

[quote=35907:@Carl Clarke]I thought that I read in another post that the Target64bit is not currently used?

Karen’s problem is a little more difficult, the app is obviously 32bit but can be run on 32bit or 64bit versions of the OS. I would look at this and some declares to make it work.

The result from calling IsWow64Process is described as:

A pointer to a value that is set to TRUE if the process is running under WOW64. If the process is running under 32-bit Windows, the value is set to FALSE. If the process is a 64-bit application running under 64-bit Windows, the value is also set to FALSE.[/quote]
Oh yeah. Good point. I presumed it meant that it detected whether or not my OS was 64 bit because I knew that there is no 64 bit support.

Gee dont be so optimistic :stuck_out_tongue:

Prove me wrong, and I’ll consider looking on the bright side :wink: