Page 1 of 1

Detect Win-64, NumberOfProcessors,CPU-Type

Posted: Sat Nov 05, 2005 1:58 pm
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)

Posted: Wed Jul 05, 2006 9:04 am
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
:)

Posted: Wed Jul 05, 2006 2:41 pm
by GeoTrail
Very cool, thanks :)