Share via


Writing Code for Multiple Devices and Versions

Many types of devices are based on the Windows CE operating system, from mobile devices to factory automation controllers. Using conditional compilation or runtime platform and version checking, you can write your code to run on a broad variety of devices and still take advantage of the particular capabilities and conventions of each platform. These techniques even allow you to share code with desktop versions of Windows operating systems.

Conditional Compilation

Depending on which platform you are targeting at compile time, you can use conditional compilation to include or exclude certain portions of code, as shown in the following code. Using a conditional compilation approach, as opposed to runtime platform and version checking, results in a separate executable file for each targeted platform.

#ifdef WIN32_PLATFORM_PSPC
    // Pocket PC code.
#if (WIN32_PLATFORM_PSPC = 400)
    // Pocket PC 2003 code.
    LoadString(g_hInst, IDS_PPC2003, szBuf, MAX_LOADSTRING);
#elif (WIN32_PLATFORM_PSPC = 310)
    // Pocket PC 2002 code.
    LoadString(g_hInst, IDS_PPC2002, szBuf, MAX_LOADSTRING);
#endif 
#endif // WIN32_PLATFORM_PSPC

Runtime Platform and Version Checking

You can use the Windows CE GetVersionEx function to write code that checks the operating system or device at run time and then runs code specific to each platform. This technique enables you to write a single executable file and run it on different versions of Windows Mobile-based devices, taking advantage of the special features of each. It is also possible to detect other versions of Windows, such as Microsoft Windows 95 or Microsoft Windows 2000. For an example of how to use this technique, see How to: Implement Runtime Platform and Version Checking.

Send feedback on this topic to the authors.

© 2005 Microsoft Corporation. All rights reserved.