检测 Windows Kit 8.0 和 Windows Kit 8.1 SDK

Detect Windows Kit 8.0 and Windows Kit 8.1 SDKs(检测 Windows Kit 8.0 和 Windows Kit 8.1 SDK)

本文介绍了检测 Windows Kit 8.0 和 Windows Kit 8.1 SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 Windows 平板电脑、Windows Phone 和 Windows Store 应用程序编写测试脚本.这些脚本主要适用于 Visual Studio 2012 和 Windows Kit 8.0 SDK.Microsoft 似乎为 Visual Studio 2013 和 Windows Kit 8.1 SDK 更改了一些内容,并导致失败:

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 Kits8.1includesharedwinapifamily.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
VCBINx86_ARMcl.exe"' : return code '0x2'

我们如何检测正在使用的 Windows Kit SDK?

How can we detect the Windows Kit SDK being used?

推荐答案

如果你在第 115 行查看C:Program Files (x86)Windows Kits8.1Includesharedwinapifamily.h",你会发现将看到 WINAPI_FAMILY 值必须是 WINAPI_FAMILY_DESKTOP_APPWINAPI_FAMILY_PC_APPWINAPI_FAMILY_PHONE_APP 之一(Windows 10 添加 <代码>WINAPI_FAMILY_SYSTEMWINAPI_FAMILY_SERVER 混合).这意味着当您为 Windows 8.1 或 10 构建时,您的命令行标志 /DWINAPI_FAMILY=WINAPI_PARTITION_DESKTOP 应该改为 /DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP.但是,如果您忽略它,你会得到你想要的默认值 - 请参见 winapifamily.h 的 Windows 8.1 SDK 版本中的第 57 行.

If you look in "C:Program Files (x86)Windows Kits8.1Includesharedwinapifamily.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.

检查之后,标头要做的下一件事是根据设置的 WINAPI_FAMILY 值定义 WINAPI_PARTITION_* 值.请注意,它们都是 1 或 0,在 Windows 8.0 中,WINAPI_PARTITION_APP 值始终为 0x00000002.可以想象,您可以测试 WINAPI_PARTITION_APP 是否设置为 1 而不是 0x00000002 以确定正在使用的 SDK 是否正在构建 8.1 应用而不是 8.0 应用:

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

我实际上并没有尝试过,因为我不需要根据正在使用的 SDK 在我的代码中进行切换.

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

这篇关于检测 Windows Kit 8.0 和 Windows Kit 8.1 SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:检测 Windows Kit 8.0 和 Windows Kit 8.1 SDK

基础教程推荐