【问题标题】:<winapifamily.h> and "fatal error C1012: unmatched parenthesis : missing ')'<winapifamily.h> 和“致命错误 C1012:括号不匹配:缺少 ')'
【发布时间】:2016-04-28 10:36:38
【问题描述】:

我正在尝试使用 Microsoft 的 &lt;winapifamily.h&gt;WINAPI_FAMILY_PARTITION 宏。我使用 Visual Studio 工具菜单中的 VS2012 ARM 开发人员提示。当我在下面的代码中使用宏时:

#if defined(CRYPTOPP_WIN32_AVAILABLE) && defined(WINAPI_FAMILY)
# if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))
#   undef SOCKETS_AVAILABLE
# endif
#endif

然后结果是:

cl.exe /nologo /W4 /D_MBCS /Zi /TP /EHsc /MD /DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP /c wait.cpp
wait.cpp
c:\...\config.h(548) : fatal error C1012: unmatched parenthesis : missing ')'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 11.0
\VC\BIN\x86_ARM\cl.exe"' : return code '0x2'

第 548 行是#if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))

删除#if 块会清除不匹配括号的直接错误,但会导致其他地方出现大量与套接字相关的错误。所以我必须能够检测到 Windows Store 和 Windows Phone 应用程序并停用代码路径。

这个不匹配的括号到底在哪里,我该如何解决?


这是来自&lt;winapifamily.h&gt; 的相关信息。它来自 Windows Phone Kit。我相当肯定我正在按预期使用它。

/*
 *  Windows APIs can be placed in a partition represented by one of the below bits.   The 
 *  WINAPI_FAMILY value determines which partitions are available to the client code.
 */

#define WINAPI_PARTITION_DESKTOP   0x00000001
#define WINAPI_PARTITION_APP       0x00000002    

/*
 * A family may be defined as the union of multiple families. WINAPI_FAMILY should be set
 * to one of these values.
 */
#define WINAPI_FAMILY_APP          WINAPI_PARTITION_APP
#define WINAPI_FAMILY_DESKTOP_APP  (WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_APP)

/*
 * A constant that specifies which code is available to the program's target runtime platform.
 * By default we use the 'desktop app' family which places no restrictions on the API surface. 
 * To restrict the API surface to just the App API surface, define WINAPI_FAMILY to WINAPI_FAMILY_APP.
 */
#ifndef WINAPI_FAMILY
#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
#endif

/* Macro to determine if a partition is enabled */
#define WINAPI_FAMILY_PARTITION(Partition)  ((WINAPI_FAMILY & Partition) == Partition)

/* Macro to determine if only one partition is enabled from a set */
#define WINAPI_FAMILY_ONE_PARTITION(PartitionSet, Partition) ((WINAPI_FAMILY & PartitionSet) == Partition)

/*
 * Macro examples:
 *    The following examples are typical macro usage for enabling/restricting access to header code based
 *    on the target runtime platform. The examples assume a correct setting of the WINAPI_FAMILY macro.
 *
 *      App programs:
 *          Explicitly set WINAPI_FAMILY to WINAPI_PARTITION_APP (cannot access DESKTOP partition)
 *      Desktop programs:
 *          Leave WINAPI_FAMILY set to the default above (currently WINAPI_FAMILY_DESKTOP_APP)
 *
 *      Note: Other families and partitions may be added in the future.
 *
 *
 * The WINAPI_FAMILY_PARTITION macro:
 *    Code-block is available to programs that have access to specified partition.
 *
 *      Example: Available to App and Desktop programs
 *          #if WINAPI_FAMILY_PARTITION( WINAPI_PARTITION_APP )
 *
 *      Example: Available to Desktop programs
 *          #if WINAPI_FAMILY_PARTITION( WINAPI_PARTITION_DESKTOP )
 *
 *
 * The WINAPI_FAMILY_ONE_PARTITION macro:
 *    Code-block is available to programs that have access to specified parition, but not others in the partition set.
 *
 *      Example: Available only to App programs
 *          #if WINAPI_FAMILY_ONE_PARTITION( WINAPI_FAMILY, WINAPI_PARTITION_APP )
 *
 *      Example: Available only to Desktop programs
 *          #if WINAPI_FAMILY_ONE_PARTITION( WINAPI_FAMILY, WINAPI_PARTITION_DESKTOP )
 *
 *      Example: Available to App, but not Desktop programs
 *          #if WINAPI_FAMILY_ONE_PARTITION( WINAPI_FAMILY_DESKTOP_APP, WINAPI_PARTITION_APP )
 */

【问题讨论】:

  • 你能发布你的源代码的第一行(直到有问题的行/#include)吗?
  • 不太可能是问题所在:它被编译为 C++ 代码 (/TP) 但它被标记为 C。还可以尝试使用 /w44668 进行编译(参见 C4668 / GCC 的 -Wundef)。我的猜测是 WINAPI_FAMILY_PARTITION 没有定义。
  • 哦,WINAPI_PARTITION_DESKTOP 可能也没有定义。这意味着你最终会得到# if !(0(0))
  • @cremno - 关于/TP 的要点。我重新标记了它。对此感到抱歉。

标签: c++ visual-studio macros windows-phone windows-store-apps


【解决方案1】:

&lt;winapifamily.h&gt; 默认不包括在内。如果您不包含它(最好通过#include,但/FI 也是一个选项),那么预处理器将用0 替换(未定义的)WINAPI_FAMILY_PARTITIONWINAPI_PARTITION_DESKTOP。这意味着

# if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP))

等价于

# if !(0(0))

这不是一个有效的预处理表达式。可以通过指示编译器/预处理器发出诊断信息来发现此类错误。 MSVC 有C4668。这是 4 级警告,但默认关闭。所以你必须用/w44668 启用它。 GCC 有-Wundef

【讨论】:

  • 谢谢。我相当肯定所有这些微软的废话都被打破了。三年前,我购买了 Visual Studio Ultimate、两台 Surface 平板电脑(ARM/WinRT 和 Pro/x64)、一台 Windows Phone 和一台新笔记本电脑,因为微软不允许我在我拥有的硬件上安装 Phone SDK(甚至虽然我计划在我购买的真实硬件上运行)。我能说的最好的,我花了大约 8000 美元一无所获。我仍然无法清除诸如问题 143:支持通用 Windows 平台 (UWP)"问题 164:需要基于 Windows 的 BCryptGenRandom 的 NonblockingRng" 之类的错误。工具还是坏了。
  • +1 因为这是我能找到的唯一将这个错误消息与预处理器指令无效的真正原因相关联的东西。
猜你喜欢
  • 2015-03-31
  • 1970-01-01
  • 1970-01-01
  • 2016-10-23
  • 1970-01-01
  • 2016-02-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多