C# .NET compact framework-是否在emulator下检测?
有没有办法从.NETCF代码中检测我们是在模拟器上运行还是在真实设备上运行 谢谢 多米尼克间接地告诉你怎么做。它展示了如何创建一个实用方法C# .NET compact framework-是否在emulator下检测?,c#,.net,compact-framework,device-emulation,C#,.net,Compact Framework,Device Emulation,有没有办法从.NETCF代码中检测我们是在模拟器上运行还是在真实设备上运行 谢谢 多米尼克间接地告诉你怎么做。它展示了如何创建一个实用方法IsEmulator,以实现这一目的。如果您关心的是一般的平台检测,那么您可能也会感兴趣 从文章中: using System; using System.IO; using System.Windows.Forms; using Microsoft.Win32; using System.Runtime.InteropServices; using Syst
IsEmulator
,以实现这一目的。如果您关心的是一般的平台检测,那么您可能也会感兴趣
从文章中:
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"));
}
}
}
如果您使用的是,则可以测试OpenNETCF.WindowsCE.DeviceManagement.OemInfo属性以查看它是否等于“Microsoft DeviceEmulator”。这就是我如何检测到我正在模拟器下运行,并且不应该与特定硬件(如条形码阅读器)交互