Forum > Windows

Windows API test programs / Examples

<< < (12/12)

440bx:
Just an observation, you probably don't need to GetProcAddress the function since it is implemented in Windows XP and above.  IOW, you need the GetProcAddress only for O/Ses older than XP.

This also means that the "else" part of the "if Assigned" can report the O/S as being 32 bit (it cannot be anything else, at least on intel compatible hardware.)

Tested on 64 bit Windows and 32 bit Windows XP, not tested on any ARM cpu.

It would be nice to know if that method works on an ARM64.  Maybe PascalDragon can do that test if he is so inclined. ;)

part of my test program :
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function WndProc (Wnd : HWND; Msg : UINT; wParam, lParam : ptrint)         : ptrint; stdcall;  { main application/window handler function                                  }const  GetSystemWow64Directory_Call    = 'GetSystemWow64Directory (Buf : pchar; BufSize : UINT) : UINT;';   SystemWow64Directory : packed array[0..MAX_PATH] of char = #0;   NotImplemented       = 'There is no Wow64 directory in this installation';   DisplayText          : pchar = NotImplemented;  { 32 bit                    } var  ps           : TPAINTSTRUCT;  ClientRect   : TRECT;  Buf          : packed array[0..MAX_PATH] of char;  TextSize     : TSIZE; begin  WndProc := 0;   case Msg of    WM_CREATE:    begin      ZeroMemory(@SystemWow64Directory, sizeof(SystemWow64Directory));       if GetSystemWow64Directory(SystemWow64Directory,                          sizeof(SystemWow64Directory)) <> 0 then      begin        DisplayText := SystemWow64Directory;  { s/b 64 bit                    }      end;    end; 

PascalDragon:

--- Quote from: FlierMate on January 29, 2021, 04:03:18 pm ---I just need to replace plus sign with comma on my FPC 3.2.0:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Writeln('64-bit ', Buffer)
--- End quote ---

You need to compile with {$H+}.


--- Quote from: FlierMate on January 29, 2021, 04:03:18 pm ---Have you tested it? Not sure what is the result if running on 64-bit Windows (both ARM64 and AMD64).

--- End quote ---

The output is the following on both x86_64 and aarch64:


--- Code: ---64-bit C:\WINDOWS\SysWOW64
--- End code ---

Please note however that you can not detect whether you're running on Windows on ARM64 this way, only that you're running on a 64-bit system which is where IsWow64Process2 comes in if one doesn't want to parse an important PE file like csrss.exe as 440bx is doing.

FlierMate:

--- Quote from: 440bx on January 29, 2021, 04:18:06 pm ---Just an observation, you probably don't need to GetProcAddress the function since it is implemented in Windows XP and above......
Tested on 64 bit Windows and 32 bit Windows XP, not tested on any ARM cpu..

--- End quote ---

Good catch. And thanks for the testing.


--- Quote from: PascalDragon on January 30, 2021, 06:45:58 pm ---You need to compile with {$H+}.

The output is the following on both x86_64 and aarch64:


--- Code: ---64-bit C:\WINDOWS\SysWOW64
--- End code ---

Please note however that you can not detect whether you're running on Windows on ARM64 this way, only that you're running on a 64-bit system which is where IsWow64Process2 comes in if one doesn't want to parse an important PE file like csrss.exe as 440bx is doing.

--- End quote ---

Didn't know about the long string compiler directive, hah. And thanks a lot for helping to test it on ARM64 as well.
I admit that it would be good to know CPU architecture as well.

Can I say we have third method to check for Windows Bitness?    8)

From the reply of one of .NET user, he said he used:

--- Code: ---public static bool Is64BitOperatingSystem { get; }
--- End code ---

It is intriguing if System.Runtime.dll has some access to Win32 APIs, or has direct access to the operating system? Of course this is not in the scope of this series of topic discussion.

440bx:

--- Quote from: FlierMate on January 31, 2021, 08:22:42 am ---Good catch. And thanks for the testing.

--- End quote ---
You're welcome.


--- Quote from: FlierMate on January 31, 2021, 08:22:42 am ---Can I say we have third method to check for Windows Bitness?    8)

--- End quote ---
The method you've proposed looks quite reasonable but, the fact that MS does not acknowledge it could be used to determine the O/S bitness creates some doubt about its reliability.  The same can be said about GetNativeSystemInfo, at first glance, it would also seem to be a reasonable alternative but, given the fact that MS can muck around with either leaves open some room for discomfort.


--- Quote from: FlierMate on January 31, 2021, 08:22:42 am ---It is intriguing if System.Runtime.dll has some access to Win32 APIs, or has direct access to the operating system? Of course this is not in the scope of this series of topic discussion.

--- End quote ---
Access to the API is direct access to the O/S (at least its user mode part) and .NET most definitely has direct access to the API but, it is on the programmer's shoulders to ensure any direct access to the API doesn't violate assumptions the .NET framework makes about a .NET program.

Navigation

[0] Message Index

[*] Previous page

Go to full version