Detect Win-64, NumberOfProcessors,CPU-Type

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rings
Moderator
Moderator
Posts: 1435
Joined: Sat Apr 26, 2003 1:11 am

Detect Win-64, NumberOfProcessors,CPU-Type

Post by Rings »

Code updated For 5.20+

while playing with X64,

Code: Select all

SysInfo64.SYSTEM_INFO  
hLib = LoadLibrary_("KERNEL32.DLL")
Message.s
C.s=Chr(13)+Chr(10)
If hLib  
 ProcSI = GetProcAddress_(hLib, "GetNativeSystemInfo") 
 If ProcSI
  RetL=CallFunctionFast(ProcSI ,@SysInfo64) 
  Message = "Processors type:" + Str(SysInfo64\dwProcessorType) + C
  Message = Message + "Number of processors:" + Str(SysInfo64\dwNumberOfProcessors) + C + C
 EndIf
 ProcWow = GetProcAddress_(hLib, "IsWow64Process")
 If ProcWow 
  PID=GetCurrentProcess_()
  RetL=CallFunctionFast(ProcWow ,PID, @Wow64) 
  If Wow64 
       Message = Message + "Running under a 64 bit OS !" + C 
     Else
       Message = Message + "Running under a 32 bit OS !" + C  
  EndIf  
 Else
    Message = Message + "IsWow64Process function not supported" + C 
 EndIf
EndIf 

MessageRequester("Info",Message,0)
SPAMINATOR NR.1
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Microsoft Platform SDK :

Code: Select all

#include <windows>

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

LPFN_ISWOW64PROCESS 
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle("kernel32"),"IsWow64Process");
 
BOOL IsWow64()
{
    BOOL bIsWow64 = FALSE;
 
    if (NULL != fnIsWow64Process)
    {
        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
        {
            // handle error
        }
    }
    return bIsWow64;
}
one Purebasic 4.0 translation :

Code: Select all

Procedure.l IsWow64() ; For PB4.0
  
  Protected bIsWow64.l = #False
  
  fnIsWow64Process = GetProcAddress_(GetModuleHandle_("kernel32"), "IsWow64Process")
  
  If fnIsWow64Process ; Windows XP +
    If Not CallFunctionFast(fnIsWow64Process, GetCurrentProcess_(), @bIsWow64)
      ; handle error
    EndIf
  EndIf
  
  ProcedureReturn bIsWow64
  
EndProcedure
another one :

Code: Select all

Prototype IsWow64Process(pid.l, *bResult)

Procedure.l IsWow64() ; For PB4.0
  
  Protected bIsWow64.l = #False
  
  fnIsWow64Process.IsWow64Process = GetProcAddress_(GetModuleHandle_("kernel32"), "IsWow64Process")
  
  If fnIsWow64Process ; Windows XP+
    If Not fnIsWow64Process(GetCurrentProcess_(), @bIsWow64)
      ; handle error
    EndIf
  EndIf
  
  ProcedureReturn bIsWow64
  
EndProcedure
:)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

Very cool, thanks :)
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
Post Reply