QA: How can I get which platform my application is compiled for?
Question
I need to check OS version, platform and processor type at compile time.
What preprocessor directives can I use?
Answer
When eVC performs compilation it sets environment variables for platform type and OS version -
CePlatform and CEVersion. By default eVC projects are configured to map these variables
to macros: Preprocessor definitions line in project settings
contains "_WIN32_WCE=$(CEVersion),$(CePlatform)".
Also each configuration contains a definition for processor type
(ARM, MIPS, SH3, SH4 or x86). You can use #ifdef and #if directives to
conditionally compile your code depending on these definitions.
CePlatform values for common CE-based platforms are shown in the following table.
| Platform | CePlatform value |
| H/PC 2000 | WIN32_PLATFORM_HPC2000 |
| H/PC Pro 2.11 | WIN32_PLATFORM_HPCPRO |
| Pocket PC | WIN32_PLATFORM_PSPC |
| Pocket PC 2002 | WIN32_PLATFORM_PSPC=310 |
| Smartphone 2002 | WIN32_PLATFORM_WFSP=100 |
If you build your project for some other platform you can determine
CePlatform value by including echo $(CePlatform) command in Post-build
step command list (see Project->Settings, Post-build step tab).
This command will output CePlatform value in the Output window after
your project is compiled and linked.
Here are some code samples illustrating how to designate OS versions,
platforms and processors in compile time.
#if (_WIN32_WCE == 201)
// Windows CE 2.01
#elif (_WIN32_WCE == 211)
// Windows CE 2.11
#elif (_WIN32_WCE == 300)
// Windows CE 3.0
#else
// etc.
#endif
#if defined(WIN32_PLATFORM_HPC2000)
// H/PC 2000
#elif defined(WIN32_PLATFORM_HPCPRO)
// H/PC Pro
#elif defined(WIN32_PLATFORM_PSPC)
// Pocket PC
#if (WIN32_PLATFORM_PSPC == 1)
// Pocket PC 2000
#elif (WIN32_PLATFORM_PSPC == 310)
// Pocket PC 2002
#else
// Some other Pocket PC
#endif
#elif defined(WIN32_PLATFORM_WFSP)
// Smartphone
#else
// etc.
#endif
#if defined(ARM)
// ARM processor
#elif defined (MIPS)
// MIPS processor
#elif defined (SH3)
// SH3 processor
#elif defined (SH4)
// SH4 processor
#elif defined (x86)
// x86 processor - emulator version
#else
// etc.
#endif
Discuss
Discuss this QA.
Here you can write your comments and read comments of other developers.
|