E_INVALIDARG一个或多个参数无效。 - CreateDevice

时间:2014-01-16 01:44:58

标签: c++ windows-8 directx

我有一个d3dDevice:

ComPtr<ID3D11Device1>d3dDevice;

我在这里使用dxgiDevice:

    ComPtr<IDXGIDevice3> dxgiDevice2;

    HRESULT hr;

    hr = d3dDevice.As( &dxgiDevice2 ); // S_OK

    hr = d2dFactory->CreateDevice( dxgiDevice2.Get(), d2dDevice.GetAddressOf() ); // E_INVALIDARG One or more arguments are invalid

    hr = d2dDevice->CreateDeviceContext(
        D2D1_DEVICE_CONTEXT_OPTIONS_NONE,
        &d2dDeviceContext
        );

为什么可能在运行时发生此错误?

http://msdn.microsoft.com/en-us/library/windows/desktop/dn280482(v=vs.85).aspx

我的代码与问题相关的全部内容:http://pastebin.com/P7Rs9xdh

1 个答案:

答案 0 :(得分:4)

问题是您尚未创建DX11设备以与Direct2D兼容。您需要传递正确的创建标志,还应考虑定义所需的功能级别。类似的东西:

// This flag adds support for surfaces with a different color channel 
// ordering than the API default.
// You need it for compatibility with Direct2D.
UINT creationFlags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;

// This array defines the set of DirectX hardware feature levels this 
// app supports.
// The ordering is important and you should  preserve it.
// Don't forget to declare your app's minimum required feature level in its
// description.  All apps are assumed to support 9.1 unless otherwise stated.
D3D_FEATURE_LEVEL featureLevels[] =
{
    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 m_featureLevel;

// Create 3D device and device context objects
D3D11CreateDevice(
    nullptr,
    D3D_DRIVER_TYPE_HARDWARE,
    nullptr,
    creationFlags,
    featureLevels,
    ARRAYSIZE(featureLevels),
    D3D11_SDK_VERSION,
    &d3dDevice11,
    &m_featureLevel,
    &d3dDeviceContext11);