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

Sven Barth pascaldragon at googlemail.com
Tue Mar 15 16:05:57 CET 2011


Am 15.03.2011 16:00, schrieb Marcos Douglas:
> On Tue, Mar 15, 2011 at 11:35 AM, Henry Vermaak<henry.vermaak at gmail.com>  wrote:
>> On 15 March 2011 14:25, Marcos Douglas<md at delfire.net>  wrote:
>>> On Tue, Mar 15, 2011 at 11:13 AM, Henry Vermaak<henry.vermaak at gmail.com>  wrote:
>>>>
>>>> On 15 March 2011 14:05, Marcos Douglas<md at delfire.net>  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



More information about the fpc-pascal mailing list