From: dmitrykos Date: Thu, 5 Aug 2021 17:23:39 +0000 (+0300) Subject: wasapi: Check for the supported Windows version explicitly in PaWasapi_Initialize... X-Git-Url: https://andrewgundersen.net/repos?a=commitdiff_plain;h=999ca47aeb3954dc8a41df9b510a7b9f035cb3d9;p=portaudio wasapi: Check for the supported Windows version explicitly in PaWasapi_Initialize() and avoid relying on existence on avrt.dll for detecting the compatible platform (user could provide avrt.dll stub that will break initialization of the library if OS version does not support WASAPI backend). --- diff --git a/src/hostapi/wasapi/pa_win_wasapi.c b/src/hostapi/wasapi/pa_win_wasapi.c index cad4b81..1890743 100644 --- a/src/hostapi/wasapi/pa_win_wasapi.c +++ b/src/hostapi/wasapi/pa_win_wasapi.c @@ -1207,6 +1207,8 @@ static BOOL IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WO } #endif // Get Windows version +// note: We are trying to get Windows version starting from Windows Vista. Earlier OS versions +// will fall into WINDOWS_UNKNOWN case. static EWindowsVersion GetWindowsVersion() { #ifndef PA_WINRT @@ -1229,14 +1231,14 @@ static EWindowsVersion GetWindowsVersion() { OSVERSIONINFOW ver = { sizeof(OSVERSIONINFOW), 0, 0, 0, 0, {0} }; - PRINT(("WASAPI: getting Windows version with RtlGetVersion()\n")); - if (fnRtlGetVersion(&ver) == NTSTATUS_SUCCESS) { dwMajorVersion = ver.dwMajorVersion; dwMinorVersion = ver.dwMinorVersion; dwBuild = ver.dwBuildNumber; } + + PRINT(("WASAPI: getting Windows version with RtlGetVersion(): major=%d, minor=%d, build=%d\n", dwMajorVersion, dwMinorVersion, dwBuild)); } #undef NTSTATUS_SUCCESS @@ -1249,17 +1251,15 @@ static EWindowsVersion GetWindowsVersion() if ((fnGetVersion = (LPFN_GETVERSION)GetProcAddress(GetModuleHandleA("kernel32"), "GetVersion")) != NULL) { - DWORD dwVersion; - - PRINT(("WASAPI: getting Windows version with GetVersion()\n")); - - dwVersion = fnGetVersion(); + DWORD dwVersion = fnGetVersion(); dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); if (dwVersion < 0x80000000) dwBuild = (DWORD)(HIWORD(dwVersion)); + + PRINT(("WASAPI: getting Windows version with GetVersion(): major=%d, minor=%d, build=%d\n", dwMajorVersion, dwMinorVersion, dwBuild)); } } @@ -2319,9 +2319,16 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd PaWasapiHostApiRepresentation *paWasapi; #ifndef PA_WINRT + // Fail safely for any Windows version below Windows Vista + if (GetWindowsVersion() == WINDOWS_UNKNOWN) + { + PRINT(("WASAPI: Unsupported Windows version!\n")); + return paNoError; + } + if (!SetupAVRT()) { - PRINT(("WASAPI: No AVRT! (not VISTA?)\n")); + PRINT(("WASAPI: avrt.dll missing! Windows integrity broken?\n")); return paNoError; } #endif @@ -2349,11 +2356,11 @@ PaError PaWasapi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiInd // Fill basic interface info *hostApi = &paWasapi->inheritedHostApiRep; - (*hostApi)->info.structVersion = 1; - (*hostApi)->info.type = paWASAPI; - (*hostApi)->info.name = "Windows WASAPI"; + (*hostApi)->info.structVersion = 1; + (*hostApi)->info.type = paWASAPI; + (*hostApi)->info.name = "Windows WASAPI"; (*hostApi)->info.deviceCount = 0; - (*hostApi)->info.defaultInputDevice = paNoDevice; + (*hostApi)->info.defaultInputDevice = paNoDevice; (*hostApi)->info.defaultOutputDevice = paNoDevice; (*hostApi)->Terminate = Terminate; (*hostApi)->OpenStream = OpenStream;