Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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 an emulator or a physical device.
Microsoft's Device Emulator gives itself away through a WinCE API called SystemParametersInfo when you pass in the argument SPI_GETOEMINFO. We'll use this to check for the emulator. When we detect something other than the Microsoft value, we must be running on a physical device.
I use partial classes because in later posts in the Platform Detection series I'll add more to these classes.
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
{
[DllImport("Coredll.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode)]
static extern int SystemParametersInfo4Strings(uint uiAction, uint uiParam, StringBuilder pvParam, uint fWinIni);
public enum SystemParametersInfoActions : uint
{
SPI_GETPLATFORMTYPE = 257, // this is used elsewhere for Smartphone/PocketPC detection
SPI_GETOEMINFO = 258,
}
public static string GetOemInfo()
{
StringBuilder oemInfo = new StringBuilder(50);
if (SystemParametersInfo4Strings((uint)SystemParametersInfoActions.SPI_GETOEMINFO,
(uint)oemInfo.Capacity, oemInfo, 0) == 0)
throw new Exception("Error getting OEM info.");
return oemInfo.ToString();
}
}
internal partial class PlatformDetection
{
private const string MicrosoftEmulatorOemValue = "Microsoft DeviceEmulator";
public static bool IsEmulator()
{
return PInvoke.GetOemInfo() == MicrosoftEmulatorOemValue;
}
}
class EmulatorProgram
{
static void Main(string[] args)
{
MessageBox.Show("Emulator: " + (PlatformDetection.IsEmulator() ? "Yes" : "No"));
}
}
}
This is the first post in a series of three on platform detection. Coming up next: discerning between Smartphones and Pocket PCs.
Comments
Anonymous
September 18, 2006
Software / Hardware Engadget gives us a few of HTC’s Q4 lineup . Here’s a link to their European pressAnonymous
June 15, 2007
I now have three blogs that I post to: this one, JMPInline , and NetCFTeam . Which posts will I put where?Anonymous
June 15, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/06/15/identity-crisis/Anonymous
July 28, 2007
PingBack from http://blogsseek.com/voip/2007/07/28/re-alternative-to-virtual-template-function/Anonymous
May 10, 2008
是否曾经想过要设计一个.NETCF应用程序,它能够同时在PocketPC和Smartphone平台上使用,并根据不同的平台加载不同的功能模块,那如何检测你的应用程序当前运行在Pock...Anonymous
May 09, 2009
作者:马宁 在开发Windows CE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在Pocket PC、Smartphone还是Windows CE上。在这篇文章里,我们介绍如何编写一个应用程序来检测当前运行的平台类型。Anonymous
May 09, 2009
作者:马宁在开发WindowsCE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在PocketPC、Smartphone还是WindowsCE上。在这篇文章里,我们介绍如何编写一个...Anonymous
May 09, 2009
作者:马宁 在开发Windows CE的应用程序时,经常需要检测平台类型,了解我们的应用程序运行在Pocket PC、Smartphone还是Windows CE上。在这篇文章里,我们介绍如何编写一个应用程序来检测当前运行的平台类型。Anonymous
May 09, 2009
PingBack from http://microsoft-sharepoint.simplynetdev.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-12/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-15/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-16/Anonymous
May 09, 2009
PingBack from http://www.anith.com/?p=36383Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-18/Anonymous
May 09, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-19/Anonymous
May 10, 2009
PingBack from http://tune-up-pc.com/blog/?p=1654Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-2/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-5/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-6/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-7/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-9/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-11/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-13/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-14/Anonymous
May 14, 2009
PingBack from http://www.codedstyle.com/%e5%a6%82%e4%bd%95%e4%bf%ae%e6%94%b9windows-ce%e7%9a%84%e5%b9%b3%e5%8f%b0%e7%b1%bb%e5%9e%8b-17/Anonymous
June 15, 2009
PingBack from http://workfromhomecareer.info/story.php?id=155