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

2011-03-15 Thread Robert Wolfe

On 3/15/2011 10:25 AM, Marcos Douglas wrote:

On Tue, Mar 15, 2011 at 11:13 AM, Henry Vermaak  wrote:

On 15 March 2011 14:05, Marcos Douglas  wrote:

Is there some function to know if the Windows is 32 or 64?

You can use the GetNativeSystemInfo function.  Check
TSystemInfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 to
see if it's 64 bit.

What unit?


I've used this function in Delphi (7) and didn't work:
function is64bitOS: boolean;
   var
 SysInfo: TSystemInfo;
   begin
 GetSystemInfo(SysInfo);
 Result := (
  (Sysinfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64)
   or (Sysinfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64)
   );
end;


Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal



Not sure this will work for you or not, but here is what I use:

Program OSType ;

Uses SysUtils;

Begin ;

   WriteLn ;
   {$IFDEF WIN32}
   WriteLn ('This is a 32-bit version of Windows.') ;
   {$ENDIF$}
   {$IFDEF WIN64}
   WriteLn ('This is a 64-bit version of Windows.') ;
   {$ENDIF}

End.

The value returned, however, depends on whether the 32-bit compiler of 
the 64-bit cross-compiler was used.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marcos Douglas
On Tue, Mar 15, 2011 at 1:40 PM, Marcos Douglas  wrote:
> On Tue, Mar 15, 2011 at 1:33 PM, Henry Vermaak  
> wrote:
>> On 15 March 2011 15:46, Marcos Douglas  wrote:
>>>
>>> Thanks Jeff, this also works and seems to be standard function to know
>>> if is a 32 or 64bits
>>
>> No, this won't work if your application is compiled for win64 (since
>> it won't run under the emulator), as Jeff mentioned.
>
> You're right.
> Look the parameter Wow64Process [out]:
> "(...)If the process is a 64-bit application running under 64-bit
> Windows, the value is also set to FALSE".
>
> http://msdn.microsoft.com/en-us/library/ms684139%28v=vs.85%29.aspx

My final test:

program iswin64;

{$mode objfpc}{$H+}

uses Classes, dynlibs, Windows;

const
  PROCESSOR_ARCHITECTURE_AMD64 = 9;
  PROCESSOR_ARCHITECTURE_IA64 = 6;

type
  TGetNativeSystemInfo = procedure (var lpSystemInfo: TSystemInfo); stdcall;

function Is64bits: Boolean;
var
  h: TLibHandle;
  si: TSystemInfo;
  getinfo: TGetNativeSystemInfo;
begin
  Result := False;
  H := GetModuleHandle('kernel32.dll');
  try
ZeroMemory(@SI, SizeOf(SI));
getinfo := TGetNativeSystemInfo(GetProcAddress(h, 'GetNativeSystemInfo'));
if not Assigned(@getinfo) then
  Exit;
getinfo(SI);
if SI.wProcessorArchitecture in
   [PROCESSOR_ARCHITECTURE_AMD64, PROCESSOR_ARCHITECTURE_IA64] then
  Result := True;
  finally
UnloadLibrary(H);
  end;
end;

begin
  writeln('WIN 64  ', Is64bits);
  readln;
end.


Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marcos Douglas
On Tue, Mar 15, 2011 at 1:33 PM, Henry Vermaak  wrote:
> On 15 March 2011 15:46, Marcos Douglas  wrote:
>>
>> Thanks Jeff, this also works and seems to be standard function to know
>> if is a 32 or 64bits
>
> No, this won't work if your application is compiled for win64 (since
> it won't run under the emulator), as Jeff mentioned.

You're right.
Look the parameter Wow64Process [out]:
"(...)If the process is a 64-bit application running under 64-bit
Windows, the value is also set to FALSE".

http://msdn.microsoft.com/en-us/library/ms684139%28v=vs.85%29.aspx

