The CreateSwapChainForHwnd fails with E_NOINTERFACE "No such interface supported" when I use the Graphics Diagnostics on Visual Studio 2013 Update 4 on Windows 7 sp1 under DirectX 11.1. The program runs fine in debug mode. Has anyone come across this problem before or know of a solution?
Here is the initialisation code:
#include <d3d11_1.h>
// Set feature levels supported by our application
D3D_FEATURE_LEVEL eFeatureLevel1[] =
{
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
};
D3D_FEATURE_LEVEL eReturnedFeatureLevel;
D3D11CreateDevice(nullptr, // default adapter
D3D_DRIVER_TYPE_HARDWARE,
0, // no software device
uiCreateDeviceFlags,
eFeatureLevel1,
ARRAYSIZE(eFeatureLevel1),
D3D11_SDK_VERSION,
&m_spDeviceOld,
&eReturnedFeatureLevel,
&m_spContextOld);
if (eReturnedFeatureLevel < D3D_FEATURE_LEVEL_11_0)
{
//MessageBox fails silently here!!!
return false;
}
// Fetch the underlying interfaces and store them:
m_spDeviceOld.As(&m_spD3DDevice);
m_spContextOld.As(&m_spD3DImmediateContext);
SETPRIVATEDATA(m_spDeviceOld, "CD3DObject::m_spDeviceOld");
SETPRIVATEDATA(m_spContextOld, "CD3DObject::m_spDeviceOldspContextOld");
// This is the earliest the Debug Layer can be created
MyDebugLayer.CreateD3DDebugLayer();
SETPRIVATEDATA(m_spD3DDevice, "CD3DObject::m_spD3DDevice");
SETPRIVATEDATA(m_spD3DImmediateContext, "CD3DObject::m_spD3DImmediateContext");
m_spD3DDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM,
4,
&m_ui4xMsaaQuality);
assert(m_ui4xMsaaQuality > 0);
DXGI_SWAP_CHAIN_DESC1 stSwpChainDesc = { 0 };
stSwpChainDesc.Width = 0;
stSwpChainDesc.Height = 0;
stSwpChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
stSwpChainDesc.Stereo = false;
stSwpChainDesc.SampleDesc.Count = 1;
stSwpChainDesc.SampleDesc.Quality = 0;
stSwpChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
stSwpChainDesc.BufferCount = 1; // Used to be 1
stSwpChainDesc.Scaling = DXGI_SCALING_STRETCH;
stSwpChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
stSwpChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
// Use 4X MSAA?
if (m_bEnable4xMsaa)
{
stSwpChainDesc.SampleDesc.Count = 4;
stSwpChainDesc.SampleDesc.Quality = m_ui4xMsaaQuality - 1;
}
// No MSAA
else
{
stSwpChainDesc.SampleDesc.Count = 1;
stSwpChainDesc.SampleDesc.Quality = 0;
}
Microsoft::WRL::ComPtr<IDXGIDevice1> spDXGIDevice;
m_spD3DDevice.As(&spDXGIDevice);
IDXGIAdapter1* pDxgiAdapter = 0;
spDXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&pDxgiAdapter);
IDXGIFactory2* pDxgiFactory = 0;
pDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&pDxgiFactory);
// Create DXGI swap chain targeting a window handle (the only Windows 7-compatible option)
HRESULT MyHr = pDxgiFactory->CreateSwapChainForHwnd((ID3D11Device*)m_spD3DDevice.Get(), m_hMainWnd, &stSwpChainDesc, nullptr, nullptr, &m_spSwapChain);
//MessageBox fails silently here!!!
//MessageBox(m_hMainWnd, _com_error(MyHr).ErrorMessage(), "Error Caputed", MB_OK);
ReleaseCOM(pDxgiAdapter);
ReleaseCOM(pDxgiFactory);
spDXGIDevice->Release();
Why does the code fail when I use the graphics diagnostics tool and not normally? Basically the main window appears then the application shuts down. Also any calls to MessageBox([NULL/or not]) fails silently too.
Supplemental: m_spDeviceOld and m_spContextOld are ID3D11Device and ID3D11DeviceContext used for getting the 11.1 interface they then are detached at exit and the 11.1 interfaces are released instead.
Thanks in advance for your indelible advice.
HRESULT
from every function that returns one to actually be sure you have correct code:As
andGetParent
both return HRESULTs you are ignoring. \$\endgroup\$ComPtr
, you should use it for the DXGI code:Microsoft::WRL::ComPtr<DXGIAdapter1> pDxgiAdapter; hr = spDXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&pDxgiAdapter); /* can remove ReleaseCOM(pDxgiAdapter); since that is now automatic */
\$\endgroup\$