c#如何使用新的Version Helper API [英] c# How to use the new Version Helper API

查看:35
本文介绍了c#如何使用新的Version Helper API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OSVersion >由于Windows 10已发布(此函数报告Windows 8 for Windows 10),现在不可靠,我正在尝试在C#应用程序中使用新的Version Helper API函数.在这里.

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.

对于这仅仅是我的DLL导入问题,我深表歉意,但这是我尝试引入这些新方法来正确检测操作系统的方法.

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:

异常是:EntryPointNotFoundException-无法在DLL"kernel32.dll"中找到名为"IsWindows7OrGreater"的入口点.

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!

编辑:请查看已接受的答案并查看

Please see the accepted answer and take a look at this code project for a good start on porting these methods over to C#.

推荐答案

不幸的是,它要复杂得多.功能"实际上是在 VersionHelpers.h 中定义的宏.

Unfortunately, it's a little more complicated than that. The "functions" are actually macros defined in VersionHelpers.h.

如果考虑到这一点,那是唯一的方法-他们无法追溯地向旧版Windows添加功能.

If you think of it, that's the only way to do it - they can't add functions to older Windows versions retroactively.

您必须将宏移植到C#.

You have to port the macros over to C#.

这篇关于c#如何使用新的Version Helper API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