我正在阅读头文件的定义winapifamily.h并注意以下定义WINAPI_FAMILY_PARTITION
:
#define WINAPI_FAMILY_PARTITION(Partitions) (Partitions)
该宏的一般用法(作为示例)如下:
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
现在我很困惑,似乎它相当于
#if WINAPI_PARTITION_APP
拥有它有什么意义#if WINAPI_FAMILY_PARTITION(...)
根本吗?
这是相关部分winapifamily.h头文件:
/*
* Header files use the WINAPI_FAMILY_PARTITION macro to assign one or
* more declarations to some group of partitions. The macro chooses
* whether the preprocessor will emit or omit a sequence of declarations
* bracketed by an #if/#endif pair. All header file references to the
* WINAPI_PARTITION_* values should be in the form of occurrences of
* WINAPI_FAMILY_PARTITION(...).
*
* For example, the following usage of WINAPI_FAMILY_PARTITION identifies
* a sequence of declarations that are part of both the Windows Desktop
* Partition and the Windows-Phone-Specific Store Partition:
*
* #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_PHONE_APP)
* ...
* #endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_PHONE_APP)
*
* The comment on the closing #endif allow tools as well as people to find the
* matching #ifdef properly.
*
* Usages of WINAPI_FAMILY_PARTITION may be combined, when the partitition definitions are
* related. In particular one might use declarations like
*
* #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
*
* or
*
* #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
*
* Direct references to WINAPI_PARTITION_ values (eg #if !WINAPI_FAMILY_PARTITION_...)
* should not be used.
*/
#define WINAPI_FAMILY_PARTITION(Partitions) (Partitions)
假设一个文件包含可在 Metro 应用程序中使用的代码
所以标题将定义
WINAPI_FAMILY = WINAPI_PARTITION_APP
=>WINAPI_FAMILY_DEKSTOP_APP has value of 2
#define WINAPI_FAMILY_PARTITION(Partition) ((WINAPI_FAMILY & Partition) == Partition)
该宏将检查 API 系列的类型
现在假设你想编写仅在 Metro 环境下运行的代码,所以
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
your code for metro application
#endif
替换值
WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) => ((2 & 2) == 2
现在,如果用户想使用地铁代码,他们必须定义
为什么需要间接WINAPI_FAMILY = WINAPI_PARTITION_APP
3 = > 00 11 (both desktop & metro)
2 => 00 10 (metro apis)
1 => 00 01 (desktop)
使用这个AND函数宏,因为如果WINAPI_FAMILY is 3
, 表示两个api都可以使用#define WINAPI_FAMILY_PARTITION(Partition)
,那么你可以指定 Partition = 2, 3
并执行 (3 & 1) 或 (3& 2) == 1
这意味着如果WINAPI_FAMILY = 3
,你可以同时使用(桌面或地铁 API)
这就是为什么需要 anding
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)