能力值:
( LV2,RANK:10 )
|
-
-
2 楼
你首先看格式化之后的内容,你这各种指针转换让人蛋疼
直接判断dwMajorVersion dwMinorVersion就足够了
上代码
//获取系统版本 TCHAR tzSystem[32]; OSVERSIONINFOEX osvi; memset(&osvi,0,sizeof(osvi)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if (!GetVersionEx((OSVERSIONINFO*)&osvi)) return FALSE; else { switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2 ) _tcscpy_s(tzSystem,_countof(tzSystem),_T("Win 8")); if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 ) _tcscpy_s(tzSystem,_countof(tzSystem),_T("Win 7")); if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 ) _tcscpy_s(tzSystem,_countof(tzSystem),_T("Win Vista")); if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) _tcscpy_s(tzSystem,_countof(tzSystem),_T("Win 2003")); if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) _tcscpy_s(tzSystem,_countof(tzSystem),_T("Win XP")); if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) _tcscpy_s(tzSystem,_countof(tzSystem),_T("Win 2000")); if ( osvi.dwMajorVersion <= 4 ) _tcscpy_s(tzSystem,_countof(tzSystem),_T("Win NT")); break; case VER_PLATFORM_WIN32_WINDOWS: if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) _tcscpy_s(tzSystem,_countof(tzSystem),_T("Win 95")); if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) _tcscpy_s(tzSystem,_countof(tzSystem),_T("Win 98")); break; } } _stprintf_s(Info.cOS,_T("%s SP%d (Build %d)"),tzSystem,osvi.wServicePackMajor,osvi.dwBuildNumber);
|
能力值:
( LV3,RANK:20 )
|
-
-
3 楼
可能是被编译器优化了,切换到反汇编看下了.
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
int sprintf_s(
char *buffer,
size_t sizeOfBuffer,
const char *format [,
argument] ...
);
看懂了么? 自己把函数用错了。
|
能力值:
( LV2,RANK:10 )
|
-
-
5 楼
帖汇编看看
|
能力值:
( LV2,RANK:10 )
|
-
-
6 楼
if (5==os.dwMajorVersion&&1==os.dwMinorVersion&&768==(long)*(short*)SPNum)
肯定是运算符优先级的问题,要不你弄清运算符的优先级(baidu),要不直接用"()"把关系表示清楚(最直接)。
|
能力值:
( LV2,RANK:10 )
|
-
-
7 楼
我没看到你的问题,但我看到你熬夜了,都是凌晨的大侠啊。
|
能力值:
( LV2,RANK:10 )
|
-
-
8 楼
CHAR和INT是(long)*(short*)SPNum这样转? 第一次发现。
|
能力值:
( LV2,RANK:10 )
|
-
-
9 楼
[QUOTE=Addictions;1262517]CHAR和INT是 (long)*(short*)SPNum这样转? 第一次发现。[/QUOTE]
我也不想这样写,但是RegQueryValueExA读取到的REG_DWORD类型的值如果不这样转死活都不正确,这种转法是我在百度上面查的,我也不知道为什么.
|
能力值:
( LV2,RANK:10 )
|
-
-
10 楼
原来还有wServicePackMajor这个成员,谢谢大侠的指点,我知道该怎么改了
|
能力值:
( LV13,RANK:1760 )
|
-
-
11 楼
直接这样就行了
int GetSys_ver()
{
OSVERSIONINFOEX osver;
osver.dwOSVersionInfoSize=sizeof(osver);
GetVersionEx((OSVERSIONINFO *)&osver);
int t;
if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0) //2000
{
t = 0;
}
else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1) //XP
{
t = 1;
}
else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2)
{
if (GetSystemMetrics(SM_SERVERR2) == 0) //Windows Server 2003
{
t = 2;
}
else //Windows Server 2003 R2
{
t = 3;
}
}
else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 0)
{
if(osver.wProductType == VER_NT_WORKSTATION) //vista
{
t = 4;
}
else
{
t = 5; //windows server 2008
}
}
else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 1)
{
if(osver.wProductType == VER_NT_WORKSTATION) //windows 7
{
t = 6;
}
else
{
t = 7; //windows server 2008 r2
}
}
else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 2)
{
if(osver.wProductType == VER_NT_WORKSTATION) //windows 8
{
t = 8;
}
else
{
t = 9; //windows server 2012
}
}
else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 3)
{
if(osver.wProductType == VER_NT_WORKSTATION) //windows 8.1
{
t = 10;
}
else
{
t = 11; //windows server 2012 R2
}
}
else t = 12; //其他版本
return t;
}
|
能力值:
( LV2,RANK:10 )
|
-
-
12 楼
SPSize 不初始化 你后面的代码造成SPSize的初值发生变化 所以变的诡异
|
能力值:
( LV6,RANK:90 )
|
-
-
13 楼
RegQueryValueExA(hKey,"CSDVersion",NULL,&dwType,(LPBYTE)SPNum,&SPSize);
//SPSize未初始化
|
能力值:
( LV2,RANK:10 )
|
-
-
14 楼
RegQueryValueExA(hKey,"CSDVersion",NULL,&dwType,(LPBYTE)SPNum,&SPSize);
//SPSize未初始化
|
|
|