Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows 8.1 and VirtualFree #18

Closed
stonstad opened this issue Dec 8, 2015 · 3 comments
Closed

Windows 8.1 and VirtualFree #18

stonstad opened this issue Dec 8, 2015 · 3 comments
Assignees
Labels

Comments

@stonstad
Copy link

stonstad commented Dec 8, 2015

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)

struct virtual_deleter { void operator()(void* p) { if (p) VirtualFree(p, 0, MEM_RELEASE); } };

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.

@stonstad
Copy link
Author

stonstad commented Dec 8, 2015

I don't get this behavior with the samples provided so I am going to assume this is user error. Thank you!

@stonstad stonstad closed this as completed Dec 8, 2015
@walbourn
Copy link
Member

walbourn commented Dec 8, 2015

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 to WINAPI_FAMILY_DESKTOP_APP because VirtualAlloc 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

See Dual-use Coding Techniques for Games

@walbourn walbourn self-assigned this Dec 8, 2015
@stonstad
Copy link
Author

stonstad commented Dec 9, 2015

Thank you Chuck! Your reply is very insightful and helps me better understand DirectXTK. It is such a clean, well thought out library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants