2014-08-29 61 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