Thanks.

Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Henry Vermaak
On 15 March 2011 15:46, Marcos Douglas  wrote:
>
> Thanks Jeff, this also works and seems to be standard function to know
> if is a 32 or 64bits

No, this won't work if your application is compiled for win64 (since
it won't run under the emulator), as Jeff mentioned.

Henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marcos Douglas
On Tue, Mar 15, 2011 at 12:48 PM, Marco van de Voort  wrote:
> In our previous episode, Marcos Douglas said:
>> > ? ?if (IsWow64Process(GetCurrentProcess, IsWow64)) then
>> > ? ? Result := IsWow64
>> > ? end;
>> > ?FreeLibrary(hKernel32);
>> > end;
>>
>> Thanks Jeff, this also works and seems to be standard function to know
>> if is a 32 or 64bits
>> See http://msdn.microsoft.com/en-us/library/ms684139%28v=vs.85%29.aspx
>
> IIRC Delphi.about.com has Delphi code for this.

But I need it for FPC.


Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marco van de Voort
In our previous episode, Marcos Douglas said:
> > ? ?if (IsWow64Process(GetCurrentProcess, IsWow64)) then
> > ? ? Result := IsWow64
> > ? end;
> > ?FreeLibrary(hKernel32);
> > end;
> 
> Thanks Jeff, this also works and seems to be standard function to know
> if is a 32 or 64bits
> See http://msdn.microsoft.com/en-us/library/ms684139%28v=vs.85%29.aspx

IIRC Delphi.about.com has Delphi code for this.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marcos Douglas
On Tue, Mar 15, 2011 at 11:47 AM, DaWorm  wrote:
> 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;

Thanks Jeff, this also works and seems to be standard function to know
if is a 32 or 64bits
See http://msdn.microsoft.com/en-us/library/ms684139%28v=vs.85%29.aspx

Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marcos Douglas
On Tue, Mar 15, 2011 at 12:36 PM, Henry Vermaak  wrote:
> On 15 March 2011 15:19, Marcos Douglas  wrote:
>>
>> Right. But is better ignore the IA64?
>
> You can do whatever you like.  We chose to ignore it, since we don't
> support it.  You just have to check for the
> PROCESSOR_ARCHITECTURE_IA64, too, if you'd like to support it.  See
> the msdn page:
>
> http://msdn.microsoft.com/en-us/library/ms724958%28v=vs.85%29.aspx

OK, thanks.


Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Henry Vermaak
On 15 March 2011 15:19, Marcos Douglas  wrote:
>
> Right. But is better ignore the IA64?

You can do whatever you like.  We chose to ignore it, since we don't
support it.  You just have to check for the
PROCESSOR_ARCHITECTURE_IA64, too, if you'd like to support it.  See
the msdn page:

http://msdn.microsoft.com/en-us/library/ms724958%28v=vs.85%29.aspx

Henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marcos Douglas
On Tue, Mar 15, 2011 at 12:05 PM, Sven Barth
 wrote:
>> Weird. This code did not compile in this line:
>>  @GNSIProc := GetProcAddress(GetModuleHandle('kernel32.dll'),
>> 'GetNativeSystemInfo');
>>
>> Error: unit1.pas(46,2) Error: Can't assign values to an address
>>
>>
>
> Just a guess:
> Add {$mode delphi} at the top.
>
> Another solution would be:
> GNSIProc := TGNSIProc(GetProcAddress(...));

