0
votes

I'm working on a test script for Windows Tablets, Windows Phones and Windows Store apps. The scripts are mostly working for under Visual Studio 2012 and Windows Kit 8.0 SDK. It appears Microsoft changed some things for Visual Studio 2013 and Windows Kit 8.1 SDK, and its causing a failure:

cl.exe /nologo /W4 /D_MBCS /Zi /TP /EHsc /MD /FI winapifamily.h /D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1
/DWINAPI_FAMILY=WINAPI_PARTITION_DESKTOP /Yc"pch.h" /Fp"pch.pch" /c pch.cpp
pch.cpp
C:\Program Files (x86)\Windows Kits\8.1\include\shared\winapifamily.h(116) : fatal error C1189:
#error :  Unknown WINAPI_FAMILY value. Was it defined in terms of a WINAPI_PARTITION_* value?
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0
\VC\BIN\x86_ARM\cl.exe"' : return code '0x2'

How can we detect the Windows Kit SDK being used?

1

1 Answers

1
votes

If you look in "C:\Program Files (x86)\Windows Kits\8.1\Include\shared\winapifamily.h" on line 115, you'll see that the WINAPI_FAMILY value has to be one of WINAPI_FAMILY_DESKTOP_APP, WINAPI_FAMILY_PC_APP, or WINAPI_FAMILY_PHONE_APP (Windows 10 adds WINAPI_FAMILY_SYSTEM and WINAPI_FAMILY_SERVER to the mix). This implies that your command-line flag /DWINAPI_FAMILY=WINAPI_PARTITION_DESKTOP should instead be /DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP when you build for Windows 8.1 or 10. However, if you leave it out, you'll get the default you want - see line 57 in the Windows 8.1 SDK version of winapifamily.h.

After the check, the next thing the header does is define the WINAPI_PARTITION_* values based on which WINAPI_FAMILY values are set. Notice that they are all either 1 or 0, where in Windows 8.0, the WINAPI_PARTITION_APP value was always 0x00000002. Conceivably, you could test whether WINAPI_PARTITION_APP is set to 1 instead of 0x00000002 to determine if the SDK in use was building an 8.1 app instead of an 8.0 app:

#if defined(WINAPI_PARTITION_APP)
#if (WINAPI_PARTITION_APP == 0x00000002)
#define USING_WINDOWS_8_0_SDK
#endif
#if defined(WINAPI_FAMILY_SYSTEM)
#define USING_WINDOWS_10_SDK
#else
#if (WINAPI_PARTITION_APP == 1)
#define USING_WINDOWS_8_1_SDK
#endif
#endif
#endif

I haven't actually tried this, since I haven't needed to switch within my code based on which SDK is in use.