What happened to WINVER and _WIN32_WINNT guards in windows.h?

visual-c++, winapi, windows

Solution

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.

Problem

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. 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 ); ``` 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 */ ``` 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? Edited to add: Here is a test. foo.h contains: ``` #include <windows.h> ``` Then run: ``` cl /E /D_WIN32_WINNT=0x0501 /DNTDDI_VERSION=0x05010000 foo.h | grep CancelSynchronousIo ``` My expectation is that I'd get no output, but instead CancelSynchronousIo is defined.

Original source