Platform detection II: Is your app running on Smartphone or Pocket PC?

While both Smartphones and Pocket PCs are based on Windows Mobile, there are some very important differences for developers who are targeting both platforms.  Not the least of which are lack of LinkButtons and other clickable elements on Smartphones (since they have no touch screen).  In this post I show how to detect whether your app is running on a Smartphone or a Pocket PC style Windows Mobile device.

It is a simple call to SystemParametersInfo to find whether you are running on a Smartphone or a Pocket PC.  You need a few constants defined and the P/Invoke marshaling code to make it work from managed code however.

This post builds on the first post in the Platform Detection series.  You'll need to build on the code from that post for this post to compile and run.  Like the last post, this code uses partial classes, so you can copy and paste the previous post's code into one file and this code into another (removing the first post's Main method) and your project will compile and run.

using System;
using System.IO;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Text;

namespace PlatformDetection
    internal partial class PInvoke
        public static string GetPlatformType()
            StringBuilder platformType = new StringBuilder(50);
            if (SystemParametersInfo4Strings((uint)SystemParametersInfoActions.SPI_GETPLATFORMTYPE,
                (uint)platformType.Capacity, platformType, 0) == 0)
                throw new Exception("Error getting platform type.");
            return platformType.ToString();
    internal partial class PlatformDetection
        public static bool IsSmartphone()
            return PInvoke.GetPlatformType() == "SmartPhone";
        public static bool IsPocketPC()
            return PInvoke.GetPlatformType() == "PocketPC";
    class PlatformProgram
        static void Main(string[] args)
            string platform;
            if (PlatformDetection.IsSmartphone())
                platform = "Smartphone";
            else if (PlatformDetection.IsPocketPC())
                platform = "Pocket PC";
                platform = "Other WinCE";
            MessageBox.Show("Platform: " + platform);


This is the second post in a series of three on platform detection.  Coming up next: detecting the presence of a touch screen.

Comments (28)
  1. When you develop your Windows CE or Windows Mobile application in .NET Compact Framework, you probably do a lot of testing on the Microsoft Device Emulators for Smartphone and Pocket PC.  Here I describe how to detect whether your program is running on

  2. Bob Li says:


  3. I now have three blogs that I post to: this one, JMPInline , and NetCFTeam . Which posts will I put where?

  4. Bob Li says:

    是否曾经想过要设计一个 .NET CF 应用程序,它能够同时在 Pocket PC 和 Smartphone 平台上使用,并根据不同的平台加载不同的功能模块,那如何检测你的应用程序当前运行在 Pocket PC 上还是 Smartphone上,甚至是模拟器上呢?

  5. fox23 says:

    本文介绍了如何利用.NET CF3.5的新功能方便的确定设备类型Smartphone,PPC or PPC Phone?

  6. 作者:马宁 在开发Windows CE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在Pocket PC、Smartphone还是Windows CE上。在这篇文章里,我们介绍如何编写一个应用程序来检测当前运行的平台类型。

  7. 马宁 says:


  8. 作者:马宁 在开发Windows CE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在Pocket PC、Smartphone还是Windows CE上。在这篇文章里,我们介绍如何编写一个应用程序来检测当前运行的平台类型。

Comments are closed.

Skip to main content