I forgot... =(  I just copied the code from Delphi to Lazarus... sorry.
I used the second solution.

>>> This ignores ia64, as you can see.
>>
>> What is ia64?
>
> A 64-bit architecture developed by Intel and supported by Windows server
> systems (although it should be dropped with one of the next versions?!) and
> Linux systems.
>
> Also see here:
> http://en.wikipedia.org/wiki/IA64

Right. But is better ignore the IA64?

I found this code to Delphi:
const
  PROCESSOR_ARCHITECTURE_AMD64 = 9;
  {$EXTERNALSYM PROCESSOR_ARCHITECTURE_AMD64}
  PROCESSOR_ARCHITECTURE_IA64 = 6;
  {$EXTERNALSYM PROCESSOR_ARCHITECTURE_IA64}

function GetNativeSystemInfo(var SystemInfo: TSystemInfo): Boolean;
type
  TGetNativeSystemInfo = procedure (var SystemInfo: TSystemInfo) stdcall;
var
  LibraryHandle: HMODULE;
  _GetNativeSystemInfo: TGetNativeSystemInfo;
begin
  Result := False;
  LibraryHandle := GetModuleHandle(kernel32);

  if LibraryHandle <> 0 then
  begin
_GetNativeSystemInfo := GetProcAddress(
  LibraryHandle, 'GetNativeSystemInfo');
if Assigned(_GetNativeSystemInfo) then
begin
  _GetNativeSystemInfo(SystemInfo);
  Result := True;
end
else
  GetSystemInfo(SystemInfo);
  end
  else
GetSystemInfo(SystemInfo);
end;

function IsWindows64: Boolean;
var
  ASystemInfo: TSystemInfo;
begin
  GetNativeSystemInfo(ASystemInfo);
  Result := ASystemInfo.wProcessorArchitecture in
[PROCESSOR_ARCHITECTURE_IA64, PROCESSOR_ARCHITECTURE_AMD64];
end;


So, IA64 is 6. That is correct?

Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Henry Vermaak
On 15 March 2011 15:00, Marcos Douglas  wrote:
>
> Weird. This code did not compile in this line:
>  @GNSIProc := GetProcAddress(GetModuleHandle('kernel32.dll'),
> 'GetNativeSystemInfo');
>
> Error: unit1.pas(46,2) Error: Can't assign values to an address

This was Delphi code, so remove the @.

Henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Sven Barth

Am 15.03.2011 16:00, schrieb Marcos Douglas:

On Tue, Mar 15, 2011 at 11:35 AM, Henry Vermaak  wrote:

On 15 March 2011 14:25, Marcos Douglas  wrote:

On Tue, Mar 15, 2011 at 11:13 AM, Henry Vermaak  wrote:


On 15 March 2011 14:05, Marcos Douglas  wrote:

Is there some function to know if the Windows is 32 or 64?


You can use the GetNativeSystemInfo function.  Check
TSystemInfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 to
see if it's 64 bit.


What unit?


None, since the minimum supported client is XP.  Try to load it yourself, e.g.:

type
  TGNSIProc = procedure (var lpSystemInfo: TSystemInfo); stdcall;

const
  PROCESSOR_ARCHITECTURE_AMD64 = 9;

function Isx64: Boolean;
var
  si: TSystemInfo;
  GNSIProc: TGNSIProc;
begin
  Result := False;
  ZeroMemory(@si, SizeOf(si));
  @GNSIProc := GetProcAddress(GetModuleHandle('kernel32.dll'),
'GetNativeSystemInfo');
  if @GNSIProc = nil then
Exit;
  GNSIProc(si);
  if si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 then
Result := True;
end;


Weird. This code did not compile in this line:
  @GNSIProc := GetProcAddress(GetModuleHandle('kernel32.dll'),
'GetNativeSystemInfo');

Error: unit1.pas(46,2) Error: Can't assign values to an address




Just a guess:
Add {$mode delphi} at the top.

Another solution would be:
GNSIProc := TGNSIProc(GetProcAddress(...));



This ignores ia64, as you can see.


What is ia64?


A 64-bit architecture developed by Intel and supported by Windows server 
systems (although it should be dropped with one of the next versions?!) 
and Linux systems.


Also see here:
http://en.wikipedia.org/wiki/IA64

Regards,
Sven
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marcos Douglas
On Tue, Mar 15, 2011 at 11:35 AM, Henry Vermaak  wrote:
> On 15 March 2011 14:25, Marcos Douglas  wrote:
>> On Tue, Mar 15, 2011 at 11:13 AM, Henry Vermaak  
>> wrote:
>>>
>>> On 15 March 2011 14:05, Marcos Douglas  wrote:
>>> > Is there some function to know if the Windows is 32 or 64?
>>>
>>> You can use the GetNativeSystemInfo function.  Check
>>> TSystemInfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 to
>>> see if it's 64 bit.
>>
>> What unit?
>
> None, since the minimum supported client is XP.  Try to load it yourself, 
> e.g.:
>
> type
>  TGNSIProc = procedure (var lpSystemInfo: TSystemInfo); stdcall;
>
> const
>  PROCESSOR_ARCHITECTURE_AMD64 = 9;
>
> function Isx64: Boolean;
> var
>  si: TSystemInfo;
>  GNSIProc: TGNSIProc;
> begin
>  Result := False;
>  ZeroMemory(@si, SizeOf(si));
>  @GNSIProc := GetProcAddress(GetModuleHandle('kernel32.dll'),
>    'GetNativeSystemInfo');
>  if @GNSIProc = nil then
>    Exit;
>  GNSIProc(si);
>  if si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 then
>    Result := True;
> end;

Weird. This code did not compile in this line:
 @GNSIProc := GetProcAddress(GetModuleHandle('kernel32.dll'),
'GetNativeSystemInfo');

Error: unit1.pas(46,2) Error: Can't assign values to an address


>
> This ignores ia64, as you can see.

What is ia64?


Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread DaWorm
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.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Henry Vermaak
On 15 March 2011 14:25, Marcos Douglas  wrote:
> On Tue, Mar 15, 2011 at 11:13 AM, Henry Vermaak  
> wrote:
>>
>> On 15 March 2011 14:05, Marcos Douglas  wrote:
>> > Is there some function to know if the Windows is 32 or 64?
>>
>> You can use the GetNativeSystemInfo function.  Check
>> TSystemInfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 to
>> see if it's 64 bit.
>
> What unit?

None, since the minimum supported client is XP.  Try to load it yourself, e.g.:

type
  TGNSIProc = procedure (var lpSystemInfo: TSystemInfo); stdcall;

const
  PROCESSOR_ARCHITECTURE_AMD64 = 9;

function Isx64: Boolean;
var
  si: TSystemInfo;
  GNSIProc: TGNSIProc;
begin
  Result := False;
  ZeroMemory(@si, SizeOf(si));
  @GNSIProc := GetProcAddress(GetModuleHandle('kernel32.dll'),
'GetNativeSystemInfo');
  if @GNSIProc = nil then
Exit;
  GNSIProc(si);
  if si.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 then
Result := True;
end;

This ignores ia64, as you can see.

Henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marcos Douglas
On Tue, Mar 15, 2011 at 11:13 AM, Henry Vermaak  wrote:
>
> On 15 March 2011 14:05, Marcos Douglas  wrote:
> > Is there some function to know if the Windows is 32 or 64?
>
> You can use the GetNativeSystemInfo function.  Check
> TSystemInfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 to
> see if it's 64 bit.

What unit?


I've used this function in Delphi (7) and didn't work:
function is64bitOS: boolean;
  var
SysInfo: TSystemInfo;
  begin
GetSystemInfo(SysInfo);
Result := (
 (Sysinfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64)
  or (Sysinfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_IA64)
  );
end;


Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Henry Vermaak
On 15 March 2011 14:05, Marcos Douglas  wrote:
> Is there some function to know if the Windows is 32 or 64?

You can use the GetNativeSystemInfo function.  Check
TSystemInfo.wProcessorArchitecture = PROCESSOR_ARCHITECTURE_AMD64 to
see if it's 64 bit.

Henry
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


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

2011-03-15 Thread Marcos Douglas
Is there some function to know if the Windows is 32 or 64?

Marcos Douglas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal