const int MAX_PATH = 260;
[DllImport("Coredll.dll")]
static extern int SHGetSpecialFolderPath(IntPtr hwndOwner, StringBuilder lpszPath, int nFolder, int fCreate);
public enum SystemParametersInfoActions : uint
{
SPI_GETPLATFORMTYPE = 257, // this is used elsewhere for Smartphone/PocketPC detection
SPI_GETOEMINFO = 258,
}
public static string GetOemInfo()
{
//10/26/2006 wangyun Change from 50 to 100, as it doesn't work on "FUJITSU SIEMENS COMPUTERS Pocket LOOX"
StringBuilder oemInfo = new StringBuilder(100);
if (SystemParametersInfo4Strings((uint)SystemParametersInfoActions.SPI_GETOEMINFO,
(uint)oemInfo.Capacity, oemInfo, 0) == 0)
throw new Exception("Error getting OEM info.");
return oemInfo.ToString();
}
public static string GetPlatformType()
{
//10/26/2006 wangyun Change from 50 to 100 to avoid the possible bug as above
StringBuilder platformType = new StringBuilder(100);
if (SystemParametersInfo4Strings((uint)SystemParametersInfoActions.SPI_GETPLATFORMTYPE,
(uint)platformType.Capacity, platformType, 0) == 0)
throw new Exception("Error getting platform type.");
return platformType.ToString();
}
public enum SpecialFolders : int
{
CSIDL_WINDOWS = 0x0024,
}
public static string GetSpecialFolder(SpecialFolders specialFolder)
{
StringBuilder path = new StringBuilder(MAX_PATH);
if (SHGetSpecialFolderPath(IntPtr.Zero, path, (int)specialFolder, 0) == 0)
throw new Exception("Error getting Windows path.");
return path.ToString();
}
}
public class PlatformDetection
{
private const string MicrosoftEmulatorOemValue = "Microsoft DeviceEmulator";
//10/26/2006 wangyun To effect compatibility between PC and PDA devices
public static bool IsWinCE()
{
return System.Environment.OSVersion.Platform == PlatformID.WinCE;
}
public static bool IsEmulator()
{
if (IsWinCE())
return PInvoke.GetOemInfo() == MicrosoftEmulatorOemValue;
else
return false;
}
public static bool IsSmartphone()
{
if (IsWinCE())
return PInvoke.GetPlatformType() == "SmartPhone";
else
return false;
}
public static bool IsPocketPC()
{
if (IsWinCE())
return PInvoke.GetPlatformType() == "PocketPC";
else
return false;
}
return
driverExists &&
// Windows Mobile 5.0 Smartphone emulator and earlier has a driver, but no touch screen.
!(IsSmartphone() && IsEmulator() && Environment.OSVersion.Version.Major < 6);
}
else
return false;
}
}
}