Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET compact framework-是否在emulator下检测?_C#_.net_Compact Framework_Device Emulation - Fatal编程技术网

C# .NET compact framework-是否在emulator下检测?

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

有没有办法从.NETCF代码中检测我们是在模拟器上运行还是在真实设备上运行

谢谢 多米尼克间接地告诉你怎么做。它展示了如何创建一个实用方法
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”。这就是我如何检测到我正在模拟器下运行,并且不应该与特定硬件(如条形码阅读器)交互