Ticket #42383

Implement a "legacy-safe" emulation of Microsoft's "versionhelpers" API.

Open Date: 2021-05-25 04:00 Last Update: 2021-05-26 01:14

Open [Owner assigned]
5 - Medium
5 - Medium
Score: 1
100.0% (1/1)
0.0% (0/1)


The Ada component for GCC-10 has introduced a gratuitous dependency on Microsoft's <versionhelpers.h> API. Notwithstanding that this is an appalling choice, by the GCC-Ada developers — OS version, (which is what this API tests,) is never a reliable indicator of feature availability — to facilitate continuing support for GCC-Ada, in MinGW, it is almost imperative that we provide our own <versionhelpers.h> API emulation; (the alternative would be to commit to patching future versions of GCC-Ada, in perpetuity, to circumvent this ill-advised dependency).

Ticket History (3/3 Histories)

2021-05-25 04:00 Updated by: keith
  • New Ticket "Implement a "legacy-safe" emulation of Microsoft's "versionhelpers" API." created
2021-05-25 05:43 Updated by: keith

Microsoft first introduced the <versionhelpers.h> API as a component of the Windows 8.1 Software Development Kit. However, as noted in Microsoft's documentation, this API is based on the VerifyVersionInfo() function, which, according to the pertinent documentation, has been supported on all WinNT derivatives since Windows 2000, and thus, the <versionhelpers.h> API is backwardly compatible with Win2K, and all subsequent WinNT derivatives.

Unfortunately, while backward compatibility with Win2K, and all later WinNT derivatives, may be sufficient for many applications, it does not satisfy MinGW's objective of supporting even earlier WinNT variants, and Win9x; (indeed, the MinGW libraries are compiled with nominal support for WinNT4, with additional compatibility infrastructure to support Win9x). Any MinGW emulation would, thus, need to incorporate such "legacy-support" infrastructure, even if such support offered no more than an indication that the run-time platform is too old for the requested level of support; (indeed, such an indication would be entirely appropriate, since the API specification incorporates no test for any OS version prior to IsWindowsXPOrGreater()).

2021-05-26 01:14 Updated by: keith
  • Resolution Update from None to Accepted

I committed 475f0b6. With this in place, the trivial program:

  1. #include <stdio.h>
  2. #include <versionhelpers.h>
  3. #include "legacy.h"
  4. const char *test( BOOL status )
  5. { return status ? "is" : "is not"; }
  6. void report( const char *what, BOOL status )
  7. { printf( "%s %s supported\n", what, test( status ) ); }
  8. int main()
  9. { printf( "Host %s a Windows server\n", test( IsWindowsServer() ) );
  10. report( "WinXP", IsWindowsXPOrGreater() );
  11. report( "WinXP-SP1", IsWindowsXPSP1OrGreater() );
  12. report( "WinXP-SP2", IsWindowsXPSP2OrGreater() );
  13. report( "WinXP-SP3", IsWindowsXPSP3OrGreater() );
  14. report( "Vista", IsWindowsVistaOrGreater() );
  15. report( "Vista-SP1", IsWindowsVistaSP1OrGreater() );
  16. report( "Vista-SP2", IsWindowsVistaSP2OrGreater() );
  17. report( "Win7", IsWindows7OrGreater() );
  18. report( "Win7-SP1", IsWindows7SP1OrGreater() );
  19. report( "Win8", IsWindows8OrGreater() );
  20. report( "Win8.1", IsWindows8Point1OrGreater() );
  21. report( "Win10", IsWindows10OrGreater() );
  22. return 0;
  23. }
produces this output, when run on a WinXP-SP2 virtual machine:
Host is not a Windows server
WinXP is supported
WinXP-SP1 is supported
WinXP-SP2 is supported
WinXP-SP3 is not supported
Vista is not supported
Vista-SP1 is not supported
Vista-SP2 is not supported
Win7 is not supported
Win7-SP1 is not supported
Win8 is not supported
Win8.1 is not supported
Win10 is not supported
while on a Win7-SP1 VM, it produces:
Host is not a Windows server
WinXP is supported
WinXP-SP1 is supported
WinXP-SP2 is supported
WinXP-SP3 is supported
Vista is supported
Vista-SP1 is supported
Vista-SP2 is supported
Win7 is supported
Win7-SP1 is supported
Win8 is not supported
Win8.1 is not supported
Win10 is not supported

I don't have ready access to any other Windows hosts, so if anyone else is able to help with further testing, it would be appreciated.

Attachment File List

No attachments


Please login to add comment to this ticket » Login