我正在开发一个跨平台的 C++ 库。我的目标是 WP8,我需要检测目标是 WP8 还是桌面 Windows。
是否有为 WP8 目标自动设置的标志?
我考虑过使用 _WIN32,但它似乎在两个平台上都有定义。
最佳答案
不确定这是否是您要查找的内容,但如果您正在做一个通用应用程序/可移植库,您可以使用
检测到它C++
来自 winapifamily.h
/*
* When compiling C and C++ code using SDK header files, the development
* environment can specify a target platform by #define-ing the
* pre-processor symbol WINAPI_FAMILY to one of the following values.
* Each FAMILY value denotes an application family for which a different
* subset of the total set of header-file-defined APIs are available.
* Setting the WINAPI_FAMILY value will effectively hide from the
* editing and compilation environments the existence of APIs that
* are not applicable to the family of applications targeting a
* specific platform.
*/
#define WINAPI_FAMILY_PC_APP 2 /* Windows Store Applications */
#define WINAPI_FAMILY_PHONE_APP 3 /* Windows Phone Applications */
#define WINAPI_FAMILY_DESKTOP_APP 100 /* Windows Desktop Applications */
// example usage
#if WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP
// TODO:
#endif
C#
#if WINDOWS_APP
// TODO
#endif
#if WINDOWS_PHONE_APP
// TODO
#endif
关于c++ - 如何在编译时检测WP8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25573752/