2010-06-25 2 views

답변

7

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

당신이 OpenNETCF Smart Device Framework를 사용하는 경우, 당신은 "마이크로 소프트 DeviceEmulator을"동일 있는지 확인하기 위해 OpenNETCF.WindowsCE.DeviceManagement.OemInfo 속성을 테스트 할 수 있습니다. 그래서 에뮬레이터에서 실행 중이며 바코드 판독기와 같은 특정 하드웨어와 상호 작용해서는 안됩니다.

관련 문제