admin 管理员组文章数量: 887021
获取版本代码
float getSysVersion(){
float f_ret;
typedef void(__stdcall*NTPROC)(DWORD*, DWORD*, DWORD*);
DWORD dwMajor, dwMinor, dwBuildNumber;
NTPROC proc = (NTPROC)GetProcAddress(
LoadLibrary("ntdll.dll"),
"RtlGetNtVersionNumbers"
); proc(&dwMajor, &dwMinor, &dwBuildNumber);
// win 10
if (dwMajor == 10 && dwMinor == 0){
f_ret = dwMajor + dwMinor*0.1;
return f_ret;
}
// win 8.1
if (dwMajor == 6 && dwMinor == 3){
f_ret = dwMajor + dwMinor*0.1;
return f_ret;
}
// win 8.1 以下
SYSTEM_INFO info;
GetSystemInfo(&info);
OSVERSIONINFOEX os;
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
#pragma warning(disable:4996)
if(GetVersionEx((OSVERSIONINFO *)&os)){
f_ret = os.dwMajorVersion + os.dwMinorVersion*0.1;
}
return f_ret;
}
效果图:
获取 ReleaseId
string get_systemReleaseId(){
string releaseId = "";
HKEY hKey_return = NULL;
char keyValue[256];
DWORD keySzType;
DWORD keySize;
if(ERROR_SUCCESS != RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\",0,KEY_READ,&hKey_return)){
cout << "RegOpenKeyEx failed." << endl;
goto end;
}
if(ERROR_SUCCESS != RegQueryValueEx(hKey_return,"ReleaseId",0,&keySzType,(LPBYTE)&keyValue,&keySize)){
cout << "RegQueryValueEx failed." << endl;
goto end;
}
releaseId = keyValue;
end:
return releaseId;
}
版权声明:本文标题:CC++ 获取系统版本 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1729009820h1306468.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论