简体   繁体   中英

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. The application is, for historical reasons, written in C++. This means that the application is compiled for each OS/architecture version. 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.

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.

I have also investigated System.Management , but that is not available on WEC7 that I can find.

Any suggestions?

You could always P/Invoke the GetSystemInfo call:

[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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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