简体   繁体   English

您如何判断要在Windows CE中使用C#运行的体系结构?

[英]How do you tell the architecture you're running on in Windows-CE in C#?

I am writing the installer for a WEC7 application that runs on several devices, each with a different architecture and possibly even different OS versions. 我正在为一个在多个设备上运行的WEC7应用程序编写安装程序,每个设备具有不同的体系结构,甚至可能具有不同的OS版本。 The application is, for historical reasons, written in C++. 由于历史原因,该应用程序是用C ++编写的。 This means that the application is compiled for each OS/architecture version. 这意味着该应用程序针对每个OS /体系结构版本进行编译。 The installer package has all versions as resouces. 安装程序软件包具有所有版本。 I just need to figure out which one to install. 我只需要弄清楚要安装哪一个即可。 OS version can be had at System.Environment.OSVersion.Version.Major, but I can't tell the difference between ARM and x86 architectures. 操作系统版本可以在System.Environment.OSVersion.Version.Major上找到,但我无法说出ARM与x86体系结构之间的区别。

Possible solutions I have run into included: 我遇到的可能的解决方案包括:

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

However, that is C++ code and therefore suffers from the same issue, that is: two compiled versions (ARM & x86) and you have to know which to load... but that's why I want to run the code. 但是,这是C ++代码,因此会遇到相同的问题,即:两个编译版本(ARM和x86),您必须知道要加载哪个版本……但这就是为什么我要运行代码。

I have also investigated System.Management , but that is not available on WEC7 that I can find. 我还研究了System.Management ,但是在我发现的WEC7上没有。

Any suggestions? 有什么建议么?

You could always P/Invoke the GetSystemInfo call: 您总是可以P /调用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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM