Re: [fpc-pascal] Function to know if WIN is 32 or 64
On Wed, Mar 16, 2011 at 3:21 PM, Robert Wolfe wrote: > On 3/16/2011 8:45 AM, Marcos Douglas wrote: >> >> [...] >> The problem already been resolved (see the begin of this thread). >> The program was compiled in 32-bits but I have to know what kind of OS >> is running because my program needs to install somethings. >> > > So you are writing your own application installer then? I wrote (done!) an installer to an old application that no have installer. Was my first ("real" or "in production") application using FPC and Lazarus. This old application uses Oracle, BDE and don't have installer... and, for my client, this is a big problem... I will talk about that in another thread. 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
On 3/16/2011 8:45 AM, Marcos Douglas wrote: On Wed, Mar 16, 2011 at 9:21 AM, Juha Manninen wrote: Marcos Douglas kirjoitti keskiviikko 16 maaliskuu 2011 13:18:41: On Wed, Mar 16, 2011 at 12:56 AM, Robert Wolfe wrote: 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. Interesting. But I think not works on my case. The compiler is 32-bits but Windows can vary. I was also thinking to suggest the compile time IFDEFs. If the application is compiled for 32-bits then it can behave like a 32-bit application. No need to check anything at runtime. For what do you need the run-time info? The problem already been resolved (see the begin of this thread). The program was compiled in 32-bits but I have to know what kind of OS is running because my program needs to install somethings. So you are writing your own application installer then? ___ 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
On Wed, Mar 16, 2011 at 2:23 PM, DaWorm wrote: > On Wed, Mar 16, 2011 at 11:25 AM, Marcos Douglas wrote: >>> I also had to make sure the code was >>> being ran as an administrator. >> >> That's nice. Can you share the function? > > Again, don't remember where I found this, Google or MSDN probably. > Only tested in Delphi. > > function IsAdmin: Boolean; > [..] Thanks, I will test. 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
On Wed, Mar 16, 2011 at 11:25 AM, Marcos Douglas wrote: >> I also had to make sure the code was >> being ran as an administrator. > > That's nice. Can you share the function? Again, don't remember where I found this, Google or MSDN probably. Only tested in Delphi. function IsAdmin: Boolean; { - Returns a boolean indicating whether or not user has admin privileges. (Call only when running under NT.) - } var hAccessToken : tHandle; ptgGroups : pTokenGroups; dwInfoBufferSize : DWORD; psidAdministrators : PSID; int: integer;// counter blnResult : boolean;// return flag const SECURITY_NT_AUTHORITY: SID_IDENTIFIER_AUTHORITY = (Value: (0,0,0,0,0,5)); // ntifs SECURITY_BUILTIN_DOMAIN_RID: DWORD = $0020; DOMAIN_ALIAS_RID_ADMINS: DWORD = $0220; DOMAIN_ALIAS_RID_USERS : DWORD = $0221; DOMAIN_ALIAS_RID_GUESTS: DWORD = $0222; DOMAIN_ALIAS_RID_POWER_: DWORD = $0223; begin Result := False; ptgGroups := nil; blnResult := OpenThreadToken( GetCurrentThread, TOKEN_QUERY, True, hAccessToken ); if ( not blnResult ) then begin if GetLastError = ERROR_NO_TOKEN then blnResult := OpenProcessToken( GetCurrentProcess, TOKEN_QUERY, hAccessToken ); end; if ( blnResult ) then try GetMem(ptgGroups, 1024); blnResult := GetTokenInformation( hAccessToken, TokenGroups, ptgGroups, 1024, dwInfoBufferSize ); CloseHandle( hAccessToken ); if ( blnResult ) then begin AllocateAndInitializeSid( SECURITY_NT_AUTHORITY, 2, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, psidAdministrators ); {$R-} for int := 0 to ptgGroups.GroupCount - 1 do if EqualSid( psidAdministrators, ptgGroups.Groups[ int ].Sid ) then begin Result := True; Break; end; {$R+} FreeSid( psidAdministrators ); end; finally FreeMem( ptgGroups ); end; end; ___ 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
On Wed, Mar 16, 2011 at 12:19 PM, DaWorm wrote: > On Wed, Mar 16, 2011 at 8:45 AM, Marcos Douglas wrote: >> The program was compiled in 32-bits but I have to know what kind of OS >> is running because my program needs to install somethings. > > That's why I needed it too. In my case, my code is always 32 bit, but > to install a smart card NULL driver, I needed to be able to adjust > both the 32 bit registry and the 64 bit registry. Just adjusting the > 32 bit registry wasn't enough. Exactly. > I also had to make sure the code was > being ran as an administrator. That's nice. Can you share the function? 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
On Wed, Mar 16, 2011 at 8:45 AM, Marcos Douglas wrote: > The program was compiled in 32-bits but I have to know what kind of OS > is running because my program needs to install somethings. That's why I needed it too. In my case, my code is always 32 bit, but to install a smart card NULL driver, I needed to be able to adjust both the 32 bit registry and the 64 bit registry. Just adjusting the 32 bit registry wasn't enough. I also had to make sure the code was being ran as an administrator. 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
On Wed, Mar 16, 2011 at 9:21 AM, Juha Manninen wrote: > Marcos Douglas kirjoitti keskiviikko 16 maaliskuu 2011 13:18:41: >> On Wed, Mar 16, 2011 at 12:56 AM, Robert Wolfe > wrote: >> > 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. >> >> Interesting. But I think not works on my case. The compiler is 32-bits >> but Windows can vary. > > I was also thinking to suggest the compile time IFDEFs. > If the application is compiled for 32-bits then it can behave like a 32-bit > application. No need to check anything at runtime. > > For what do you need the run-time info? The problem already been resolved (see the begin of this thread). The program was compiled in 32-bits but I have to know what kind of OS is running because my program needs to install somethings. 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
Marcos Douglas kirjoitti keskiviikko 16 maaliskuu 2011 13:18:41: > On Wed, Mar 16, 2011 at 12:56 AM, Robert Wolfe wrote: > > 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. > > Interesting. But I think not works on my case. The compiler is 32-bits > but Windows can vary. I was also thinking to suggest the compile time IFDEFs. If the application is compiled for 32-bits then it can behave like a 32-bit application. No need to check anything at runtime. For what do you need the run-time info? Regards, Juha ___ 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
On Wed, Mar 16, 2011 at 12:56 AM, Robert Wolfe wrote: > 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. Interesting. But I think not works on my case. The compiler is 32-bits but Windows can vary. 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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