Page 2 of 2

Re: OSBits()

Posted: Sat May 26, 2012 3:03 pm
by ts-soft
ProcessorArchitecture <> 0 ;#PROCESSOR_ARCHITECTURE_INTEL
always 64 Bit

Re: OSBits()

Posted: Sat May 26, 2012 3:07 pm
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 )?

Re: OSBits()

Posted: Sat May 26, 2012 3:13 pm
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:

Re: OSBits()

Posted: Sat May 26, 2012 3:15 pm
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

Re: OSBits()

Posted: Sat May 26, 2012 3:21 pm
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()

Re: OSBits()

Posted: Sat May 26, 2012 3:22 pm
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. ;)

Re: OSBits()

Posted: Sat May 26, 2012 3:41 pm
by ts-soft
<offtopic>
However, the number of the MacOS and Linux user will rise if Windows 8 appears :mrgreen:
</offtopic>

Re: OSBits()

Posted: Sat May 26, 2012 4:10 pm
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.

Re: OSBits()

Posted: Sat May 26, 2012 4:16 pm
by ts-soft
@skywalk

The Systemdrive is not always C: and the windows Dir can have different Names!

Re: OSBits()

Posted: Sat May 26, 2012 5:28 pm
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")

Re: OSBits()

Posted: Sat May 26, 2012 5:39 pm
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()

Re: OSBits()

Posted: Sat May 26, 2012 8:23 pm
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")

Re: OSBits()

Posted: Sat May 26, 2012 11:00 pm
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

Re: OSBits()

Posted: Tue May 29, 2012 2:38 pm
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.