Closed stonstad closed 8 years ago
I don't get this behavior with the samples provided so I am going to assume this is user error. Thank you!
This condition is in PlatformHeaders.h
which in the src
directory rather than the inc
directory. As such, it's intended use is as an internal implementation header. You are certainly free to use it directly in applications, but I do make slightly different assumptions.
The reason you are getting this error is mostly likely because _WIN32_WINNT_WIN10
is not defined, which means it defaults to 0 so the expression is evaluated to true.
I know the problem is not because
WINAPI_FAMILY
is not defined or it is set toWINAPI_FAMILY_DESKTOP_APP
becauseVirtualAlloc
is in the desktop partition so you would not be getting a compiler error. If you were building your Windows Store app with that setting, it would compile but it would fail to pass WACK validation.
This is one of the challenges of writing code that compiles with a broad range of toolsets & SDKs. The Windows 10 SDK is the only place that _WIN32_WINNT_WIN10
is defined by the standard headers, so contexts where the Windows 8.0, Windows 8.1 SDK, or Xbox One XDK are used won't have it defined. A similar issue happens with _WIN32_WINNT_WINBLUE
not being defined in the Windows 8.0 SDK--I don't actually have any 8.0 vs. 8.1 differences in any of my GitHub libraries. To solve this generally, I have two solutions based on internal vs. public use.
In public headers (i.e. those in Inc
) I explicitly use the version number rather than symbol name :
#if (_WIN32_WINNT >= 0x0A00 /*_WIN32_WINNT_WIN10*/)
Internally, I have the library's pch.h
define _WIN32_WINNT_WIN10
if it is not already defined. This allows me to use the more human readable symbol in both .h
and .cpp
files in the Src
folder.
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
I guess the real question is: What in the PlatformHelpers.h
do you use in your code that I should put into a public header instead of an internal one?
As a short-term fix, just add the following somewhere before you include PlatformHelpers.h
:
#ifndef _WIN32_WINNT_WIN10
#define _WIN32_WINNT_WIN10 0x0A00
#endif
Thank you Chuck! Your reply is very insightful and helps me better understand DirectXTK. It is such a clean, well thought out library.
Hi Chuck. I wasn't sure if this was a bug but it seems suspect and I thought I would mention it. After upgrading to DirectXTK Nov 30 my Windows 8.1 apps throw a compile time error on this line:
if (_WIN32_WINNT >= _WIN32_WINNT_WIN10) || (defined(_XBOX_ONE) && defined(_TITLE)) || !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
endif
I am not very knowledgable of Windows/C++ but is it possible that VirtualFree only exists in Windows 10 libraries? If I comment out this line my Windows 8.1 UWP compiles fine. Otherwise, the error is that identifier "VirtualFree" cannot be found. Thanks, Shaun.