Determing 32 or 64 bit
Determing 32 or 64 bit
In there a way with Purebaic to determine if the OS is 32 bit or 64 bit?
This isn't the right way to gomilan1612 wrote:This information is stored by Windows in this registry key:Keyname: PROCESSOR_ARCHITECTUREHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Code: Select all
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

It is more or less the same - all environment variables are stored in this registry keyts-soft wrote:This isn't the right way to gomilan1612 wrote:This information is stored by Windows in this registry key:Keyname: PROCESSOR_ARCHITECTUREHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
In 32-Bit PB Programs come "x86" and in 64-Bit PB-Programs come "AMD64"Code: Select all
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")

Your way is easier though...
Windows 7 & PureBasic 4.4
My way is wrong, the value was changed for emulated 32-bit application,
but in the registry is the right one, i think.
// edit
tested with PB 4.20
Run with Adminprivilege
The first Debug gives "AMD64" and the second "x86" in 32-Bit programs
on 64-bit OS
but in the registry is the right one, i think.
// edit
tested with PB 4.20
Code: Select all
EnableExplicit
Procedure.s Reg_ReadString(topKey.l, KeyName.s, ValueName.s)
Protected Result.s, hKey.l, lpData.s = Space(255), lpcbData.l, Error.l
lpcbData = (255 * SizeOf(Character)) + 1
If Right(KeyName, 1) = "\" : KeyName = Left(KeyName, Len(KeyName) - 1) : EndIf
Error = RegOpenKeyEx_(topKey, @KeyName, 0, #KEY_ALL_ACCESS, @hKey)
If Error = #ERROR_SUCCESS
Error = RegQueryValueEx_(hKey, @ValueName, 0, 0, @lpData, @lpcbData)
If Error = #ERROR_SUCCESS
Result = lpData
Else
lpData.s = Space(lpcbData)
Error = RegQueryValueEx_(hKey, @ValueName, 0, 0, @lpData, @lpcbData)
If Error = #ERROR_SUCCESS
Result = lpData
Else
Result = ""
EndIf
EndIf
EndIf
If hKey : RegCloseKey_(hKey) : EndIf
ProcedureReturn Result
EndProcedure
Debug Reg_ReadString(#HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "PROCESSOR_ARCHITECTURE")
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
The first Debug gives "AMD64" and the second "x86" in 32-Bit programs
on 64-bit OS
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Yes! Is the same result on intel-cpuSFSxOI wrote:Does it still return "AMD64" on intel chipsets and processors?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

The PROCESSOR_ARCHITECTURE environment variable is changed for 32 bit programs.
There is another variable PROCESSOR_ARCHITEW6432 present when running in WOW64 (32bit app on 64bit windows)
See here: http://blogs.msdn.com/david.wang/archiv ... tness.aspx
I would use the GetNativeSystemInfo() API function. Its only XP and newer, but these are the only versions with 64bit anyway, so if the function is not present, just assume 32bit.
This works without spechial priviledges:
(also works with PB64bit
)
There is another variable PROCESSOR_ARCHITEW6432 present when running in WOW64 (32bit app on 64bit windows)
See here: http://blogs.msdn.com/david.wang/archiv ... tness.aspx
I would use the GetNativeSystemInfo() API function. Its only XP and newer, but these are the only versions with 64bit anyway, so if the function is not present, just assume 32bit.
This works without spechial priviledges:
Code: Select all
Prototype GetNativeSystemInfo(*lpSystemInfo.SYSTEM_INFO)
#PROCESSOR_ARCHITECTURE_AMD64 = 9
#PROCESSOR_ARCHITECTURE_IA64 = 6
#PROCESSOR_ARCHITECTURE_INTEL = 0
#PROCESSOR_ARCHITECTURE_UNKNOWN = $ffff
Procedure Is64bitOS()
Protected kernel32, GetNativeSystemInfo.GetNativeSystemInfo
Protected info.SYSTEM_INFO
Protected Result = #False
kernel32 = OpenLibrary(#PB_Any, "Kernel32.dll")
If kernel32
GetNativeSystemInfo = GetFunction(kernel32, "GetNativeSystemInfo")
If GetNativeSystemInfo
GetNativeSystemInfo(@info)
If info\wProcessorArchitecture <> #PROCESSOR_ARCHITECTURE_INTEL ; x86
Result = #True
EndIf
EndIf
CloseLibrary(kernel32)
EndIf
ProcedureReturn Result
EndProcedure
Debug Is64bitOS()

quidquid Latine dictum sit altum videtur
Thanks freak 
Shortversion of freaks code:

Shortversion of freaks code:
Code: Select all
Import ""
GetNativeSystemInfo(*info)
EndImport
Procedure Is64bitOS()
Protected Info.SYSTEM_INFO
GetNativeSystemInfo(Info)
If info\wProcessorArchitecture
ProcedureReturn #True
EndIf
EndProcedure
Debug Is64bitOS()
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

- doctorized
- Addict
- Posts: 882
- Joined: Fri Mar 27, 2009 9:41 am
- Location: Athens, Greece
You can also try this:SFSxOI wrote:Nice examples everyone, thanks for the help.
Code: Select all
Procedure.l IsWin64() ;Tell us if the OS is x64 or not.
*Is64 = 0
If OpenLibrary(0,"KERNEL32.DLL")
*F = GetFunction(0,"IsWow64Process")
If *F
CallFunctionFast(*F,GetCurrentProcess_(), @*Is64)
EndIf
CloseLibrary(0)
EndIf
If *Is64>0
ProcedureReturn 1 ; True
Else
ProcedureReturn 0 ; False
EndIf
EndProcedure
Debug IsWin64()
- Arctic Fox
- Enthusiast
- Posts: 609
- Joined: Sun Dec 21, 2008 5:02 pm
- Location: Aarhus, Denmark
Re:
On my 64-bit PC, it returns "x86" because I use the 32-bit version of PureBasic.ts-soft wrote:In 32-Bit PB Programs come "x86" and in 64-Bit PB-Programs come "AMD64"Code: Select all
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
Just something to be aware of... it's therefore not reliable to use for testing.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Re:
ts-soft posted the same thing if you look at the quote.PB wrote:On my 64-bit PC, it returns "x86" because I use the 32-bit version of PureBasic.ts-soft wrote:In 32-Bit PB Programs come "x86" and in 64-Bit PB-Programs come "AMD64"Code: Select all
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
Just something to be aware of... it's therefore not reliable to use for testing.
freak's example and other's after him show correct results.