如何检测不同的 Windows 目标平台? [英] How to detect different Windows target platforms?
问题描述
我想为我的 C/C++ 文件创建一个通用头文件.在该头文件中,我希望在编译时检测我正在构建的平台以及我正在为该平台构建的应用程序类型.
I would like to create a common header file for my C/C++ files. In that header file I would like to have compile-time detection of which platform I'm building for and what type of application I'm building for that platform.
选项是:
- 桌面应用.操作系统:Win 7/Win 8.x.CPU:英特尔/AMD.设备:PC/笔记本电脑
- Windows Phone 应用.操作系统:Windows:8.x.处理器:ARM.设备:Windows 手机
- 桌面应用.操作系统:Windows 8.x.处理器:英特尔.设备:平板电脑
- 商店应用.操作系统:Windows 8.x.处理器:英特尔.设备:平板电脑
- 桌面应用.操作系统:Windows RT.处理器:ARM.设备:平板电脑
- 商店应用.操作系统:Windows RT.处理器:ARM.设备:平板电脑
我不确定 [3] 和 [5] 是否是实际的可能性.
I'm not sure if [3] and [5] are actual possibilities.
我查看了 winapifamily.h,但不确定如何解释(或理解)该头文件中的分区表,因此不胜感激.
I have looked at winapifamily.h but I'm not sure how to interpret (or understand) the partition table in that header file, so some help would be greatly appreciated.
在我想创建的头文件中,我想要这样的东西:
In the header file I wish to create, I would like something like this:
#ifdef SOME_PREPROCESSOR_DEFINE
/* Option 1*/
#endif
#ifdef SOME_PREPROCESSOR_DEFINE
/* Option 2*/
#endif
#ifdef SOME_PREPROCESSOR_DEFINE
/* Option 3*/
#endif
#ifdef SOME_PREPROCESSOR_DEFINE
/* Option 4*/
#endif
#ifdef SOME_PREPROCESSOR_DEFINE
/* Option 5*/
#endif
#ifdef SOME_PREPROCESSOR_DEFINE
/* Option 6*/
#endif
谢谢.
推荐答案
窗口版本由许多宏定义,请参见 此链接.您应该能够通过使用这些来区分不同版本的 Windows.
Window versions are defined by a number of macros, see this link. You should be able to discriminate between different versions of windows by using these.
Visual Studio 的其他预定义宏在此处列出.它们的某些组合应该能够帮助您.例如,_M_ARM
是为 ARM 处理器定义的.
Other pre-defined macros for visual studio are listed here. Some combination of them should be able to help you. For example, _M_ARM
is defined for an ARM processor.
这篇关于如何检测不同的 Windows 目标平台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!