Determine the number of Windows system bits in QT

Source: Internet
Author: User

Because you want to determine the number of system bits to decide the different operations in the program.

The first thing to think about is whether or not there are packaged classes in Qt, and discover that the Qsysinfo class can provide us with some underlying information about the current system. In the Qsysinfo class, qsysinfo::wordsize can return the pointer size (32 or 64) for the platform on which the application is compiled. However, in the actual use process, it is found that the return of 32 or 64 is based on the compiler, if compiled into 32 bits that returns 32, 63 bits return 64.

So you can only use Windows system functions to determine the current system environment, there is a iswow64process function in the Windows system functions, you can use to determine whether the specified process runs under WOW64. However, the official state clearly stated:

To be compatible with operating systems that do not support this feature, call GetProcAddress to detect whether iswow64processis implemented in Kernel32.dll. If GetProcAddress succeeds, it is safe to call this function. Otherwise, WOW64 does not exist. Note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows, because Kernel32.dll in the current version of 32-bit Windows also includes this feature.

Therefore, using the GetProcAddress function, this method retrieves the address of the exported function or variable from the specified dynamic-link library (DLL). In Kernel32.dll, there is a getnativesysteminfo function that retrieves information about the current system, passes a SYSTEM_INFO structure to the modifier, The processor architecture (Wprocessorarchitecture attribute) that is included in the structure can be: processor_architecture_amd64, Processor_architecture_arm, Processor_architecture_arm64, Processor_architecture_ia64, Processor_architecture_intel, PROCESSOR_ARCHITECTURE_ Unknown one of these values, so you can determine whether the system is 64-bit based on these values.

The specific code is as follows:

1 BOOLIs64bitsystem ()2 {3typedefvoid(WINAPI *Pgnsi) (lpsystem_info);4 Pgnsi Pgnsi;5 system_info si;6ZeroMemory (&si,sizeof(System_info));7Pgnsi = (pgnsi) GetProcAddress (GetModuleHandle (TEXT ("Kernel32.dll")),"Getnativesysteminfo");8     if(Pgnsi)9     {TenPgnsi (&si); One  A         if(si.wprocessorarchitecture = = Processor_architecture_amd64 | | -Si.wprocessorarchitecture = = Processor_architecture_ia64 | | -Si.wprocessorarchitecture = =processor_architecture_arm64) the         { -             return TRUE; -         } -     } +     return FALSE; -}

Determine the number of Windows system bits in QT

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.