Windows mobile WindowsMobile6-如何以编程方式确定您是否正在使用仿真器

Windows mobile WindowsMobile6-如何以编程方式确定您是否正在使用仿真器,windows-mobile,compact-framework,Windows Mobile,Compact Framework,如何测试我使用的是仿真器还是实际的windows mobile设备?您可以尝试使用来查看它们是否不同。仿真器可能会返回不同的ID,以便您能够区分两者 GetDeviceUniqueID上的链接会带你去一个博客,解释它的功能,还有可以使用的源代码。你必须查找它,但我记得几年前看到过一个条目,其中使用反射时,在NETCF上模拟器和真实硬件的版本号存在差异。我不记得那些值在哪里,但“aa”是真正的交易,“bb”是模拟器。不确定这种技术是否在NETCF3.5上仍然有效,但它在v2上有效。经过大量搜索,我

如何测试我使用的是仿真器还是实际的windows mobile设备?

您可以尝试使用来查看它们是否不同。仿真器可能会返回不同的ID,以便您能够区分两者


GetDeviceUniqueID上的链接会带你去一个博客,解释它的功能,还有可以使用的源代码。

你必须查找它,但我记得几年前看到过一个条目,其中使用反射时,在NETCF上模拟器和真实硬件的版本号存在差异。我不记得那些值在哪里,但“aa”是真正的交易,“bb”是模拟器。不确定这种技术是否在NETCF3.5上仍然有效,但它在v2上有效。

经过大量搜索,我最终找到了我想要的答案-。
我在另一个Stackoverflow上找到了指向此的链接。

您可以调用KernelIoControl来获取设备型号名称,看看这是否告诉您它是否是模拟器

[DllImport("coredll", SetLastError = true)]
public static extern bool KernelIoControl([In] uint IoControlCode,
  [In] byte[] InputBuffer,
  [In] uint InputBufferSize,
  [In, Out] byte[] OutputBuffer,
  [In] uint OutputBufferSize,
  [Out] out uint BytesReturned);

public const int ERROR_INSUFFICIENT_BUFFER = 0x7A;
public const int SPI_GETOEMINFO = 258;
public const Int32 FILE_DEVICE_HAL = 0x00000101;
public const Int32 FILE_ANY_ACCESS = 0x0;
public const Int32 METHOD_BUFFERED = 0x0;

private static uint CTL_CODE(uint DeviceType, uint Function, uint Method, 
 uint Access)
{
  return ((DeviceType << 16) | (Access << 14) | (Function << 2) | Method);
}

public static uint IOCTL_HAL_GET_DEVICE_INFO = CTL_CODE(FILE_DEVICE_HAL, 1,
            METHOD_BUFFERED, FILE_ANY_ACCESS);

public static string GetDeviceModelName()
{
  byte[] inputBuffer = BitConverter.GetBytes(SPI_GETOEMINFO);
  byte[] outputBuffer = new byte[256];
  uint bytesReturned = 0;

  // call KernelIoControl with IOCTL_HAL_GET_DEVICE_INFO parameter
  bool retVal = false;
  try
  {
    retVal = KernelIoControl(IOCTL_HAL_GET_DEVICE_INFO,
               inputBuffer, (uint)inputBuffer.Length, outputBuffer,
               (uint)outputBuffer.Length, out bytesReturned);
  }
  catch
  {
  }

  // if not succeeded, then try the last step again, now with increased buffer size
  if (!retVal)
  {
    int error = Marshal.GetLastWin32Error();

    // if the buffer size is incorrect, adjust it and call function again.
    if (error == ERROR_INSUFFICIENT_BUFFER)
    {
      int buffSize = BitConverter.ToInt32(outputBuffer, 0);
      outputBuffer = new byte[buffSize];
      BitConverter.GetBytes(buffSize).CopyTo(outputBuffer, 0);

      retVal = KernelIoControl(IOCTL_HAL_GET_DEVICE_INFO,
                 inputBuffer, (uint)inputBuffer.Length, outputBuffer,
                 (uint)outputBuffer.Length, out bytesReturned);
    }
  }

  // extract the model name
  string modelNameStr = null;
  if (retVal)
  {
    modelNameStr = System.Text.Encoding.Unicode.GetString(outputBuffer, 0, 
                     outputBuffer.Length).Replace("\0","");
  }

  return modelNameStr;
}
[DllImport(“coredll”,SetLastError=true)]
公共静态外部布尔内核控制([In]uint IoControlCode,
[In]字节[]输入缓冲区,
[In]单元输入缓冲区大小,
[In,Out]字节[]输出缓冲区,
[In]单元输出缓冲区大小,
[Out]Out uint字节返回);
公共常量int错误\u缓冲区不足=0x7A;
公共常数int SPI_GETOEMINFO=258;
public const Int32文件\u设备\u HAL=0x00000101;
public const Int32 FILE\u ANY\u ACCESS=0x0;
public const Int32方法\u BUFFERED=0x0;
专用静态uint CTL_代码(uint设备类型、uint函数、uint方法、,
单元访问)
{

返回((DeviceType谢谢你的回答。模拟器的DeviceId确实与我使用的实际设备不同。我真正想做的是在模拟器运行时跳过一些特定于设备的代码。因为我在团队中工作,所以我不想依赖于单个模拟器或设备的唯一Id。@安德鲁:你试过了吗另一台机器?不同机器的模拟器设备Id可能相同。不,我没有尝试过。我目前使用的是设备名称。我尝试过的所有模拟器的设备名称都是pocket_pc,但设备没有。我知道这并不理想,但它让我克服了眼前的问题。