曾经在书上看到过,也被人问起过,搜索过,为了记忆更加深刻,还是写一篇博文吧~
程序位数是将一段程序编译后,程序本身的位数,比如32bit。
32bit程序在一般情况下可以在32bit和64bit的操作系统上运行。
下面分别列出获取程序位数和操作系统位数的方法:
程序位数:
通过指针位数即可获得:
sizeof(void*) * 8
操作系统位数:
Windows:
#include <Windows.h>
#include <stdio.h>
#include <tchar.h>
#include <conio.h>
// 安全的取得真实系统信息
VOID SafeGetNativeSystemInfo(__out LPSYSTEM_INFO lpSystemInfo)
{
if (NULL==lpSystemInfo) return;
typedef VOID (WINAPI *LPFN_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo);
LPFN_GetNativeSystemInfo fnGetNativeSystemInfo = (LPFN_GetNativeSystemInfo)GetProcAddress( GetModuleHandle(_T("kernel32")), "GetNativeSystemInfo");;
if (NULL != fnGetNativeSystemInfo)

本文介绍了如何使用C++来确定程序自身的位数以及操作系统位数。在Windows环境下,可以通过GetNativeSystemInfo API获取真实系统信息,IsWow64Process则用于判断进程是否在WOW64环境下运行。而在Linux系统中,通常借助shell脚本来获取这些信息。
最低0.47元/天 解锁文章
4010

被折叠的 条评论
为什么被折叠?



