vitaliy-zh
vitaliy-zh

Reputation: 205

What is the best way to detect an ARM-CPU with Delphi?

What is the most reliable way to detect an ARM processor architecture using Delphi (running on Windows 11 ARM)?

Upvotes: 1

Views: 660

Answers (1)

HeartWare
HeartWare

Reputation: 8251

Remy's suggestion above is fine, but if you want to detect if an x86/x64 program is running on an ARM Windows, I think you can do it this way (untested, as I don't have access to an ARM Windows):

TYPE
  TImageFileMachine     = USHORT;
  TIsWow64Process2      = FUNCTION(Handle : THandle ; VAR ProcessMachine,NativeMachine : TImageFileMachine) : LongBool; stdcall;

CONST
  IMAGE_FILE_MACHINE_ARM64 = $AA64;

FUNCTION IsARM : BOOLEAN;
  VAR
    F   : TIsWow64Process2;
    P,N : TImageFileMachine;

  BEGIN
    @F:=GetProcAddress(GetModuleHandle('kernel32.dll'),'IsWow64Process2');
    IF NOT Assigned(F) THEN
      Result:=FALSE
    ELSE IF NOT F(GetCurrentProcess,P,N) THEN
      Result:=FALSE
    ELSE
      Result:=(N=IMAGE_FILE_MACHINE_ARM64)
  END;

Upvotes: 4

Related Questions