2014-08-29 55 views
2

我正在开发一个跨平台的C++库。我针对WP8和其他人,我需要检测目标是WP8还是桌面Windows。如何在编译时检测WP8

是否有为WP8目标自动设置的标志?

我曾考虑过使用_WIN32,但它似乎仍然在两个平台上定义。

回答

1

不知道这是你在找什么,但如果你正在做一个通用的应用程序/便携式库,您可以通过使用


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 
+1

这看起来很有希望,但winapifamily.h似乎并不存在于我所有的系统上。我在另一台win32电脑上找不到VS2012 – Eric 2014-09-01 17:12:14