Yes, I also wanted to clarify the point about compile time and run time:
1.
At run timeIn this case, it can be done in the
Windows module itself. In the initialization section, it can get the current OS version and put it in a global variable. And in functions that are version-dependent, this variable can be checked and throw an exception in case of an error.
Then user programs can handle the exception and continue execution if the call to this function is not necessary, or it has an alternative implementation. This ensures portability of the executable between OS versions.
But it should be expected that now a simple API call can return an exception. So it is better to define a global directive (e.g. "
WINAPI_CHECKVER") to allow/disable such a check.
2.
At compile timeIn this case, when compiling, you must first somehow specify a specific version (just as you can now specify a CPU, OS, and widget set in the IDE).
Then, based on this, the path with the required include file can be selected, as suggested by
Thaddy (if I understood correctly).
This is a faster way not only for compilation, but also for running (since there are no checks at runtime). However, unlike the first method, it simply prevents the program from compiling at all, whether this function is needed or not.
By the way, this method is quite "officially" feasible, since the MS website always indicates the minimum required version. For example, for
VirtualAlloc2, "Windows 10" is clearly written at the bottom. Perhaps someone will even be able to write a program to automatically generate such files.