[fpc-pascal] Function to know if WIN is 32 or 64

DaWorm daworm at gmail.com
Tue Mar 15 15:47:20 CET 2011


I've used this in Delphi 32 and it seems to work.  Forgot where I
pulled the basic info.  Probably doesn't do much on native 64 bit.

function Is64BitOS: Boolean;
type
  TIsWow64Process = function(Handle:THandle; var IsWow64 : BOOL) :
BOOL; stdcall;
var
  hKernel32 : Integer;
  IsWow64Process : TIsWow64Process;
  IsWow64 : BOOL;
begin
  // we can check if the operating system is 64-bit by checking whether
  // we are running under Wow64 (we are 32-bit code). We must check if this
  // function is implemented before we call it, because some older versions
  // of kernel32.dll (eg. Windows 2000) don't know about it.
  // see http://msdn.microsoft.com/en-us/library/ms684139%28VS.85%29.aspx
  Result := False;
  hKernel32 := LoadLibrary('kernel32.dll');
  if (hKernel32 = 0) then RaiseLastOSError;
  @IsWow64Process := GetProcAddress(hkernel32, 'IsWow64Process');
  if Assigned(IsWow64Process) then
   Begin
    IsWow64 := False;
    if (IsWow64Process(GetCurrentProcess, IsWow64)) then
     Result := IsWow64
   end;
  FreeLibrary(hKernel32);
end;

Jeff.



More information about the fpc-pascal mailing list