OSBits()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OSBits()

Post by ts-soft »

ProcessorArchitecture <> 0 ;#PROCESSOR_ARCHITECTURE_INTEL
always 64 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.
Image
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: OSBits()

Post by Danilo »

ts-soft wrote:ProcessorArchitecture <> 0 ;#PROCESSOR_ARCHITECTURE_INTEL
always 64 Bit
Is #PROCESSOR_ARCHITECTURE_ARM always <>0 and 32bit or 64bit ( for Windows 8 )?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OSBits()

Post by ts-soft »

Can this result ever come with PB EXE?
As long pb doesn't support ARM, this result can't come, not on windows 8 or other :wink:
Last edited by ts-soft on Sat May 26, 2012 3:15 pm, edited 1 time 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.
Image
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: OSBits()

Post by Little John »

KJ67 wrote:I think that Ts-soft's code checks if the CPU can run 64-bit code.
My processor can only run 32-bit code, so the result "64" is definitely wrong on my machine.

Regards, Little John
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OSBits()

Post by ts-soft »

Oh :oops: small typo, false member of structure (shit autocomplete and bad eyes :mrgreen: )

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()
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.
Image
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: OSBits()

Post by Danilo »

ts-soft wrote:Can this result ever come with PB EXE?
As long pb doesn't support ARM, this result can't come, not on windows 8 or other :wink:
3 MacOSX and 5 Linux users, at least 5.000 Windows users.

Yes, PB/Windows/ARM is the next big thing. ;)
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OSBits()

Post by ts-soft »

<offtopic>
However, the number of the MacOS and Linux user will rise if Windows 8 appears :mrgreen:
</offtopic>
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.
Image
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: OSBits()

Post by skywalk »

Windows only...

Code: Select all

Macro Is(expression)
  ((expression) And 1)  ;((expression) Or 0)
EndMacro
Procedure.s IIFs(expression,IsTrue.s,IsFalse.s)
  If Is(expression)
    ProcedureReturn IsTrue
  Else
    ProcedureReturn IsFalse
  EndIf
EndProcedure

Macro FL_FileExists(Fname)
  ;  0 = File or Folder does not exist
  ;  1 = File Exists
  ; -1 = Folder Exists
  ; Since FileSize() returns:
  ;       -1 = File Not found.
  ;       -2 = File is a directory.
  ;        0 = Empty File, > 1 = File Exists
  ;        FileSize() respects '*' wildcards and reports results accordingly.
  FileSize(Fname) + 1
EndMacro

Macro SL_Is64BitOS()
  ; Windows 64-bit OS Info
  ; ----------------------   ----------------------------------
  ; C:\Windows\System32      System directory for 64-bit files
  ; C:\Windows\SysWOW64      System directory for 32-bit files
  ; C:\Program Files         Apps directory for 64-bit files
  ; C:\Program Files (x86)   Apps directory for 32-bit files
  ; --------------------------------   -------------------------------------------------------------------
  ; WoW64 uses 3 DLLs                  Description
  ; --------------------------------   -------------------------------------------------------------------
  ; C:\Windows\System32\Wow64.dll      core interface to Windows NT kernel that translates between
  ;                                    32-bit & 64-bit calls including pointer & call stack manipulations
  ; C:\Windows\System32\Wow64win.dll   provide appropriate entry-points for 32-bit apps
  ; C:\Windows\System32\Wow64cpu.dll   switch processor from 32-bit to 64-bit mode
  ; 32-bit apps runnning on 64-bit OS are redirected, so query the existence of C:\Windows\SysWOW64\*.dll's
  FL_FileExists(GetEnvironmentVariable("WinDir")+"\SysWow64\*.dll")
