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;
    }
    


  • 相关阅读:
    SLAB
    /proc/vmstat 详解
    swap空间可以有效缓解内存压力
    内存问题排查手段及相关文件介绍
    buddyinfo 内存碎片数据采集
    取得Linux系统的各种统计信息
    HTML的常用总结
    采用jquery同django实现ajax通信
    Django的quarySet
    Django-MySQL数据库使用01
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3146973.html
Copyright © 2011-2022 走看看