获取 Windows 架构(32/64 位版本) [英] Getting Architecture of Windows (32/64 bit version)
问题描述
我遇到了一个小问题:
我想了解操作系统的架构,问题是我的编程语言不支持此类功能.因此,我需要从 windows dll(如 kernel32.dll)中读取此信息
我确实尝试使用 GetNativeSystemInfo/GetVersionEx/GetSystemInfo
函数获取信息.
不幸的是,我无法获得架构:/
im tring to get the architecture of the OS, the problem is my programming language doesnt support such functions. Therefore i need to read this information form an windows dll (like kernel32.dll)
i did try to get the infos with the functions GetNativeSystemInfo/GetVersionEx/GetSystemInfo
.
Unfortunately i were not able to get the architecture :/
是否有其他函数可以读取任何 windows dll 中的体系结构?
(它不需要是kernel32它可以是任何dll但它必须存在于win xp+中)
Are there some other Functions to read the architecture in any windows dll?
(it dosnt need to be kernel32 it can be any dll but it must exists in win xp+)
信息:我正在使用 Gupta(SQLWindows/Team devoloper)
As info: im using Gupta (SQLWindows/Team devoloper)
编辑 1:
typedef struct _SYSTEM_INFO {
union {
DWORD dwOemId;
struct {
WORD wProcessorArchitecture;
WORD wReserved;
} ;
} ;
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO;
这是来自 MSDN 的信息,我试图用 10 和 12 个参数调用这个函数(Gupta 不支持结构).
在 32Bit 上我得到:
替代文字 http://img714.imageshack.us/img714/1954/32bit.gif
thats the info from MSDN, i tried to call this Function with with 10 and 12 Parameters
(Gupta dosnt support structs).
On 32Bit i get:
alt text http://img714.imageshack.us/img714/1954/32bit.gif
在 64 位上我得到:
替代文字 http://img691.imageshack.us/img691/8978/64bit.gif
on 64Bit i get:
alt text http://img691.imageshack.us/img691/8978/64bit.gif
我是否每次都会在 32 位上获得 0
OemID?或者更好的是在 64 位版本的 Windows 上每次都填写 OemID?
do i get every time a 0
OemID on 32 bit? or better is the OemID everytiem filled on 64bit version of windows?
谢谢帮助!!
问候
极光
推荐答案
GetNativeSystemInfo
绝对是要使用的函数.如果您的应用是本机 64 位应用,GetNativeSystemInfo
与 GetSystemInfo
;否则,如果它在 WOW64 下运行,它将返回真实的系统属性,即使它在模拟的 32 位环境中运行.
GetNativeSystemInfo
is definitely the function to use. If your app is a native 64-bit app, GetNativeSystemInfo
is the same as GetSystemInfo
; otherwise, if it runs under WOW64, it will return the true system properties, even if it is run in an emulated 32-bit environment.
GetNativeSystemInfo
填充 SYSTEM_INFO
结构,其中的 wProcessorArchitecture
成员告诉您系统是 32 位(可能是 PROCESSOR_ARCHITECTURE_INTEL
)还是 64 位(可能是 PROCESSOR_ARCHITECTURE_AMD64
).
GetNativeSystemInfo
fills a SYSTEM_INFO
structure, the wProcessorArchitecture
member of which tells you whether the system is 32-bit (probably PROCESSOR_ARCHITECTURE_INTEL
) or 64-bit (probably PROCESSOR_ARCHITECTURE_AMD64
).
如果你的语言没有这个 Win API 函数的包装器,要使用它,你可以像往常一样使用 LoadLibrary
和 GetProcAddress
,你需要定义SYSTEM_INFO
结构,当然.
If your language does not have a wrapper for this Win API function, to use it, you can employ LoadLibrary
and GetProcAddress
as usual, and you need to define the SYSTEM_INFO
structure, of course.
我会定义
typedef struct _SYSTEM_INFO {
WORD wProcessorArchitecture;
WORD wReserved;
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
} SYSTEM_INFO;
然后 wProcessorArchitecture = 0
在(通用)32 位系统上,wProcessorArchitecture = 9
在(通用)64 位系统上.这些只是常量PROCESSOR_ARCHITECTURE_INTEL
和PROCESSOR_ARCHITECTURE_AMD64
.这些是常见的 32 位和 64 位架构.PROCESSOR_ARCHITECTURE_IA64 = 6
稍微不常见,PROCESSOR_ARCHITECTURE_UNKNOWN = 65535
肯定也是如此.
Then wProcessorArchitecture = 0
on a (common) 32-bit system, and wProcessorArchitecture = 9
on a (common) 64-bit system. These are just the constants PROCESSOR_ARCHITECTURE_INTEL
and PROCESSOR_ARCHITECTURE_AMD64
, respectively. These are the common 32-bit and 64-bit architectures. PROCESSOR_ARCHITECTURE_IA64 = 6
is slightly more uncommon, as is surely PROCESSOR_ARCHITECTURE_UNKNOWN = 65535
.
是的,我明白你的问题.在 C 中,union
意味着您一次选择一个选项.也就是说,结构要么是
Yes, I see your problem. In C, union
means that you choose one of the options at a time. That is, the structure is either
DWORD dwOemId;
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
或
WORD wProcessorArchitecture;
WORD wReserved;
DWORD dwPageSize;
LPVOID lpMinimumApplicationAddress;
LPVOID lpMaximumApplicationAddress;
DWORD_PTR dwActiveProcessorMask;
DWORD dwNumberOfProcessors;
DWORD dwProcessorType;
DWORD dwAllocationGranularity;
WORD wProcessorLevel;
WORD wProcessorRevision;
因为一个 DWORD 由与两个字 (2×2) 一样多的字节 (4) 组成,所以替代方案只是对整个结构的数据进行寻址(和命名)的两种方式.在我们的例子中,我们对 wProcessorArchitecture
词更感兴趣,而不是 wProcessorArchitecture
的增加 dwOemId
和完全无趣的 wReserved代码>文字.
Because one DWORD consists of as many bytes (4) as two words (2×2), the alternatives are just two ways of adressing (and naming) the data of the entire structure. In our case, we are more interested in the wProcessorArchitecture
word rather then the augment dwOemId
of wProcessorArchitecture
and the utterly uninteresting wReserved
words.
这篇关于获取 Windows 架构(32/64 位版本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!