windows.h 中的 WINVER 和 _WIN32_WINNT 守卫发生了什么? [英] What happened to WINVER and _WIN32_WINNT guards in windows.h?

查看:25
本文介绍了windows.h 中的 WINVER 和 _WIN32_WINNT 守卫发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Windows 标头, Microsoft 声称 _WIN32_WINNT 和 NTDDI_VERSION 可用于阻止为较新版本的 Windows 定义 API 函数.然而,这似乎并不普遍.

In Using the Windows Headers, Microsoft claim that _WIN32_WINNT and NTDDI_VERSION can be used to prevent defining API functions for newer versions of Windows. However, this does not seem to be universally true.

例如,CancelSynchronousIo 需要Vista 或更高版本,但在我拥有的两个 Windows SDK 版本(v6.0 和 v7.1)中根本没有受到保护.

For example, CancelSynchronousIo requires Vista or later, but it is not guarded at all in the two versions of the windows SDK that I have (v6.0 and v7.1).

WINBASEAPI
BOOL
WINAPI
CancelIoEx(
    __in HANDLE hFile,
    __in_opt LPOVERLAPPED lpOverlapped
    );

与此同时,GetVolumeInformationByHandleW,这也需要Vista,正如您所期望的那样受到保护:

Meanwhile, GetVolumeInformationByHandleW, which also requires Vista, is guarded as you might expect:

#if(_WIN32_WINNT >= 0x0600)
WINBASEAPI
BOOL
WINAPI
GetVolumeInformationByHandleW(
    __in      HANDLE hFile,
    __out_ecount_opt(nVolumeNameSize) LPWSTR lpVolumeNameBuffer,
    __in      DWORD nVolumeNameSize,
    __out_opt LPDWORD lpVolumeSerialNumber,
    __out_opt LPDWORD lpMaximumComponentLength,
    __out_opt LPDWORD lpFileSystemFlags,
    __out_ecount_opt(nFileSystemNameSize) LPWSTR lpFileSystemNameBuffer,
    __in      DWORD nFileSystemNameSize
    );
#endif /* _WIN32_WINNT >=  0x0600 */

这种事情只是一个错误吗?_WIN32_WINT 守卫没用吗?谁能推荐一种可靠的方法来确定哪个版本的 Windows 引入了哪些 API 函数?

Is this sort of thing just a bug? Are _WIN32_WINT guards useless? Can anyone recommend a reliable way to determine which version of Windows introduced which API functions?

编辑添加:

这是一个测试.foo.h 包含:

Here is a test. foo.h contains:

#include <windows.h>

然后运行:

cl /E /D_WIN32_WINNT=0x0501 /DNTDDI_VERSION=0x05010000 foo.h | grep CancelSynchronousIo

我的期望是我不会得到任何输出,而是定义了 CancelSynchronousIo.

My expectation is that I'd get no output, but instead CancelSynchronousIo is defined.

推荐答案

这是一个错误.参考示例 在这里此处.一些次要证据表明 Longhorn 项目确实是一个非常麻烦的项目.Windows 团队不像 DevDiv 那样接受反馈,很难修复错误.您可以在 MSDN 库页面底部留下注释.

It's a bug. Reference examples are here and here. Some secondary evidence that the Longhorn project was indeed a very troubled one. The Windows team doesn't take feedback like DevDiv does, hard to get bugs fixed. You can leave an annotation at the bottom of the MSDN Library page.

这篇关于windows.h 中的 WINVER 和 _WIN32_WINNT 守卫发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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