- What happens if
SetConsoleMode(handle, ENABLE_VIRTUAL_TERMINAL_PROCESSING)
is invoked on a Windows version that does not support the mode (i.e. prior to version 10.0.14393)? - How do we differentiate between Windows not supporting
ENABLE_VIRTUAL_TERMINAL_PROCESSING
versus the mode being supported butSetConsoleMode()
failing for a different reason?
Asked
Active
Viewed 186 times
1

Gili
- 86,244
- 97
- 390
- 689
1 Answers
1
Answering my own question:
Seeing as the specification does not provide a concrete answer we are forced to use the Windows version to make a decision:
/**
* @param majorVersion a major version number
* @param minorVersion a minor version number
* @param buildVersion a build version number
* @return true if the Windows version is greater than or equal to the specified number
*/
bool isWindowsVersionOrGreater(WORD majorVersion, WORD minorVersion, WORD buildVersion)
{
// See http://stackoverflow.com/a/36545162/14731 and https://github.com/DarthTon/Blackbone/blob/master/contrib/VersionHelpers.h#L78
RTL_OSVERSIONINFOW verInfo = { 0 };
verInfo.dwOSVersionInfoSize = sizeof(verInfo);
static auto RtlGetVersion = (RtlGetVersionPtr) GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "RtlGetVersion");
if (RtlGetVersion != 0 && RtlGetVersion(&verInfo) == 0)
{
if (verInfo.dwMajorVersion > majorVersion)
return true;
else if (verInfo.dwMajorVersion < majorVersion)
return false;
if (verInfo.dwMinorVersion > minorVersion)
return true;
else if (verInfo.dwMinorVersion < minorVersion)
return false;
if (verInfo.dwBuildNumber >= buildVersion)
return true;
}
return false;
}
If the Windows version is equal to or greater than 10.0.14393
then ENABLE_VIRTUAL_TERMINAL_PROCESSING
is supported.

Gili
- 86,244
- 97
- 390
- 689
-
plus one ... that is C code so I might make it `extern "C"` – Chef Gladiator Nov 03 '20 at 12:41