Sunday, September 07, 2008

Detecting whether you're running on smartphone or Pocket PC

In the old days (before Compact Framework 3.5) detecting whether you're running on PPC or smartphone was done using a method such as this.

This is no longer required as the SystemSettings class has been extended to support a Platform property. So now you can easily distinguish the difference between PPC, smartphone or a generic WinCE device. SystemSettings lives in the Microsoft.WindowsCE.Forms.dll assembly, so you'll need to add a reference to this dll in your project.

The code is very simple and could look like the following:
Microsoft.WindowsCE.Forms.WinCEPlatform platform = 

switch (platform)
case Microsoft.WindowsCE.Forms.WinCEPlatform.PocketPC:
//Do PPC stuff.
case Microsoft.WindowsCE.Forms.WinCEPlatform.Smartphone:
//Do smartphone stuff.
case Microsoft.WindowsCE.Forms.WinCEPlatform.WinCEGeneric:
//Do WinCE stuff.
That's alot cleaner than ugly P/invoke code.

No comments: