[fpc-pascal] Function to know if WIN is 32 or 64
Marcos Douglas
md at delfire.net
Tue Mar 15 17:41:18 CET 2011
On Tue, Mar 15, 2011 at 1:40 PM, Marcos Douglas <md at delfire.net> wrote:
> On Tue, Mar 15, 2011 at 1:33 PM, Henry Vermaak <henry.vermaak at gmail.com> wrote:
>> On 15 March 2011 15:46, Marcos Douglas <md at delfire.net> 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
More information about the fpc-pascal
mailing list