VC obtains the Window OS version number, gets the operating system bit number

Source: Internet
Author: User
Tags strcmp

Original link: http://www.greensoftcode.net/techntxt/2014315195331643021849

#include <Windows.h>
Include <stdio.h>
#include <tchar.h>
#include <conio.h>

#include "stdafx.h"
#include "OsVersion.h"
#include "OsVersionDlg.h"

void Getosversion (char* szosname)
{
DWORD dwMajorVersion;
DWORD dwminorversion;
DWORD dwBuildNumber;
DWORD dwPlatformId;
osversioninfo osvi;//defining OSVERSIONINFO data Structure objects
memset (&OSVI, 0, sizeof (OSVERSIONINFO));//Open Space
osvi.dwosversioninfosize = sizeof (OSVERSIONINFO);//define Size
GetVersionEx (&OSVI);//Get version information
dwmajorversion=osvi.dwmajorversion;//Major Version number
dwminorversion=osvi.dwminorversion;//Sub-version
dwbuildnumber=osvi.dwbuildnumber;//Create number
dwplatformid=osvi.dwplatformid;//id No.
Char swversion[10]={0};
sprintf (swversion, "%d.%d", dwmajorversion,dwminorversion);
//Dwvesion=atoi (swversion);
 
if (!strcmp (swversion, "4.0")) strcpy (Szosname, "Win95"); Win95
if (!strcmp (swversion, "4.1")) strcpy (Szosname, "Win98"); Win98
if (!strcmp (swversion, "4.9")) strcpy (Szosname, "Win_me"); Win_me
if (!strcmp (swversion, "3.51")) strcpy (Szosname, "win_nt_3_5"); Win_nt_3_5
if (!strcmp (swversion, "5.0")) strcpy (Szosname, "Win2000"); Win2000
if (!strcmp (swversion, "5.1")) strcpy (Szosname, "win_xp"); WIN_XP
if (!strcmp (swversion, "5.2")) strcpy (Szosname, "win2003"); Win2003
if (!strcmp (swversion, "6.6")) strcpy (Szosname, "Vista"); Vista
if (!strcmp (swversion, "6.1")) strcpy (Szosname, "Win7"); Win7
if (!strcmp (swversion, "6.1")) strcpy (Szosname, "Win8"); Win8
 

}


#define __IN
#define __out
 
#define MS_PROCESSOR_ARCHITECTURE_IA64 6
#define MS_PROCESSOR_ARCHITECTURE_AMD64 9
 
//secure access to real system Information
VOID safegetnativesysteminfo (__out lpsystem_info lpsysteminfo)
{
if (null==lpsysteminfo) return;
typedef VOID (WINAPI *lpfn_getnativesysteminfo) (Lpsystem_info lpsysteminfo);
lpfn_getnativesysteminfo fngetnativesysteminfo = (lpfn_getnativesysteminfo) GetProcAddress (GetModuleHandle (_T ( "Kernel32")), "Getnativesysteminfo");;
if (NULL! = fngetnativesysteminfo)
 {
Fngetnativesysteminfo (lpsysteminfo);
 }
Else
 {
GetSystemInfo (lpsysteminfo);
 }
}

Get the number of operating system bits
int Getsystembits ()
{
System_info si;
Safegetnativesysteminfo (&SI);
if (si.wprocessorarchitecture = = Ms_processor_architecture_amd64 | |
Si.wprocessorarchitecture = = ms_processor_architecture_ia64)

{
return 64;
}
return 32;
}

void Cosversiondlg::onbutton1 ()
{
Todo:add your control notification handler code here
Char szosversion[40]={0};
Getosversion (szosversion); Get the operating system name

int lzbit=getsystembits (); Get the number of operating system bits

}

VC obtains the Window OS version number, gets the operating system bit number

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.