2016-04-28 52 views
2

我正在嘗試使用微軟的<winapifamily.h>WINAPI_FAMILY_PARTITION宏,我使用Visual Studio工具菜單中的VS2012 ARM Developer Prompt。我用的是宏在下面的代碼:<winapifamily.h>和「致命錯誤C1012:不匹配的括號:缺少')'

#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應用程序並停用代碼路徑。

在這裏,確切地說,這是無與倫比的括號,我該如何解決它?


這是<winapifamily.h>的相關位。它從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) 
*/ 
+0

你可以發佈你的源代碼的第一行(直到違規行/#包括)? –

+0

不太可能是問題:它被編譯爲C++代碼('/ TP'),但它被標記爲C.還可以嘗試使用'/ w44668'編譯(參見[C4668](https://msdn.microsoft.com/zh-cn/ -us/library/4dt9kyhy.aspx)/ GCC的'-Wundef')。我的猜測是'WINAPI_FAMILY_PARTITION'沒有定義。 – cremno

+1

哦,'WINAPI_PARTITION_DESKTOP'可能沒有定義。這意味着你最終得到'#if!(0(0))'。 – cremno

回答

2

<winapifamily.h>默認情況下不包括在內。如果不包含它(最好通過#include/FI也是一個選項),那麼預處理器將用0替換(未定義的)WINAPI_FAMILY_PARTITIONWINAPI_PARTITION_DESKTOP。這意味着

# if !(WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)) 

相當於

# if !(0(0)) 

這不是一個有效的預處理表達。這種錯誤可以通過指示編譯器/預處理器發出診斷來找到。 MSVC有C4668。這是一個4級警告,但默認關閉。所以你必須使用/w44668來啓用它。 GCC有-Wundef

+0

謝謝。我很確定所有這些微軟垃圾都壞了。三年前,我購買了Visual Studio Ultimate,兩個Surface平板電腦(ARM/WinRT和Pro/x64),一部Windows Phone和一臺新筆記本電腦,因爲微軟不允許我在我的硬件上安裝Phone SDK儘管我計劃在我購買的真實硬件上運行)。我可以告訴我的最好,我花了大約8000美元沒有。我仍然無法清除諸如*問題143:支持通用Windows平臺(UWP)「*和*問題164:需要基於Windows的BCryptGenRandom的NonblockingRng」*。工具仍然被打破。 – jww

+0

+1因爲這是我能找到的唯一的東西,它將這個錯誤信息與預處理指令無效的真正原因聯繫起來。 – CPlayer