WinAPI deprecation after Windows 8.1

徘徊边缘 提交于 2019-12-06 03:55:53

问题


I have been using GetVersionEx and it failed in machine which runs with Windows 8.1. After looking some information found out that GetVersionEx is depracated since 8.1 version.

I want to ask where could I find full list of deprecated APIs because I don't want to use it anymore.

EDIT: I'm not asking what to use instead of GetVersionEx, I'm asking for a full list of deprecated APIs.


回答1:


Microsoft has described the changes in Operating system version changes in Windows 8.1 and Windows Server 2012 R2. On the left of the article you can navigate to other issues related to Windows 8.1 and Windows Server 2012 R2 client and server compatibility.

The behavior you experience is the following:

In Windows 8.1, the GetVersion(Ex) APIs have been deprecated. That means that while you can still call the APIs, if your app does not specifically target Windows 8.1, you will get Windows 8 versioning (6.2.0.0).




回答2:


Somebody on another forum pointed me to this approach.

Include your Windows 8.1 OS GUID in your application Manifest file

your .manifest should include Windows 8.1. and look like this.

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
   <application>
     <!--This Id value indicates the application supports Windows 8.1 functionality-->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>

</application>

One issue with this approach is that your old binaries will always show the wrong Windows version on Windows 8.1 and later Windows Version.

another issue with this approach is that the GetVersionEx API is still deprecated so you will be not able to target Visual Studio 2013 Platform Toolset. You must set your Platform Toolset to Visual Studio 2012 or below.

Update: Actually I remembered you can disable that using something like this.

#pragma warning (disable : 4996)    
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
POSVERSIONINFO pVersionInfo = (POSVERSIONINFO)&versionInfo;
if (::GetVersionEx(pVersionInfo))
{
    if (6 == versionInfo.dwMajorVersion && 3 == versionInfo.dwMinorVersion)
    {
        wcout << _T("Windows 8.1 Detected") << endl;
    }
    else if (6 == versionInfo.dwMajorVersion && 2 == versionInfo.dwMinorVersion)
    {
        wcout << _T("Windows 8.0 Detected") << endl;
    }       
}
#pragma warning (default : 4996)

you could use a NetWkstaGetInfo API to get local machine's Version as well.

bool GetWindowsVersion(DWORD& major, DWORD& minor)
{   
    LPBYTE pinfoRawData;
    if (NERR_Success == NetWkstaGetInfo(NULL, 100, &pinfoRawData))
    {
        WKSTA_INFO_100 * pworkstationInfo = (WKSTA_INFO_100 *)pinfoRawData;
        major = pworkstationInfo->wki100_ver_major;
        minor = pworkstationInfo->wki100_ver_minor;
        ::NetApiBufferFree(pinfoRawData);
        return true;
    }
    return false;
}
int _tmain(int argc, _TCHAR* argv[])
{   
    DWORD major = 0;
    DWORD minor = 0;
    if (GetWindowsVersion(major, minor))
    {
        wcout << _T("Major:") << major << _T("Minor:") << minor << endl;
    }   
    return 0;
}

All that Said I have written two code samples to get Windows Version Without using GetVersionEx or GetVersion APIs. I have posted them on the bottom of the page. The issue is GetVersionEx API takes only about 10 Micro Seconds to Execute while my code samples take upward of 10-50 milliseconds to execute.

Getting Windows Version VerifyVersionInfo API



来源:https://stackoverflow.com/questions/19518670/winapi-deprecation-after-windows-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!