简体   繁体   中英

C++ verifying the version of directx on Windows Vista OS

I want to test on different OS, Windows Vista, Windows Vista SP1, Windows Vista SP2, Windows 2012R2, Windows 7, Windows 8, Windows 10 and others, is there any possibility of using Direct3D 11 Graphics technology.

Somewhere on msdn found that the best way to make sure that the OS can work with this technology is to call D3D11CreateDevice and check the result.

If you run this code on Windows Vista, which does not have a service pack, it will not even start because there is no d3d11.dll. It turns out that to check supports Direct3D 11 Graphics technology, you need the same technology?

#include "stdafx.h"
#include "windows.h"
#include "dxgi.h"
#include "d3d11.h"

BOOL IsDirectx11Available()
{
    D3D_FEATURE_LEVEL lvl[] = {
        D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0,
        D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1 };

    DWORD createDeviceFlags = 0;

    ID3D11Device *device;
    ID3D11DeviceContext *context;
    D3D_FEATURE_LEVEL fl;

    HRESULT hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
        createDeviceFlags, lvl, _countof(lvl),
        D3D11_SDK_VERSION, &device, &fl, &context);

    if (hr == E_INVALIDARG)
    {
    hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
        createDeviceFlags, &lvl[1], _countof(lvl) - 1,
        D3D11_SDK_VERSION, &device, &fl, &context);

    return false;
}

return true;
}
int main()
{
if (IsDirectx11Available())
{
    printf("Directx api available\n");
}

system("PAUSE");
return 0;
}

Also tried

DWORD dwVersion;
DWORD dwRevision;
if (DirectXSetupGetVersion(&dwVersion, &dwRevision))
{
    printf("DirectX version is %d.%d.%d.%d\n",
           HIWORD(dwVersion), LOWORD(dwVersion),
           HIWORD(dwRevision), LOWORD(dwRevision));
}

with dsetup.h, dsetup.lib from directx sdk. But when I rum .exe it shows notification that dsetup.dll not found.

How to get out of this situation and check the availability on Windows Vista?

Every one of the OSes you list has a specific DirectX version based just on the OS number. With the exception of two specific updates, you can't change which version of DirectX is on the system so there's nothing to 'detect' in most cases. Running the DirectX End-User Runtime doesn't change the DirectX version at all on any of these OSes.

Windows XP SP2     |     DirectX 9.0c
Windows XP SP3     |     DirectX 9.0c
Windows Vista RTM  |     DirectX 10.0
Windows Vista SP1  |     DirectX 10.1
Windows Vista SP2  |     DirectX 10.1 or DirectX 11.0 (KB 971644)
Windows 7 RTM      |     DirectX 11.0
Windows 7 SP1      |     DirectX 11.0 or DirectX 11.1 (KB 2670838)
Windows 8          |     DirectX 11.1
Windows 8.1        |     DirectX 11.2
Windows 10         |     DirectX 12 (build number will determine specifics)

The Server OS equivalents are the same (and have the same version number) starting with Windows Server 2003 SP1.

Remember that only tells you what OS software API is present. You have to try to create a Direct3D device and detect it's Direct3D hardware feature level to know anything about the video card / driver attached to the system. See Direct3D Feature Levels .

To solve the problem of missing d3d11.dll on the non-updated Windows Vista systems you need to use explicit DLL linking (aka LoadLibrary ) or DLL delay loading .

dsetup.dll is only in the legacy DirectX SDK and is part of the side-by-side stuff in the deprecated DirectX End-User Runtime package. That is why it's not present on all your machines. See MSDN . The legacy DirectSetup API was never updated for DirectX 10 or later, so it still reports the same 9.0c number that it always did.

See the following blog posts: Not So Direct Setup , What's in a version number? , and Manifest Madness

A few footnotes:

  • As of Windows Vista RTM or later, there is no Direct3D retained mode, DirectPlay Voice, or DX7/DX8 Visual Basic support as part of the "DirectX 9.0c" components included in later runtimes.

  • As of Windows 8.1 or later, DirectPlay isn't installed by default. It's an Windows optional feature that has to be enabled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM