Freigeben über

D3D11CreateDevice Function

Creates a device that represents the display adapter.


HRESULT D3D11CreateDevice(
  __in   IDXGIAdapter *pAdapter,
  __in   D3D_DRIVER_TYPE DriverType,
  __in   HMODULE Software,
  __in   UINT Flags,
  __in   const D3D_FEATURE_LEVEL *pFeatureLevels,
  __in   UINT FeatureLevels,
  __in   UINT SDKVersion,
  __out  ID3D11Device **ppDevice,
  __out  D3D_FEATURE_LEVEL *pFeatureLevel,
  __out  ID3D11DeviceContext **ppImmediateContext


  • pAdapter [in]
    Typ: IDXGIAdapter*

    A pointer to the video adapter to use when creating a device. Pass NULL to use the default adapter, which is the first adapter that is enumerated by IDXGIFactory1::EnumAdapters.

    Hinweis  Do not mix the use of DXGI 1.0 (IDXGIFactory) and DXGI 1.1 (IDXGIFactory1) in an application. Use IDXGIFactory or IDXGIFactory1, but not both in an application.

  • DriverType [in]

    The D3D_DRIVER_TYPE, which represents the driver type to create.

  • Software [in]
    Typ: HMODULE

    A handle to a DLL that implements a software rasterizer. If DriverType is D3D_DRIVER_TYPE_SOFTWARE, Software must not be NULL. Get the handle by calling LoadLibrary, LoadLibraryEx , or GetModuleHandle.

  • Flags [in]
    Typ: UINT

    The runtime layers to enable (see D3D11_CREATE_DEVICE_FLAG); values can be bitwise OR'd together.

  • pFeatureLevels [in]
    Typ: const D3D_FEATURE_LEVEL*

    A pointer to an array of D3D_FEATURE_LEVELs, which determine the order of feature levels to attempt to create. Use default parameters to get the greatest feature level available. If pFeatureLevels is set to NULL, the following array of feature levels will be used:

  • FeatureLevels [in]
    Typ: UINT

    The number of elements in pFeatureLevels.

  • SDKVersion [in]
    Typ: UINT

    The SDK version; use D3D11_SDK_VERSION.

  • ppDevice [out]
    Typ: ID3D11Device**

    Returns the address of a pointer to an ID3D11Device object that represents the device created.

  • pFeatureLevel [out]

    If successful, returns the first D3D_FEATURE_LEVEL from the pFeatureLevels array which succeeded. Otherwise, returns 0.

  • ppImmediateContext [out]
    Typ: ID3D11DeviceContext**

    Returns the address of a pointer to an ID3D11DeviceContext object that represents the device context.



This method returns one of the following Direct3D 11 Return Codes.


This entry-point is supported by the Direct3D 11 runtime, which is available on Windows 7, Windows Server 2008 R2, and as an update to Windows Vista (KB971644).

Set ppDevice and ppImmediateContext to NULL to determine which feature level is supported by looking at pFeatureLevel without creating a device.

For an example, see How To: Create a Device and Immediate Context; to create a device and a swap chain at the same time, use D3D11CreateDeviceAndSwapChain.

If you set the pAdapter parameter to a non-NULL value, you must also set the DriverType parameter to the D3D_DRIVER_TYPE_UNKNOWN value. If you set the pAdapter parameter to a non-NULL value and the DriverType parameter to the D3D_DRIVER_TYPE_HARDWARE value, D3D11CreateDevice returns an HRESULT of E_INVALIDARG.

Differences between Direct3D 10 and Direct3D 11:

In Direct3D 10, the presence of pAdapter dictated which adapter to use and the DriverType could mismatch what the adapter was.

In Direct3D 11, if you are trying to create a hardware or a software device, set pAdapter != NULL which constrains the other inputs to be:

  • DriverType must be D3D_DRIVER_TYPE_UNKNOWN
  • Software must be NULL.

On the other hand, if pAdapter == NULL, the DriverType cannot be set to D3D_DRIVER_TYPE_UNKNOWN; it can be set to either:

  • If DriverType == D3D_DRIVER_TYPE_SOFTWARE, Software cannot be NULL.
  • If DriverType == D3D_DRIVER_TYPE_HARDWARE, the adapter used will be the default adapter, which is the first adapter that is enumerated by IDXGIFactory1::EnumAdapters







Siehe auch

Core Functions