gpt4 book ai didi

c# - .NET compact framework - 检测是否在模拟器下?

转载 作者:太空狗 更新时间:2023-10-29 20:08:52 26 4
gpt4 key购买 nike

有没有办法通过 .NET CF 代码检测我们是在模拟器上运行还是在真实设备上运行?

谢谢多米尼克

最佳答案

This article间接地告诉你怎么做。它展示了如何创建一个实用方法 IsEmulator 来完成这个任务。您可能还对 follow-up 感兴趣如果您总体上关心平台检测。

来自文章:

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"));
}
}
}

关于c# - .NET compact framework - 检测是否在模拟器下?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3118825/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com