Alex Alex - 1 year ago 181
C Question

Calling DuplicateOutput With D3D12Device Fails With E_NOINTERFACE

I have been trying to make an application that utilizes the desktop duplication api, but having no experience with directx it is turning out to be quite a challenge. Everything seems to work until I call

at which point it returns E_NOINTERFACE. This error is not defined in the msdn documentation so I am having trouble diagnosing the problem. I think that this code should work, but I must be missing something.

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

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

In my debug window I notice that I am getting two _com_errors when I call


I narrowed the problem down to the fact that I am using a ID3D12Device instead of an ID3D11Device. As exemplified by the fact that this code works:

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

What I don't understand is why that is a problem. Isn't the desktop duplication api compatible with directx 12?

Answer Source

DXGI DuplicateOutput does not support DirectX 12 devices yet. As you have no experience using DirectX, you should be using DirectX 11 anyhow. DirectX 12 is an API designed for graphics experts who are assumed to already be deeply familiar with DirectX 11.

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download