How to detect different Windows target platforms?

。_饼干妹妹 提交于 2019-12-24 07:07:19

问题


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.

The options are:

  1. Desktop App. OS: Win 7 / Win 8.x. CPU: Intel/AMD. Device: PC/Laptop
  2. Windows Phone App. OS: Windows: 8.x. CPU: ARM. Device: Windows Mobile Phone
  3. Desktop App. OS: Windows 8.x. CPU: Intel. Device: Tablet
  4. Store App. OS: Windows 8.x. CPU: Intel. Device: Tablet
  5. Desktop App. OS: Windows RT. CPU: ARM. Device: Tablet
  6. Store App. OS: Windows RT. CPU: ARM. Device: Tablet

I'm not sure if [3] and [5] are actual possibilities.

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

Thank you.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/25462950/how-to-detect-different-windows-target-platforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!