如何判断vc++6.0的程序是在32位还是64位下执行?

在内存中,指针不同于一般变量,存的是变量的地址,在同一架构下地址长度都是相同的,是cpu的最大寻址内存空间,所以不同类型的指针长度都一样。
在32位机器上,指针占4个字节。在64位机器上,占8个字节。

===================================================
在vc6上验证指针在内存中的字节数:

 printf("%d\n",sizeof(char*));
 printf("%d\n",sizeof(int*));
 printf("%d\n",sizeof(float*));
 printf("%d\n",sizeof(double*));

结果:

4
4
4
4

我的操作系统是x64,应该全是 8 才对。查阅了很多资料,最后得知vc6是在32位系统下执行程序的

下面是检验方法。

1. 检测代码:

(在vc6中直接复制运行)

#include <stdio.h>
#include <windows.h>
#include <tchar.h>

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);

LPFN_ISWOW64PROCESS fnIsWow64Process;

BOOL IsWow64()
{
    BOOL bIsWow64 = FALSE;

    //IsWow64Process is not available on all supported versions of Windows.
    //Use GetModuleHandle to get a handle to the DLL that contains the function
    //and GetProcAddress to get a pointer to the function if available.

    fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
        GetModuleHandle(TEXT("kernel32")),"IsWow64Process");

    if(NULL != fnIsWow64Process)
    {
        if (!fnIsWow64Process(GetCurrentProcess(),&bIsWow64))
        {
            //handle error
        }
    }
    return bIsWow64;
}

int main( void )
{
    if(IsWow64())
        _tprintf(TEXT("The process is running under WOW64.\n"));
    else
        _tprintf(TEXT("The process is not running under WOW64.\n"));

    return 0;
}

(转自 https://docs.microsoft.com/zh-cn/windows/win32/api/wow64apiset/nf-wow64apiset-iswow64process?redirectedfrom=MSDN

2.判断

结果

The process is running under WOW64.

WOW64 什么意思?

MSDN上关于IsWow64Process函数的解释:“Determines whether the specified process is running under WOW64.”

这里的WOW64是Windows上提供的一种机制,用来在64位系统上运行32位进程。(重点!)

如果当前进程运行在WOW64,意味着当前进程是一个32位进程并运行在支持WOW64的64位系统上。

(转自https://www.jianshu.com/p/b90fc847afb3

3.结论

虽然操作系统是64位的,但是vc6是运行的32位进程。
因此在vc6 IDE下,相当于是在32位系统下运行。

  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值