OSBits()
-
- Addict
- Posts: 4779
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
OSBits()
Hi all,
we already have the function OSVersion(). As an addition, a function named say OSBits() would be useful, which in these days would return 32 or 64, respectively.
Regards, Little John
we already have the function OSVersion(). As an addition, a function named say OSBits() would be useful, which in these days would return 32 or 64, respectively.
Regards, Little John
Last edited by Little John on Sat May 26, 2012 11:27 am, edited 2 times in total.
Re: OSBits()
Something like this?
Code: Select all
Macro IntegerInBits()
(SizeOf(Integer) * 8)
EndMacro
The best preparation for tomorrow is doing your best today.
-
- Addict
- Posts: 4779
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: OSBits()
Does this tell the size at compile time or at run time?
I want a function that returns the size at run time.
Unfortunately, I don't have a 64 bit system for testing.
Regards, Little John
I want a function that returns the size at run time.
Unfortunately, I don't have a 64 bit system for testing.
Regards, Little John
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Re: OSBits()
Compile time.Little John wrote:Does this tell the size at compile time or at run time?
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Re: OSBits()
Runtime, Windows OS:
Code: Select all
#PROCESSOR_ARCHITECTURE_INTEL = 0
#PROCESSOR_ARCHITECTURE_AMD64 = 9
;Import "kernel32.lib"
; GetNativeSystemInfo(*si.SYSTEM_INFO)
;EndImport
Procedure GetSystemInfo(*si.SYSTEM_INFO)
Protected kernel32.i
If OSVersion() < #PB_OS_Windows_XP
GetSystemInfo_(*si)
Else
kernel32 = OpenLibrary(#PB_Any,"kernel32.dll")
If kernel32
CallFunction(kernel32,"GetNativeSystemInfo",*si)
CloseLibrary(kernel32)
EndIf
EndIf
EndProcedure
Procedure OSBits()
Protected si.SYSTEM_INFO
GetSystemInfo(si)
If si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_INTEL
ProcedureReturn 32 ;#PB_Processor_x86
ElseIf si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_AMD64
ProcedureReturn 64 ;#PB_Processor_x64
EndIf
EndProcedure
Debug OSBits()
Re: OSBits()
There is no test required for WinVersion before WinXP, is always 32-Bit 

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.

Re: OSBits()
The test for '< XP' is required for the function GetNativeSystemInfo_(), whichts-soft wrote:There is no test required for WinVersion before WinXP, is always 32-Bit
is available on WinXP+. GetSytemInfo_() returns 32bit OS if running in Wow64,
whereas GetNativeSystemInfo returns the correct value.
Same same but different:
Code: Select all
#PROCESSOR_ARCHITECTURE_INTEL = 0
#PROCESSOR_ARCHITECTURE_AMD64 = 9
Procedure OSBits()
Protected si.SYSTEM_INFO, kernel32.i
If OSVersion() < #PB_OS_Windows_XP
ProcedureReturn 32 ;#PB_Processor_x86
Else
kernel32 = OpenLibrary(#PB_Any,"kernel32.dll")
If kernel32
CallFunction(kernel32,"GetNativeSystemInfo",@si)
CloseLibrary(kernel32)
If si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_INTEL
ProcedureReturn 32 ;#PB_Processor_x86
ElseIf si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_AMD64
ProcedureReturn 64 ;#PB_Processor_x64
EndIf
EndIf
EndIf
EndProcedure
Debug OSBits()
Re: OSBits()
The result of the missing function on < XP is always 0 = 32-Bit!
See here: http://purebasic.fr/english/viewtopic.p ... 72#p256372
See here: http://purebasic.fr/english/viewtopic.p ... 72#p256372
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.

Re: OSBits()
What are you trying to say?ts-soft wrote:The result of the missing function on < XP is always 0 = 32-Bit!
See here: http://purebasic.fr/english/viewtopic.p ... 72#p256372

Your code at the link contains:
Code: Select all
Import ""
GetNativeSystemInfo(*info)
EndImport
My codes work on all >= 32bit Windows.
Re: OSBits()
My english is bad
Only this check is required (but doesn't make a difference)
My links should show the code by Freak
// edit
Code fixed!

Only this check is required (but doesn't make a difference)
Code: Select all
Procedure OSBits()
Protected si.SYSTEM_INFO, result = 32
Protected DLL = OpenLibrary(#PB_Any, "Kernel32.dll")
If DLL
If GetFunction(DLL,"GetNativeSystemInfo")
CallFunction(DLL, "GetNativeSystemInfo", @si)
If si\wProcessorArchitecture
result = 64
EndIf
EndIf
CloseLibrary(DLL)
EndIf
ProcedureReturn result
EndProcedure
Debug OSBits()
// edit
Code fixed!
Last edited by ts-soft on Sat May 26, 2012 3:25 pm, edited 2 times in total.
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.

Re: OSBits()
So optimized. Thank you, ts-soft!
-
- Addict
- Posts: 4779
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: OSBits()
Many thanks to all of you!
Danilo's first code is correct here (Windows XP Professional SP3 32 bit), as well as Freak's code to which ts-soft has posted the link. But ts-soft, your last "optimized" code wrongly returns 64 here.
Thanks again, and Happy Whitsun!
Little John
Danilo's first code is correct here (Windows XP Professional SP3 32 bit), as well as Freak's code to which ts-soft has posted the link. But ts-soft, your last "optimized" code wrongly returns 64 here.
Thanks again, and Happy Whitsun!
Little John
Re: OSBits()
I think that Ts-soft's code checks if the CPU can run 64-bit code.
The best preparation for tomorrow is doing your best today.
-
- PureBasic Expert
- Posts: 4229
- Joined: Sat Apr 26, 2003 8:27 am
- Location: Strasbourg / France
- Contact:
Re: OSBits()
Yes, it should beKJ67 wrote:I think that Ts-soft's code checks if the CPU can run 64-bit code.
Code: Select all
#PROCESSOR_ARCHITECTURE_AMD64 = 9
Procedure OSBits()
Protected si.SYSTEM_INFO, result = 32
Protected DLL = OpenLibrary(#PB_Any, "Kernel32.dll")
If DLL
If GetFunction(DLL,"GetNativeSystemInfo")
CallFunction(DLL, "GetNativeSystemInfo", @si)
If si\wProcessorArchitecture = #PROCESSOR_ARCHITECTURE_AMD64
ProcedureReturn 64
EndIf
EndIf
CloseLibrary(DLL)
EndIf
ProcedureReturn result
EndProcedure
Debug OSBits()
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
Re: OSBits()
si\dwProcessorType:ts-soft wrote:Code: Select all
If si\dwProcessorType result = 64 EndIf
It's always true a.k.a. '>0'.dwProcessorType
An obsolete member that is retained for compatibility. Use the wProcessorArchitecture, wProcessorLevel, and wProcessorRevision members to determine the type of processor.
PROCESSOR_INTEL_386 (386)
PROCESSOR_INTEL_486 (486)
PROCESSOR_INTEL_PENTIUM (586)
PROCESSOR_INTEL_IA64 (2200)
PROCESSOR_AMD_X8664 (8664)