EndMacro
MessageRequester("SL_Is64BitOS", IIFs(SL_Is64BitOS(),"64","32"), #MB_ICONINFORMATION)
Edit: modified given ts-soft's comments below.
Last edited by skywalk on Sat May 26, 2012 8:26 pm, edited 2 times in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OSBits()

Post by ts-soft »

@skywalk

The Systemdrive is not always C: and the windows Dir can have different Names!
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.
Image
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: OSBits()

Post by skywalk »

Thanks ts-soft, I modified previous code to allow for non-standard installs...

Code: Select all

FL_FileExists(GetEnvironmentVariable("WinDir")+"\System32\Wow64.dll")
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: OSBits()

Post by ts-soft »

The other problem is, a 32-Bit executable, on a 64-bit os, will not found the DLL. The exe use the syswow64 version of the path :wink:

This one works, but is to much code :wink:

Code: Select all

Prototype.i IsWow64Process(hProcess.i, Wow64Process.i)
Prototype.i Wow64EnableWow64FsRedirection(Wow64EnableRedirection.i)

Procedure.i DisableWow64FsRedirection(Flag.i)
  If OSVersion() >= #PB_OS_Windows_Vista
    Protected.i DLL = OpenLibrary(#PB_Any, "kernel32.dll")
    Protected.IsWow64Process IsWow64Process
    Protected.Wow64EnableWow64FsRedirection Wow64EnableWow64FsRedirection
    Protected.i IsWow64
    If DLL
      IsWow64Process = GetFunction(DLL, "IsWow64Process")
      Wow64EnableWow64FsRedirection = GetFunction(DLL, "Wow64EnableWow64FsRedirection")
      
      If IsWow64Process(GetCurrentProcess_(), @IsWow64)
        If IsWow64
          ProcedureReturn Wow64EnableWow64FsRedirection(Flag ! 1)
        EndIf
      EndIf
    EndIf
  EndIf
EndProcedure

Macro FL_FileExists(Fname)
  ;  0 = File or Folder does not exist
  ;  1 = File Exists
  ; -1 = Folder Exists
  ; Since FileSize() returns:
  ;       -1 = File Not found.
  ;       -2 = File is a directory.
  ;        0 = Empty File, > 1 = File Exists
  ;        FileSize() respects '*' wildcards and reports results accordingly.
  FileSize(Fname) + 1
EndMacro

Macro SL_Is64BitOS()
  ; Windows 64-bit OS Info
  ; ----------------------   ----------------------------------
  ; C:\Windows\System32      System directory for 64-bit files
  ; C:\Windows\SysWOW64      System directory for 32-bit files
  ; C:\Program Files         Apps directory for 64-bit files
  ; C:\Program Files (x86)   Apps directory for 32-bit files
  ; --------------------------------   -------------------------------------------------------------------
  ; WoW64 uses 3 DLLs                  Description
  ; --------------------------------   -------------------------------------------------------------------
  ; C:\Windows\System32\Wow64.dll      core interface to Windows NT kernel that translates between
  ;                                    32-bit & 64-bit calls including pointer & call stack manipulations
  ; C:\Windows\System32\Wow64win.dll   provide appropriate entry-points for 32-bit apps
  ; C:\Windows\System32\Wow64cpu.dll   switch processor from 32-bit to 64-bit mode
  FL_FileExists(GetEnvironmentVariable("WinDir")+"\System32\Wow64.dll") 
EndMacro

DisableWow64FsRedirection(#True)
Debug SL_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.
Image
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: OSBits()

Post by skywalk »

Sorry ts-soft, I didn't run the code on x64 machine. :oops:
This works...

Code: Select all

  ; 32-bit apps runnning on 64-bit OS are redirected, so query the existence of C:\Windows\SysWOW64\*.dll's
  FL_FileExists(GetEnvironmentVariable("WinDir")+"\SysWow64\*.dll")
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: OSBits()

Post by nco2k »

Code: Select all

Procedure OSBitness()
  CompilerSelect SizeOf(Integer)
    CompilerCase 4
      Protected Result, Library, *Function, Wow64Process
      Library = OpenLibrary(#PB_Any, "Kernel32.dll")
      If Library
        *Function = GetFunction(Library, "IsWow64Process")
        If *Function
          If CallFunctionFast(*Function, GetCurrentProcess_(), @Wow64Process)
            If Wow64Process
              Result = 64
            Else
              Result = 32
            EndIf
          EndIf
        Else
          Result = 32
        EndIf
        CloseLibrary(Library)
      EndIf
      ProcedureReturn Result
    CompilerCase 8
      ProcedureReturn 64
  CompilerEndSelect
EndProcedure
Debug OSBitness()
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Thorium
Addict
Addict
Posts: 1305
Joined: Sat Aug 15, 2009 6:59 pm

Re: OSBits()

Post by Thorium »

Danilo wrote:
ts-soft wrote:ProcessorArchitecture <> 0 ;#PROCESSOR_ARCHITECTURE_INTEL
always 64 Bit
Is #PROCESSOR_ARCHITECTURE_ARM always <>0 and 32bit or 64bit ( for Windows 8 )?
There are no 64 bit ARM CPU's. They are allways 32 bit and 16 bit depending on the instruction set you use: ARM or Thumb.
Post Reply