Implement a "legacy-safe" emulation of Microsoft's "versionhelpers" API.
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()).
I committed 475f0b6. With this in place, the trivial program:
produces this output, when run on a WinXP-SP2 virtual machine:
- #include <stdio.h>
- #include <versionhelpers.h>
- #include "legacy.h"
- const char *test( BOOL status )
- { return status ? "is" : "is not"; }
- void report( const char *what, BOOL status )
- { printf( "%s %s supported\n", what, test( status ) ); }
- int main()
- { printf( "Host %s a Windows server\n", test( IsWindowsServer() ) );
- report( "WinXP", IsWindowsXPOrGreater() );
- report( "WinXP-SP1", IsWindowsXPSP1OrGreater() );
- report( "WinXP-SP2", IsWindowsXPSP2OrGreater() );
- report( "WinXP-SP3", IsWindowsXPSP3OrGreater() );
- report( "Vista", IsWindowsVistaOrGreater() );
- report( "Vista-SP1", IsWindowsVistaSP1OrGreater() );
- report( "Vista-SP2", IsWindowsVistaSP2OrGreater() );
- report( "Win7", IsWindows7OrGreater() );
- report( "Win7-SP1", IsWindows7SP1OrGreater() );
- report( "Win8", IsWindows8OrGreater() );
- report( "Win8.1", IsWindows8Point1OrGreater() );
- report( "Win10", IsWindows10OrGreater() );
- return 0;
- }
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 supportedwhile 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
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).