我正在开发一个跨平台的c ++库。我的目标是WP8,我需要检测目标是WP8还是桌面Windows。
是否为WP8目标自动设置了标志?
我考虑过使用_WIN32,但无论如何它似乎都定义在两个平台上。
答案 0 :(得分:1)
不确定这是否是您正在寻找的内容,但如果您正在使用Universal App / Portable库,则可以使用
进行检测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