c++ - 使用 D3D12Device 调用 DuplicateOutput 失败并出现 E_NOINTERFACE

标签 c++ c windows directx directx-12

我一直在尝试制作一个利用桌面复制 API 的应用程序,但由于没有使用 directx 的经验,这确实是一个相当大的挑战。一切似乎都正常,直到我调用 output1->DuplicateOutput(),此时它返回 E_NOINTERFACE。 msdn 文档中没有定义此错误,因此我无法诊断该问题。我认为这段代码应该可以工作,但我一定错过了一些东西。

#include <windows.h>
#include <d3d12.h>
#include <dxgi1_5.h>

int main()
{
    HRESULT hr;
    ID3D12Debug *debug;
    hr = D3D12GetDebugInterface(IID_PPV_ARGS(&debug));
    debug->EnableDebugLayer();
    IDXGIFactory1 *factory;
    hr = CreateDXGIFactory1(IID_PPV_ARGS(&factory));
    IDXGIAdapter1 *adapter;
    hr = factory->EnumAdapters1(0, &adapter);
    factory->Release();
    IDXGIOutput *junkput;
    hr = adapter->EnumOutputs(0, &junkput);
    IDXGIOutput1 *output1;
    hr = junkput->QueryInterface(IID_PPV_ARGS(&output1));
    junkput->Release();
    ID3D12Device *device;
    hr = D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));
    IDXGIOutputDuplication *dupl;
    hr = output1->DuplicateOutput(device, &dupl);
    return 0;
}

在我的调试窗口中,我注意到当我调用 output1->DuplicateOutput 时收到两个 _com_errors。

更新:

我将问题范围缩小到我使用的是 ID3D12Device 而不是 ID3D11Device。正如此代码有效的事实所证明的:

ID3D11Device *device;
D3D_FEATURE_LEVEL reallevel;
ID3D11DeviceContext *context;
hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, NULL, featurelevels, ARRAYSIZE(featurelevels), D3D11_SDK_VERSION, &device, &reallevel, &context);
IDXGIOutputDuplication *dupl;
hr = output1->DuplicateOutput(device, &dupl);

我不明白为什么这是一个问题。桌面复制 API 不兼容 directx 12 吗?

最佳答案

DXGI DuplicateOutput 尚不支持 DirectX 12 设备。由于您没有使用 DirectX 的经验,因此无论如何您都应该使用 DirectX 11。 DirectX 12 是专为图形专家设计的 API,假定他们已经非常熟悉 DirectX 11。

Note that D3D11On12CreateDevice devices should work with DXGI DuplicateOutput, but I've not tried it myself.

关于c++ - 使用 D3D12Device 调用 DuplicateOutput 失败并出现 E_NOINTERFACE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40165786/

相关文章:

c++ - 在多线程场景中提升 asio async_receive_from 缓冲消息

c - 为什么不使用大于 10 位的数字?

c - 在具有多个输入值的 C 中使用 atof() 函数

c# - 是否可以通过关联文件将命令行参数传递给可执行文件?

windows - 检测windows上的核心数

java - 哪个Jdk版本支持windows xp

在 Mac OS X Snow Leopard 上使用 Xcode 的 C++11

c# - 固定地址在.NET中被占用

c++ - 通过类名实例化类

c - 将枚举值切换为位标志