Determine whether it is a 64-bit operating system or a 32-bit System

Source: Internet
Author: User
1. iswow64process: determines whether the specified process runs in a 64-bit 32-bit operating system environment (wow64. Syntax
BOOL WINAPI IsWow64Process(  __in HANDLE hProcess,  __out PBOOL Wow64Process  );
The hprocess handle parameter. This handle must have process_query_information or process_query_limited_information access permission. wow64process points to a bool value. If the process is a 32-bit process and runs in a 64-bit operating system, the value is true. Otherwise, the value is false. If the process is a 64-bit application running on a 64-bit system, the value is also set to false. Return Value: if the function is successful, the return value is a non-zero value. If this function fails, the return value is zero. To obtain the extended error information, call the getlasterror. Microsoft example:
  #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;  }

Note: It is not appropriate to use this function to determine whether the operating system is 32-bit or 64-bit. If you want to use this function, you can point to a 32-bit process.

2. The best practice is:
  BOOL Is64bitSystem()  {    SYSTEM_INFO si;    GetNativeSystemInfo(&si);    if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||            si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 )      return TRUE;    else      return FALSE;  }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.