How to determine whether the operating system is 64-bit or 32-bit

Source: Internet
Author: User

The 64-bit wnidows contains a wow64 Simulator technology, which can enable 32-bitProgramRun on 64-bit windows. When you want to execute differentCodeYou need to determine whether the operating system is 32-bit or 64-bit. Use Windows API functionsGetnativesysteminfo You can obtain this information.

 

Sample Code:

 

System_info Si;
Getnativesysteminfo (& Si );

If (Si. wprocessorarchitecture = processor_ubunture_amd64 |

Si. wprocessorarchitecture! = Processor_ubunture_ia64)

{

// 64-bit Operating System

}

Else

{

// 32-bit Operating System

}

 

 

In addition, Windows API provides Iswow64process The function checks whether the program runs on the wow64 simulator.

 

Sample Code:

 

bool biswow64 = false;
iswow64process (getcurrentprocess (), & biswow64);

It must be noted that getnativesysteminfo Functions are available from Windows XP, while Iswow64process Functions are available from Windows XP with SP2 and Windows Server 2003 with SP1. So it is best to use this functionGetprocaddress.

 

Typedef void (winapi * lpfn_pgnsi) (lpsystem_info );

Typedef bool (winapi * lpfn_iswow64process) (handle, pbool );

 

Lpfn_pgnsi pgnsi = (lpfn_pgnsi) getprocaddress (

Getmodulehandle (text ("kernel32.dll"), "getnativesysteminfo ");

Lpfn_iswow64process fniswow64process = (lpfn_iswow64process) getprocaddress (
Getmodulehandle (text ("Kernel32"), "iswow64process ");

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.