zoukankan      html  css  js  c++  java
  • 通过加载Kernel32来动态判断 当前操作系统32bit还是64bit


    工作原理:通过加载Kernel32来获取IsWow64Process 函数然后通过函数的地址操作,执行函数的操作。

    在程序中只要我们获取了一个函数的地址,就可以找到正确的方法执行这个函数。

    但是这种方法并不是一种十分稳定的方式,因为我取到的函数在32bit和64bit操作系统中都存在


    #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.
    "));
        else
            _tprintf(TEXT("The process is not running under WOW64.
    "));
    
        return 0;
    }
    


  • 相关阅读:
    模式识别 之 BP算法
    仪器开发 之 DICOM 三维重建 HPP
    模式识别 之 BP算法 (二)
    病理分析 之 细胞分析
    脉搏血氧仪 之 算法原理
    模式识别 之 初学
    机器学习 之 模糊神经(失败总结)
    冲刺第二天
    冲刺第三天
    团队项目计划
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3146973.html
Copyright © 2011-2022 走看看