[Windows programming] how to determine whether the operating system is 64-bit or 32-bit

Source: Internet
Author: User

The 64-bit wnidows contains a simulator called wow64, which can enable the 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 functionsGetnativesysteminfoYou 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 providesIswow64processThe function checks whether the program runs on the wow64 simulator.

 

Sample Code:

 

Bool biswow64 = false;
Iswow64process (getcurrentprocess (), & biswow64 );

Note that the getnativesysteminfo function is available from Windows XP, And the iswow64process function is 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 ");

 

 

> OriginalArticleThe copyright belongs to the author. For more information, see the source and author information (Http://blog.csdn.net/WinGeek/), Thank you. <

Related Article

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.