Since OSVersion is now not reliable since Windows 10 has been released (this function reports Windows 8 for Windows 10), I'm attempting to use the new Version Helper API functions in my C# application. Here they are.
I apologize if this is simply a issue with my DLL import, but here is my attempt to pull in these new methods to detect the OS correctly.
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool IsWindows7OrGreater();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool IsWindows8OrGreater();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool IsWindows8Point1OrGreater();
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool IsWindows10OrGreater();
Whenever I'm calling these methods, I'm getting:
Exception is: EntryPointNotFoundException - Unable to find an entry point named 'IsWindows7OrGreater' in DLL 'kernel32.dll'.
Am I doing something wrong? Anyone have any ideas? Thanks for any help!
EDIT: Please see the accepted answer and take a look at this code project for a good start on porting these methods over to C#.
Unfortunately, it's a little more complicated than that. The "functions" are actually macros defined in VersionHelpers.h
.
If you think of it, that's the only way to do it - they can't add functions to older Windows versions retroactively.
You have to port the macros over to C#.