【问题标题】:How do you tell the architecture you're running on in Windows-CE in C#?你如何用 C# 告诉你在 Windows-CE 中运行的体系结构?
【发布时间】:2017-11-16 17:06:52
【问题描述】:

我正在为一个在多个设备上运行的 WEC7 应用程序编写安装程序,每个设备都有不同的架构,甚至可能有不同的操作系统版本。由于历史原因,该应用程序是用 C++ 编写的。这意味着针对每个操作系统/架构版本编译应用程序。安装程序包具有所有版本作为资源。我只需要弄清楚要安装哪一个。操作系统版本可以在 System.Environment.OSVersion.Version.Major 获得,但我无法区分 ARM 和 x86 架构。

我遇到的可能解决方案包括:

SYSTEM_INFO si;
GetSystemInfo(&si);
return si.wProcessorArchitecture;

但是,这是 C++ 代码,因此会遇到相同的问题,即:两个编译版本(ARM 和 x86),您必须知道要加载哪个...但这就是我要运行代码的原因。

我也调查了System.Management,但在我能找到的 WEC7 上没有。

有什么建议吗?

【问题讨论】:

  • Here 是一个令人作呕的骇客,可能会奏效
  • 有趣的破解。但是,它假定 IE10 可用。鉴于我的情况(嵌入式设备),我有理由确定它们都没有安装 IE10。谢谢你的指点。

标签: c# x86 arm windows-ce


【解决方案1】:

您可以随时 P/Invoke GetSystemInfo 调用:

[DllImport("coredll.dll")]
public static extern void GetSystemInfo(out SystemInfo info);

public enum ProcessorArchitecture
{
    Intel = 0,
    Mips = 1,
    Shx = 4,
    Arm = 5,
    Unknown = 0xFFFF,
}

[StructLayout(LayoutKind.Sequential)]
public struct SystemInfo
{
    public ProcessorArchitecture ProcessorArchitecture;
    public uint PageSize;
    public IntPtr MinimumApplicationAddress;
    public IntPtr MaximumApplicationAddress;
    public IntPtr ActiveProcessorMask;
    public uint NumberOfProcessors;
    public uint ProcessorType;
    public uint AllocationGranularity;
    public ushort ProcessorLevel;
    public ushort ProcessorRevision;
}

【讨论】:

  • 谢谢,这正是我所需要的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-20
  • 1970-01-01
  • 1970-01-01
  • 2011-11-29
  • 2011-09-26
  • 2014-06-06
相关资源
最近更新 更多