获得运行处理器架构

获得运行处理器架构

本文介绍了.NET Framework 获得运行处理器架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处列出了所有支持的处理器架构:http://msdn.microsoft.com/en-us/library/system.reflection.processorarchitecture.aspx

There is an enum of all supported processor architectures here: http://msdn.microsoft.com/en-us/library/system.reflection.processorarchitecture.aspx

有什么办法可以判断运行环境对应的是哪一个?System.Reflection.Assembly.GetExecutingAssembly().ProcessorArchitecture 返回 MSIL——显然是错误的.

Is there any way to determine which one corresponds to the running environment? System.Reflection.Assembly.GetExecutingAssembly().ProcessorArchitecture returns MSIL -- obviously wrong.

Bojan Resnik 发布了一个答案并将其删除.我看到需要从我得到的部分跟踪中进行一些澄清.

Bojan Resnik posted an answer and deleted it. I see that some clarification is needed from the partial trace I got.

程序集需要在多个架构上运行,并根据运行过程接受的程序集指令做不同的事情.本质上,我需要选择要加载的本机 DLL 的哪个版本.每个架构都有一个.

The assembly needs to run on multiple architectures and do different things based on what assembly instructions the running process accepts. Essentially, I need to select which version of a native DLL to load. I have one for each architecture.

推荐答案

P/Invoking GetSystemInfo 在 .Net 中是微不足道的,并且比 WMI 轻得多.此外,它返回进程看到的架构,因此在 x64 机器上,WOW 进程将看到 x86,而本机进程将看到 x64.

P/Invoking GetSystemInfo is trivial from .Net and is much lighter weight than WMI. Also, it returns the architecture as seen by the process so on a x64 machine a WOW process will see x86 and a native process will see x64.

这篇关于.NET Framework 获得运行处理器架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:17