Skip to content

Commit 5300a5a

Browse files
author
Matthieu Longo
committed
[Windows 8.1 and latter] warning C4996: GetVersionExA was declared deprecated
1 parent 51e8a5e commit 5300a5a

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

Main/StackWalker/StackWalker.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,14 +1439,10 @@ void StackWalker::OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUser
14391439
buffer[STACKWALK_MAX_NAMELEN - 1] = 0;
14401440
OnOutput(buffer);
14411441
}
1442-
#else
1442+
#elif (_MSC_VER < 1800)
14431443
OSVERSIONINFOEXA ver;
14441444
ZeroMemory(&ver, sizeof(OSVERSIONINFOEXA));
14451445
ver.dwOSVersionInfoSize = sizeof(ver);
1446-
#if _MSC_VER >= 1900
1447-
#pragma warning(push)
1448-
#pragma warning(disable : 4996)
1449-
#endif
14501446
if (GetVersionExA((OSVERSIONINFOA*)&ver) != FALSE)
14511447
{
14521448
_snprintf_s(buffer, maxLen, "OS-Version: %d.%d.%d (%s) 0x%x-0x%x\n", ver.dwMajorVersion,
@@ -1455,9 +1451,30 @@ void StackWalker::OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUser
14551451
buffer[STACKWALK_MAX_NAMELEN - 1] = 0;
14561452
OnOutput(buffer);
14571453
}
1458-
#if _MSC_VER >= 1900
1459-
#pragma warning(pop)
1460-
#endif
1454+
#else
1455+
OSVERSIONINFOEXW osInfo;
1456+
// Get a handle on RtlGetVersion
1457+
HMODULE h_NtDll = GetModuleHandleW(L"ntdll.dll");
1458+
typedef LONG(WINAPI * tRtlGetVersion)(RTL_OSVERSIONINFOEXW*);
1459+
tRtlGetVersion f_RtlGetVersion = (tRtlGetVersion)GetProcAddress(h_NtDll, "RtlGetVersion");
1460+
if (!f_RtlGetVersion)
1461+
{ // This will never happen (all processes load ntdll.dll)
1462+
_snprintf(buffer, STACKWALK_MAX_NAMELEN, "Windows V00");
1463+
}
1464+
else
1465+
{
1466+
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
1467+
f_RtlGetVersion(&osInfo);
1468+
CHAR servicePack[128] = {'\0'};
1469+
if (wcslen(osInfo.szCSDVersion) > 0)
1470+
{
1471+
_snprintf_s(servicePack, 128, "(%s) ", osInfo.szCSDVersion);
1472+
}
1473+
_snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "OS-Version: %d.%d.%d %s0x%x-0x%x\n",
1474+
osInfo.dwMajorVersion, osInfo.dwMinorVersion, osInfo.dwBuildNumber, servicePack,
1475+
osInfo.wSuiteMask, osInfo.wProductType);
1476+
}
1477+
OnOutput(buffer);
14611478
#endif
14621479
}
14631480

0 commit comments

Comments
 (0)