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 output1->DuplicateOutput()
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()
{
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;
}
In my debug window I notice that I am getting two _com_errors when I call output1->DuplicateOutput
.
Update:
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?