Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Using Windows SDK 8.1 on a Windows 7 box

$
0
0

So I have a c++ application that builds on Windows 7 and Windows 8 using Visual Studio 2013. The app uses DirectX via the Windows 8.1 SDK so all box, including the Windows 7 ones, have that installed.

So recently someone added some code related to time of day that boils down to

   #if defined(_WIN32_WINNT) && (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
      GetSystemTimePreciseAsFileTime(&fileTime);
   #else
      GetSystemTimeAsFileTime(&fileTime);
   #endif

Note the app already has a Windows 7 and a Windows 8 specific build so at first glance I thought the above would be OK. However it compiles but fails at run time. Eventually I discovered this is because the Windows 8.1 SDK defines _WIN32_WINNT to be _WIN32_WINNT_WINBLUE ( 8.1 ) even when building on a Window 7 box. This means there is a declaration for GetSystemTimePreciseAsFileTime and the above code compiles. However GetSystemTimePreciseAsFileTime lives in Kernel32.dll which is not part of the Window 8.1 SDK and so the code fails at run time with an undefined symbol.

So my question is, why would the Windows 8.1 SDK behave this way. It seems to me that adding declarations for things that are not actually available on the platform on which you are compiling or targeting is a bit odd.

As usual I assume I am misunderstanding something here, so is there for instance a better way to find out the OS version on which you are actually building ( or at least targeting )? ideally I would like to use GetSystemTimePreciseAsFileTime if it is available on the platform I am running on and GetSystemTimeAsFileTime if not and do away with the #ifdef but I'm not sure of a good way of doing that.

Any feedback gratefully received.


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>