-1

I am working on a C application (not c++). Basically the code is in *.c file. I want to add another function to this file to check the windows OS version on which my application is running. I am trying to use the versionhelper functions described below --https://learn.microsoft.com/en-us/windows/desktop/sysinfo/version-helper-apis. However, when I try to add below header file I get compilation error saying -cannot open source file "VersionHelpers.h" --

 #include <VersionHelpers.h>

I think this is because my file is a C file. Is there any way to read windows OS version from C code? (Not C++)

Mayur
  • 2,583
  • 16
  • 28
user496934
  • 3,822
  • 10
  • 45
  • 64
  • Check https://stackoverflow.com/questions/142508/how-do-i-check-os-with-a-preprocessor-directive – postit Sep 26 '18 at 07:14
  • 1
    @postit: On Windows, the OS version on which you compile is independent from the OS version on which you run. – MSalters Sep 26 '18 at 07:16
  • Is there a way I can use methods defined in VersionHelpers.h from C code ? – user496934 Sep 26 '18 at 07:17
  • 1
    I've no idea, but your reasoning is wrong. You get that error because your compiler cannot find the header file, not because you have a C program. – john Sep 26 '18 at 07:18
  • Possible duplicate of [Check Windows version](https://stackoverflow.com/questions/1963992/check-windows-version) – Lex Li Sep 26 '18 at 22:54

2 Answers2

2

VersionHelpers.h is a just an inline header file that does common checks using VerifyVersionInfo. You could just use that API directly which is C-callable.

You also need to be aware of the fact that the GetVersion and VerifyVersionInfo functions are subject to built-in appcompat version lies. See Manifest Madness for details.

Of course the real question is what are you actually going to do with that information?

Is this a "you must be this high to ride this ride" test? If so, VerifyVersionInfo is the way to do it and what the code in VersionHelpers.h does.

Is this a "I need a version for a telemetry or log file" test? In that case you probably want to use GetVersionEx and suppress the deprecation warning. Be sure you don't make any runtime decisions based on the value. For UWP apps, you'd use AnalyticsInfo.

Is this a "I'm checking to see if it's safe to use a particular OS component?" If so, there's likely a better way to do it than an OS check.

See What’s in a version number?

The VersionHelpers.h header was added in the Windows 8.1 SDK which comes with VS 2013 or later. It's also in every version of the Windows 10 SDK. It is compatible with .c as well as .cpp files.

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
1

VersionHelpers.h is from the Window 8.1 SDK (2014). It didn't ship with VS2012. You have to install it manually, or update to a current Visual Studio version.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • Um. Did you recently have a look at a calendar? Why don't you use VS 2017 and be done with it? – Swordfish Sep 26 '18 at 07:22
  • @Swordfish: Considering there's no such thing as VS2014 (The 2014 date is for Win8.1), I am wondering what he did. – MSalters Sep 26 '18 at 08:25