I just got a bug report for an issue that only occurs when the program is running "on a 64-bit machine." Now, Delphi doesn't produce 64-bit code, so theoretically that shouldn't matter, but apparently it does in this case. I think I have a workaround, but it will break things on 32-bit Windows, so I need some way to tell:
- If I'm running on a x64 or an x86 processor and
- If I'm running under a 64-bit version of Windows under Win32 emulation or native Win32 on a 32-bit OS.
Does anyone know how I can get those answers from within my app?
You can check for the existence of and then call IsWow64Process. The linked MSDN page shows the required code.
The MSDN page says:
Which means: this is a new function and you have to be careful statically linking to it.
if
sizeof(IntPtr) == 8
you're a 64-bit application on 64-bit Windows (edit: applies only to Delphi Prism)else if
IsWow64Process
succeeds and returns true, you're a 32-bit application on 64-bit Windowselse you're on 32-bit Windows
Mason, you can use IsWow64Process (WOW64 is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows)
Bye.
I see the your question 2 (are you running on Win64?) is already answered. Just keep in mind that for your code to be future-proof, you need to consider that in a (hypothetical) 64-bit Delphi app running on Win64, IsWow64Process would also return FALSE.
As regards your first question - are you on a 64-bit CPU -, you can check the hardware for the respective CPUID feature flag, like in the code below.
which uses the following two low-level functions:
EDIT1: A note on
CPUIDavailable
: This is of course assuming a >= 32-bit x86 processor (80386 or later), but Delphi Win32 code won't run on earlier machines anyway. The CPUID instruction was introduced with late 80486 processors.