C++ 在 Windows Vista OS 上验证 directx 的版本

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

我想测试不同的 OS、Windows Vista、Windows Vista SP1、Windows Vista SP2、Windows 2012R2、Windows7、Windows8、Windows10等,有没有可能使用Direct3D 11图形技术

在 msdn 的某个地方发现,确保 OS 可以使用此技术的最佳方法是调用 D3D11CreateDevice 并检查结果。

如果您在没有服务包的 Windows Vista 上 运行 此代码,它甚至不会启动,因为没有 d3d11.dll。原来要勾选支持Direct3D 11 Graphics技术,你需要同样的技术吗?

#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;
}

也尝试过

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));
}

与来自 d​​irectx sdk 的 dsetup.h、dsetup.lib。但是当我朗姆酒时 .exe 它显示 dsetup.dll 未找到的通知。

如何摆脱这种情况并检查 Windows Vista 的可用性?

您列出的每个 OSes 都有一个特定的 DirectX 版本,仅基于 OS 编号。除了两个特定的更新之外,您无法更改系统上的 DirectX 版本,因此在大多数情况下 'detect' 没有什么可做的。 运行 DirectX 最终用户运行时 根本不会更改任何这些 OSes 上的 DirectX 版本。

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)

Server OS 等效项是相同的(并且具有相同的版本号)从 Windows Server 2003 SP1 开始。

请记住,它只会告诉您存在什么 OS 软件 API。您必须尝试创建一个 Direct3D 设备并检测它的 Direct3D 硬件功能级别才能了解有关连接到系统的视频卡/驱动程序的任何信息。参见 Direct3D Feature Levels

要解决在未更新的Windows Vista 系统上缺少d3d11.dll 的问题,您需要使用显式DLL 链接(a.k.a。LoadLibrary) 或 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.

查看以下博文:Not So Direct Setup, What’s in a version number?, and Manifest Madness

几个脚注:

  • 从 Windows Vista RTM 或更高版本开始,没有 Direct3D 保留模式、DirectPlay 语音或 DX7/DX8 Visual Basic 支持作为 "DirectX 9.0c" 的一部分组件包含在以后的运行时中。

  • 从 Windows 8.1 或更高版本开始,默认情况下不安装 DirectPlay。这是一项必须启用的 Windows 可选功能。