简体   繁体   English

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

[英]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. 我想在不同的OS,Windows Vista,Windows Vista SP1,Windows Vista SP2,Windows 2012R2,Windows 7,Windows 8,Windows 10和其他操作系统上进行测试,是否有可能使用Direct3D 11 Graphics技术。

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. msdn上的某个地方发现,确保OS可以使用该技术的最佳方法是调用D3D11CreateDevice并检查结果。

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. 如果您在没有Service Pack的Windows Vista上运行此代码,则由于没有d3d11.dll,它甚至无法启动。 It turns out that to check supports Direct3D 11 Graphics technology, you need the same technology? 原来,要检查是否支持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;
}

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. 使用dsetup.h,directx sdk中的dsetup.lib。 But when I rum .exe it shows notification that dsetup.dll not found. 但是当我朗读.exe它显示未找到dsetup.dll的通知。

How to get out of this situation and check the availability on Windows Vista? 如何摆脱这种情况并检查Windows Vista上的可用性?

Every one of the OSes you list has a specific DirectX version based just on the OS number. 您列出的每个操作系统都有仅基于操作系统编号的特定DirectX版本。 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. 除了两个特定的更新之外,您无法更改系统上的DirectX版本,因此在大多数情况下无需“检测”。 Running the DirectX End-User Runtime doesn't change the DirectX version at all on any of these OSes. 在任何这些操作系统上,运行DirectX最终用户运行时都不会更改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)

The Server OS equivalents are the same (and have the same version number) starting with Windows Server 2003 SP1. 从Windows Server 2003 SP1开始,等效的Server OS是相同的(并且具有相同的版本号)。

Remember that only tells you what OS software API is present. 请记住,这仅告诉您存在哪些OS软件API。 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. 您必须尝试创建Direct3D设备并检测它的Direct3D硬件功能级别,才能了解有关系统中连接的视频卡/驱动程序的任何信息。 See Direct3D Feature Levels . 请参见Direct3D功能级别

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

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. dsetup.dll仅在旧版DirectX SDK中,并且是不建议使用的DirectX最终用户运行时程序包中并行内容的一部分。 That is why it's not present on all your machines. 这就是为什么它不存在于所有计算机上的原因。 See MSDN . 参见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. 遗留DirectSetup API从来没有更新的DirectX 10或更高版本,所以它仍然报告说,它总是做同样的9.0C号。

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. 从Windows Vista RTM或更高版本开始,没有更高版本的Direct3D保留模式,DirectPlay语音或DX7 / DX8 Visual Basic支持作为更高版本的运行时中包含的“ DirectX 9.0c”组件的一部分。

  • As of Windows 8.1 or later, DirectPlay isn't installed by default. 从Windows 8.1或更高版本开始,默认情况下未安装DirectPlay。 It's an Windows optional feature that has to be enabled. 这是必须启用的Windows可选功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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