Having my x86 (32-bit) application running on various Windows versions - I need a way to know if my 32 bit application is running on Windows x86 (32-bit) or x64 (64 bit).
IsWow64ProcessThe IsWow64Process API function present in some versions of kernel32.dll can be used to determine whether the specified (32-bit) process is running under WOW64. WOW64, provided with the operating system, is the x86 emulator that allows 32-bit Windows-based applications to run seamlessly on 64-bit Windows.
Depending on the Windows version your Delphi application is being run on, the IsWow64Process API might be (or not) present in the kernel32.dll.
To check if your 32-bit Delphi application is running under 32-bit or 64-bit Windows, you need to:
- Have your application be 32 bit application (of course)
- Dynamically load the kernel32.dll (if it exists)
- Check (using GetProcAddress) if it exposes the IsWow64Process function
- If so, get the result of IsWow64Process
NOTE: If the process (your application returned by GetCurrentProcess) is a 64-bit application running under 64-bit Windows, the result would be FALSE.function Running32ON64: boolean; type TIsWow64Process = function(Handle:THandle; var IsWow64 : boolean) : boolean; stdcall; var hDLL : cardinal; IsWow64Process : TIsWow64Process; begin result := false; hDLL := LoadLibrary('kernel32.dll'); if (hDLL = 0) then Exit; try @IsWow64Process := GetProcAddress(hDLL, 'IsWow64Process'); if Assigned(IsWow64Process) then IsWow64Process(GetCurrentProcess, result); finally FreeLibrary(hDLL); end; end;
SysUtils.TOSVersion in Delphi XE 2If you have (at least) Delphi XE 2, you should better use the SysUtils.TOSVersion record as it exposes the Architecture property (TArchitecture enumeration) returning arIntelX86 (for 32 bit Windows) or arIntelX64 (for 64 bit Windows).
Delphi tips navigator:
» More Delphi TIPS
« ShellControls (TShellTreeView, TShellListView) In Delphi XE2