zoukankan      html  css  js  c++  java
  • 判断是64位操作系统还是32位系统

    1、IsWow64Process

    确定指定进程是否运行在64位操作系统的32环境(Wow64)下。
    语法
    BOOL WINAPI IsWow64Process(
      __in HANDLE hProcess,
      __out PBOOL Wow64Process
      );
    参数
      hProcess
        进程句柄。该句柄必须具有PROCESS_QUERY_INFORMATION 或者 PROCESS_QUERY_LIMITED_INFORMATION 访问权限
      Wow64Process
        指向一个bool值,
        如果该进程是32位进程,运行在64操作系统下,该值为true,否则为false。
        如果该进程是一个64位应用程序,运行在64位系统上,该值也被设置为false。
      返回值
        如果函数成功返回值为非零值。
        如果该函数失败,则返回值为零。要获取扩展的错误的信息,请调用GetLastError .
      微软的例子:
      #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;
      }

      注意:使用此函数判断操作系统是32位还是64位并不合适,勉强要用的话,可以指向一个32位进程。

    2、比较合适的做法是:

      BOOL Is64bitSystem()
      {
        SYSTEM_INFO si;
        GetNativeSystemInfo(&si);
        if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
                si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )
          return TRUE;
        else
          return FALSE;
      }
  • 相关阅读:
    Nubiers to follow
    pp to write
    Reading source code
    build opencv with python support
    add monitor resolution
    Install cv2.so for Anaconda
    axios 上传下载显示进度
    vant 上传图片 图片回显 是base64
    多个时间段 合并
    热部署
  • 原文地址:https://www.cnblogs.com/guomeiran/p/3898718.html
Copyright © 2011-2022 走看看