在Using the Windows Headers中,Microsoft声称可以使用_WIN32_WINNT和NTDDI_VERSION来防止为较新版本的Windows定义API函数。但是,这似乎并不普遍。WINVER和WINDOWS.h中的_WIN32_WINNT警卫发生了什么?
例如,CancelSynchronousIo需要Vista或更高版本,但在Windows SDK的两个版本(v6.0和v7.1)中完全没有保护。
WINBASEAPI
BOOL
WINAPI
CancelIoEx(
__in HANDLE hFile,
__in_opt LPOVERLAPPED lpOverlapped
);
同时,GetVolumeInformationByHandleW,这也需要Vista中,被守卫你可能期望:
#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函数?
编辑补充:
这里是一个考验。 foo.h中包含:
#include <windows.h>
然后运行:
cl /E /D_WIN32_WINNT=0x0501 /DNTDDI_VERSION=0x05010000 foo.h | grep CancelSynchronousIo
我意料的是,我得不到任何输出,而是CancelSynchronousIo定义。
我使用MSDN。我会提供链接,但我看到你已经拥有了。具体而言,“要求”部分提供“最低支持的客户端”和“最低支持的服务器”。还有兴趣:[WINVER,_WIN32_WINNT,_WIN32_WINDOWS和_WIN32_IE有什么区别?](http://blogs.msdn.com/b/oldnewthing/archive/2007/04/11/2079137.aspx)。 – 2011-01-22 17:49:09