2

I am used to using Win32Ada library for calling system calls for a terminal program that I was creating for Windows. The system calls were sufficient to achieve the control needed over the console, but nothing in Ada standard library would be. Examining the list of sources of GPS Community edition, I found Win32Ada missing. I am ready to continue using Win32Ada, but it is implied by its exclusion (as was the case with the POSIX exclusion for the Linux build years ago) that there is a better way to achieve low level interface. Can anyone give me the simplest code or reference to how I may interface with Windows in the way that will be supported from now on?

Example of before:

pragma Ada_2012;
with Win32;
with Ada.Text_IO;
...
Micah W
  • 378
  • 2
  • 8

3 Answers3

3

I'm not sure that the exclusion of the win32ada library from the GNAT Community Edition implies it's obsolescence. The library is still available on GitHub and no obsolesce is mentioned in the README file. You just might have to clone, build and install it yourself.

Note also that win32ada seems to target 32-bit as well as 64-bit Windows. From what I know, the difference between 32-bit and 64-bit Windows boils down to the size of the pointers being used. These pointers are represented by the types ULONG_PTR and LONG_PTR defined in win32.ads where their sizes are defined using Standard'Address_Size; an attribute exposed by GNAT. Furthermore the fact that win32ada links to files like user32.dll and gdi32.dll with the number 32 in their names is irrelevant when it comes to targeting 32-bit or 64-bit Windows as is mentioned in e.g. this post.

That being said, you might, as an alternative, also want to check GNAT.OS_Lib. This package contains an abstraction to various OS related facilities (see also "Help > GNAT Runtime > GNAT > OS_Lib" in the GPS IDE). Depending on this package instead of win32ada might make your program more portable between operating systems.

DeeDee
  • 5,654
  • 7
  • 14
  • win23ada should still work on 64 bit windows targets, but I'm not sure it actually targets x64. x64 uses a completely different calling convention (__fastcall for example) which I don't know if GNAT supports. You can still run 32bit applications on 64 bit windows though, so it should still be useable – Jere Apr 19 '19 at 22:52
  • @Jere - Indeed, all system calls on Windows for x86-64 use ```__fastcall```, but, from what I understand, [GNAT knows this](https://docs.adacore.com/gnat_ugn-docs/html/gnat_ugn/gnat_ugn/platform_specific_information.html#windows-calling-conventions) and should handle this for you. – DeeDee Apr 20 '19 at 07:19
  • @Jere - On second thought, I'm actually not sure that this convention is named ```__fastcall```. The MS docs just call it the [x64 calling convention](https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2017). – DeeDee Apr 20 '19 at 07:30
  • I didn't remember the MS one off the top of my head. – Jere Apr 20 '19 at 15:54
1

You could take a look at the Visual Studio plugin for Ada, Visual Ada which has some UWP support for Windows 64

Visual Studio Community edition is free.

If you really really want to use win32ada, then you may have to contact AdaCore and see if they support it for their paid version or stick with the one supplied with GNAT GPL 2017 for windows 32bit (which is still downloadable). You could potentially pair it with a more updated Ada compiler from msys2 which has both 64 and 32 bit versions of GNAT that are maintained.

Jere
  • 3,124
  • 7
  • 15
1

Have a look at how it is done in GWindows: the whole framework builds for both Win32 and Win64. Especially, you'll find in the package GWindows.Types how the detection 32 vs. 64 bit is done automatically:

   type Handle is new System.Address;
   Null_Handle : constant Handle := Handle (System.Null_Address);
   type Wparam is mod 2 ** Standard'Address_Size;
   type Lparam is new Wparam;
   type Lresult is new Wparam;
Zerte
  • 1,478
  • 10
  • 9