0
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ Debug vs release ... any uninitialized variables? Does debug mode give you any warnings in console ouptut? \$\endgroup\$
    – Steven
    Commented Mar 16, 2015 at 23:59
  • \$\begingroup\$ You need to validate the HRESULT from every function that returns one to actually be sure you have correct code: As and GetParent both return HRESULTs you are ignoring. \$\endgroup\$ Commented Mar 17, 2015 at 0:09
  • \$\begingroup\$ Also, since you are making use of 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\$ Commented Mar 17, 2015 at 0:10

1 Answer 1

0
\$\begingroup\$

Found it...

Simple typo:

IDXGIAdapter1* pDxgiAdapter = 0;
spDXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&pDxgiAdapter);

IDXGIFactory2* pDxgiFactory = 0;
pDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&pDxgiFactory);

Should have been (with Chuck Walbourn's 'ComPtr suggestions):

Microsoft::WRL::ComPtr<IDXGIAdapter2> spDxgiAdapter;
HR(spDXGIDevice->GetParent(__uuidof(IDXGIAdapter2), (void**)&spDxgiAdapter));

Microsoft::WRL::ComPtr<IDXGIFactory2> spDxgiFactory;
HR(spDxgiAdapter->GetParent(__uuidof(IDXGIFactory2), (void**)&spDxgiFactory));

I had not upgraded my uuidof(...) interface IDs. It's so easy to leave of the correct numerical suffix to these things. Thanks for your resposes :)

\$\endgroup\$
2
  • \$\begingroup\$ You should use the IID_PPV_ARGS macro to avoid these kinds of mismatches in the future. For example, GetParent(IID_PPV_ARGS(&spDxgiFactory)). \$\endgroup\$
    – MooseBoys
    Commented Mar 27, 2015 at 21:55
  • \$\begingroup\$ IID_PPV_ARGS is the more robust way to go. I tend to avoid it in my code because it was missing in the Xbox One XDK at least at one point... \$\endgroup\$ Commented Jun 23, 2015 at 7:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .