svnno****@sourc*****
svnno****@sourc*****
2016年 1月 8日 (金) 21:26:38 JST
Revision: 6259 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/6259 Author: maya Date: 2016-01-08 21:26:38 +0900 (Fri, 08 Jan 2016) Log Message: ----------- バージョンチェックを変更 コンパイラのバージョンによって VefiryVersionInfo() と GetVersionEx() を使い分けるようにした Modified Paths: -------------- branches/vs2015_warn/teraterm/common/ttlib.c -------------- next part -------------- Modified: branches/vs2015_warn/teraterm/common/ttlib.c =================================================================== --- branches/vs2015_warn/teraterm/common/ttlib.c 2016-01-07 14:49:04 UTC (rev 6258) +++ branches/vs2015_warn/teraterm/common/ttlib.c 2016-01-08 12:26:38 UTC (rev 6259) @@ -978,13 +978,129 @@ OutputDebugString(tmp); } +#if (_MSC_VER < 1800) +BOOL vercmp( + DWORD cond_val, + DWORD act_val, + DWORD dwTypeMask) +{ + switch (dwTypeMask) { + case VER_EQUAL: + if (act_val == cond_val) { + return TRUE; + } + break; + case VER_GREATER: + if (act_val > cond_val) { + return TRUE; + } + break; + case VER_GREATER_EQUAL: + if (act_val >= cond_val) { + return TRUE; + } + break; + case VER_LESS: + if (act_val < cond_val) { + return TRUE; + } + break; + case VER_LESS_EQUAL: + if (act_val <= cond_val) { + return TRUE; + } + break; + } + return FALSE; +} + +/* +DWORDLONG dwlConditionMask +| 000 | 000 | 000 | 000 | 000 | 000 | 000 | 000 | + | | | | | | | +- condition of dwMinorVersion + | | | | | | +------- condition of dwMajorVersion + | | | | | +------------- condition of dwBuildNumber + | | | | +------------------- condition of dwPlatformId + | | | +------------------------- condition of wServicePackMinor + | | +------------------------------- condition of wServicePackMajor + | +------------------------------------- condition of wSuiteMask + +------------------------------------------- condition of wProductType +*/ +BOOL _myVerifyVersionInfo( + LPOSVERSIONINFOEX lpVersionInformation, + DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ + OSVERSIONINFO osvi; + WORD cond; + BOOL ret, check_next; + + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osvi); + + if (dwTypeMask & VER_BUILDNUMBER) { + cond = (WORD)((dwlConditionMask >> 2 * 3) & 0x07); + if (!vercmp(lpVersionInformation->dwBuildNumber, osvi.dwBuildNumber, cond)) { + return FALSE; + } + } + if (dwTypeMask & VER_PLATFORMID) { + cond = (WORD)((dwlConditionMask >> 3 * 3) & 0x07); + if (!vercmp(lpVersionInformation->dwPlatformId, osvi.dwPlatformId, cond)) { + return FALSE; + } + } + ret = TRUE; + if (dwTypeMask & (VER_MAJORVERSION | VER_MINORVERSION)) { + check_next = TRUE; + if (dwTypeMask & VER_MAJORVERSION) { + cond = (WORD)((dwlConditionMask >> 1 * 3) & 0x07); + if (cond == VER_EQUAL) { + if (!vercmp(lpVersionInformation->dwMajorVersion, osvi.dwMajorVersion, cond)) { + return FALSE; + } + } + else { + ret = vercmp(lpVersionInformation->dwMajorVersion, osvi.dwMajorVersion, cond); + if (ret && !vercmp(lpVersionInformation->dwMajorVersion, osvi.dwMajorVersion, VER_EQUAL)) { + check_next = FALSE; + } + } + } + if (check_next && (dwTypeMask & VER_MINORVERSION)) { + cond = (WORD)((dwlConditionMask >> 0 * 3) & 0x07); + if (cond == VER_EQUAL) { + if (!vercmp(lpVersionInformation->dwMinorVersion, osvi.dwMinorVersion, cond)) { + return FALSE; + } + } + else { + ret = vercmp(lpVersionInformation->dwMinorVersion, osvi.dwMinorVersion, cond); + } + } + } + return ret; +} +#endif + +BOOL myVerifyVersionInfo( + LPOSVERSIONINFOEX lpVersionInformation, + DWORD dwTypeMask, + DWORDLONG dwlConditionMask) +{ +#if (_MSC_VER >= 1800) + return VerifyVersionInfo(lpVersionInformation, dwTypeMask, dwlConditionMask); +#else + return _myVerifyVersionInfo(lpVersionInformation, dwTypeMask, dwlConditionMask); +#endif +} + // OS\x82\xAA Windows95 \x82\xA9\x82ǂ\xA4\x82\xA9\x82ʂ\xB7\x82\xE9\x81B // // return TRUE: 95 // FALSE: Not 95 BOOL IsWindows95() { -#if (_MSC_VER >= 1800) OSVERSIONINFOEX osvi; DWORDLONG dwlConditionMask = 0; int op = VER_EQUAL; @@ -998,20 +1114,8 @@ VER_SET_CONDITION(dwlConditionMask, VER_PLATFORMID, op); VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op); VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op); - ret = VerifyVersionInfo(&osvi, VER_PLATFORMID | VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask); + ret = myVerifyVersionInfo(&osvi, VER_PLATFORMID | VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask); return (ret); -#else - OSVERSIONINFO osvi; - - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); - if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && - osvi.dwMajorVersion == 4 && - osvi.dwMinorVersion == 0) { - return TRUE; - } - return FALSE; -#endif } // OS\x82\xAA WindowsNT \x83J\x81[\x83l\x83\x8B\x82\xA9\x82ǂ\xA4\x82\xA9\x82ʂ\xB7\x82\xE9\x81B @@ -1020,7 +1124,6 @@ // FALSE: Not NT4 kernel BOOL IsWindowsNTKernel() { -#if (_MSC_VER >= 1800) OSVERSIONINFOEX osvi; DWORDLONG dwlConditionMask = 0; int op = VER_EQUAL; @@ -1030,18 +1133,8 @@ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); osvi.dwPlatformId = VER_PLATFORM_WIN32_NT; VER_SET_CONDITION(dwlConditionMask, VER_PLATFORMID, op); - ret = VerifyVersionInfo(&osvi, VER_PLATFORMID, dwlConditionMask); + ret = myVerifyVersionInfo(&osvi, VER_PLATFORMID, dwlConditionMask); return (ret); -#else - OSVERSIONINFO osvi; - - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); - if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) { - return TRUE; - } - return FALSE; -#endif } // OS\x82\xAA WindowsNT4.0 \x82\xA9\x82ǂ\xA4\x82\xA9\x82ʂ\xB7\x82\xE9\x81B @@ -1055,7 +1148,6 @@ BOOL is_NT4() { -#if (_MSC_VER >= 1800) // VS2013\x88ȏゾ\x82\xC6 GetVersionEx() \x82\xAA\x8Cx\x8D\x90\x82ƂȂ邽\x82߁AVerifyVersionInfo() \x82\xF0\x8Eg\x82\xA4\x81B // \x82\xB5\x82\xA9\x82\xB5\x81AVS2013\x82Ńr\x83\x8B\x83h\x82\xB5\x82\xBD\x83v\x83\x8D\x83O\x83\x89\x83\x80\x82́A\x82\xBB\x82\xE0\x82\xBB\x82\xE0 NT4.0 \x82ł͓\xAE\x8D삵\x82Ȃ\xA2\x82\xBD\x82߁A // \x96\xB3\x8F\xF0\x8C\x8F\x82\xC9 FALSE \x82\xF0\x95Ԃ\xB5\x82Ă\xE0\x82悢\x82\xA9\x82\xE0\x82\xB5\x82\xEA\x82Ȃ\xA2\x81B @@ -1070,31 +1162,14 @@ osvi.dwMajorVersion = 4; VER_SET_CONDITION(dwlConditionMask, VER_PLATFORMID, op); VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op); - ret = VerifyVersionInfo(&osvi, VER_PLATFORMID | VER_MAJORVERSION, dwlConditionMask); + ret = myVerifyVersionInfo(&osvi, VER_PLATFORMID | VER_MAJORVERSION, dwlConditionMask); return (ret); -#else - OSVERSIONINFO osvi; - - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); - if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && - osvi.dwMajorVersion == 4) { - return TRUE; - } - return FALSE; -#endif } -// OS\x82\xAA Windows2000 \x88ȍ~ \x82\xA9\x82ǂ\xA4\x82\xA9\x82ʂ\xB7\x82\xE9\x81B -// -// return TRUE: 2000 or later -// FALSE: NT4 or earlier -BOOL IsWindows2000OrLater(void) +// OS\x82\xAA \x8Ew\x92肳\x82ꂽ\x83o\x81[\x83W\x83\x87\x83\x93\x88ȍ~ \x82\xA9\x82ǂ\xA4\x82\xA9\x82ʂ\xB7\x82\xE9\x81B + +BOOL IsWindowsVerOrLater(DWORD dwMajorVersion, DWORD dwMinorVersion) { -#if (_MSC_VER >= 1800) - // VS2013\x88ȏゾ\x82\xC6 GetVersionEx() \x82\xAA\x8Cx\x8D\x90\x82ƂȂ邽\x82߁AVerifyVersionInfo() \x82\xF0\x8Eg\x82\xA4\x81B - // \x82\xB5\x82\xA9\x82\xB5\x81AVS2013\x82Ńr\x83\x8B\x83h\x82\xB5\x82\xBD\x83v\x83\x8D\x83O\x83\x89\x83\x80\x82́A\x82\xBB\x82\xE0\x82\xBB\x82\xE0 2000 \x82ł͓\xAE\x8D삵\x82Ȃ\xA2\x82\xBD\x82߁A - // \x96\xB3\x8F\xF0\x8C\x8F\x82\xC9 TRUE \x82\xF0\x95Ԃ\xB5\x82Ă\xE0\x82悢\x82\xA9\x82\xE0\x82\xB5\x82\xEA\x82Ȃ\xA2\x81B OSVERSIONINFOEX osvi; DWORDLONG dwlConditionMask = 0; int op = VER_GREATER_EQUAL; @@ -1102,21 +1177,21 @@ ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - osvi.dwMajorVersion = 5; + osvi.dwMajorVersion = dwMajorVersion; + osvi.dwMinorVersion = dwMinorVersion; VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op); - ret = VerifyVersionInfo(&osvi, VER_MAJORVERSION, dwlConditionMask); + VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op); + ret = myVerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask); return (ret); -#else - OSVERSIONINFO osvi; +} - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); - if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT && - osvi.dwMajorVersion >= 5) { - return TRUE; - } - return FALSE; -#endif +// OS\x82\xAA Windows2000 \x88ȍ~ \x82\xA9\x82ǂ\xA4\x82\xA9\x82ʂ\xB7\x82\xE9\x81B +// +// return TRUE: 2000 or later +// FALSE: NT4 or earlier +BOOL IsWindows2000OrLater(void) +{ + return IsWindowsVerOrLater(5, 0); } // OS\x82\xAA WindowsVista \x88ȍ~ \x82\xA9\x82ǂ\xA4\x82\xA9\x82ʂ\xB7\x82\xE9\x81B @@ -1125,28 +1200,7 @@ // FALSE: XP or earlier BOOL IsWindowsVistaOrLater(void) { -#if (_MSC_VER >= 1800) - OSVERSIONINFOEX osvi; - DWORDLONG dwlConditionMask = 0; - int op = VER_GREATER_EQUAL; - BOOL ret; - - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - osvi.dwMajorVersion = 6; - VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op); - ret = VerifyVersionInfo(&osvi, VER_MAJORVERSION, dwlConditionMask); - return (ret); -#else - OSVERSIONINFO osvi; - - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); - if (osvi.dwMajorVersion >= 6) { - return TRUE; - } - return FALSE; -#endif + return IsWindowsVerOrLater(6, 0); } // OS\x82\xAA Windows7 \x88ȍ~ \x82\xA9\x82ǂ\xA4\x82\xA9\x82ʂ\xB7\x82\xE9\x81B @@ -1155,50 +1209,7 @@ // FALSE: Vista or earlier BOOL IsWindows7OrLater(void) { -#if (_MSC_VER >= 1800) - OSVERSIONINFOEX osvi; - DWORDLONG dwlConditionMask = 0; - int op = VER_GREATER; - BOOL ret; - - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - osvi.dwMajorVersion = 6; - VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op); - ret = VerifyVersionInfo(&osvi, VER_MAJORVERSION, dwlConditionMask); - if (ret) { - return (ret); - } - - dwlConditionMask = 0; - op = VER_EQUAL; - VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op); - ret = VerifyVersionInfo(&osvi, VER_MAJORVERSION, dwlConditionMask); - if (ret) { - dwlConditionMask = 0; - op = VER_GREATER_EQUAL; - osvi.dwMinorVersion = 1; - VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op); - ret = VerifyVersionInfo(&osvi, VER_MINORVERSION, dwlConditionMask); - if (ret) { - return (ret); - } - } - - return FALSE; -#else - OSVERSIONINFO osvi; - - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); - if (osvi.dwMajorVersion > 6) { - return TRUE; - } - if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 1) { - return TRUE; - } - return FALSE; -#endif + return IsWindowsVerOrLater(6, 1); } // OS \x82\xAA\x83}\x83\x8B\x83`\x83\x82\x83j\x83^ API \x82\xF0\x83T\x83|\x81[\x83g\x82\xB5\x82Ă\xA2\x82邩\x82ǂ\xA4\x82\xA9\x82ʂ\xB7\x82\xE9\x81B