Win32 API 日本語リファレンス
ホーム › Graphics.Direct3D11 › D3D11CreateDevice

D3D11CreateDevice

関数
Direct3D11デバイスとイミディエイトコンテキストを作成する。
DLLd3d11.dll呼出規約winapi

シグネチャ

// d3d11.dll
#include <windows.h>

HRESULT D3D11CreateDevice(
    IDXGIAdapter* pAdapter,   // optional
    D3D_DRIVER_TYPE DriverType,
    HMODULE Software,   // optional
    D3D11_CREATE_DEVICE_FLAG Flags,
    const D3D_FEATURE_LEVEL* pFeatureLevels,   // optional
    DWORD FeatureLevels,
    DWORD SDKVersion,
    ID3D11Device** ppDevice,   // optional
    D3D_FEATURE_LEVEL* pFeatureLevel,   // optional
    ID3D11DeviceContext** ppImmediateContext   // optional
);

パラメーター

名前型方向説明
pAdapterIDXGIAdapter*inoptional

デバイスの作成時に使用するビデオアダプターへのポインター。既定のアダプターを使用するには NULL を渡します。既定のアダプターとは、IDXGIFactory1::EnumAdapters によって最初に列挙されるアダプターです。

メモ 1 つのアプリケーション内で DXGI 1.0 (IDXGIFactory) と DXGI 1.1 (IDXGIFactory1) を混在して使用しないでください。アプリケーションでは IDXGIFactory または IDXGIFactory1 のいずれか一方を使用し、両方を使用しないでください。
DriverTypeD3D_DRIVER_TYPEin作成するドライバーの種類を表す D3D_DRIVER_TYPE です。
SoftwareHMODULEoptionalソフトウェアラスタライザーを実装する DLL のハンドルです。 DriverType が D3D_DRIVER_TYPE_SOFTWARE の場合、 Software を NULL にすることはできません。ハンドルは LoadLibrary、 LoadLibraryEx、 または GetModuleHandle を呼び出して取得します。
FlagsD3D11_CREATE_DEVICE_FLAGin有効にするランタイムレイヤーです (D3D11_CREATE_DEVICE_FLAG を参照)。 値はビットごとの OR で組み合わせることができます。
pFeatureLevelsD3D_FEATURE_LEVEL*inoptional

作成を試行する機能レベルの順序を決定する D3D_FEATURE_LEVEL の配列へのポインターです。 pFeatureLevels に NULL を設定した場合、 この関数は次の機能レベルの配列を使用します。

{
    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,
};
メモ コンピューターに Direct3D 11.1 ランタイムが存在し、pFeatureLevels に NULL を設定した場合、この関数は D3D_FEATURE_LEVEL_11_1 のデバイスを作成しません。D3D_FEATURE_LEVEL_11_1 のデバイスを作成するには、D3D_FEATURE_LEVEL_11_1 を含む D3D_FEATURE_LEVEL 配列を明示的に指定する必要があります。Direct3D 11.1 ランタイムがインストールされていないコンピューターで D3D_FEATURE_LEVEL_11_1 を含む D3D_FEATURE_LEVEL 配列を指定した場合、この関数は直ちに E_INVALIDARG で失敗します。
FeatureLevelsDWORDinpFeatureLevels の要素数です。
SDKVersionDWORDinSDK のバージョンです。D3D11_SDK_VERSION を使用してください。
ppDeviceID3D11Device**outoptional作成されたデバイスを表す ID3D11Device オブジェクトへのポインターのアドレスを返します。このパラメーターが NULL の場合、ID3D11Device は返されません。
pFeatureLevelD3D_FEATURE_LEVEL*outoptional成功した場合、pFeatureLevels 配列のうち作成に成功した最初の D3D_FEATURE_LEVEL を返します。どの機能レベルがサポートされているかを判別する必要がない場合は、入力として NULL を指定します。
ppImmediateContextID3D11DeviceContext**outoptionalデバイスコンテキストを表す ID3D11DeviceContext オブジェクトへのポインターのアドレスを返します。このパラメーターが NULL の場合、ID3D11DeviceContext は返されません。

戻り値の型: HRESULT

公式ドキュメント

ディスプレイアダプターを表すデバイスを作成します。(D3D11CreateDevice)

戻り値

型: HRESULT

このメソッドは Direct3D 11 の戻り値のいずれかを返すことがあります。

pAdapter パラメーターに NULL 以外の値を設定し、DriverType パラメーターに D3D_DRIVER_TYPE_HARDWARE 値を設定した場合、このメソッドは E_INVALIDARG を返します。

Flags に D3D11_CREATE_DEVICE_DEBUG を指定し、コンピューターに正しくないバージョンのデバッグレイヤーがインストールされている場合、このメソッドは DXGI_ERROR_SDK_COMPONENT_MISSING を返します。正しいバージョンを入手するには、最新の Windows SDK をインストールしてください。

解説(Remarks)

このエントリポイントは Direct3D 11 ランタイムでサポートされます。Direct3D 11 ランタイムは Windows 7、Windows Server 2008 R2 で利用できるほか、Windows Vista 向けの更新プログラム (KB971644) としても提供されます。

Direct3D 11.1 デバイス (ID3D11Device1) は、Windows 8、Windows Server 2012、および Platform Update for Windows 7 をインストールした Windows 7 と Windows Server 2008 R2 で利用できます。これを作成するには、まずこの関数で ID3D11Device を作成し、次に ID3D11Device オブジェクトに対して QueryInterface メソッドを呼び出して ID3D11Device1 インターフェイスを取得します。

Direct3D 11.2 デバイス (ID3D11Device2) は、Windows 8.1 と Windows Server 2012 R2 で利用できます。これを作成するには、まずこの関数で ID3D11Device を作成し、次に ID3D11Device オブジェクトに対して QueryInterface メソッドを呼び出して ID3D11Device2 インターフェイスを取得します。

ppDevice と ppImmediateContext に NULL を設定すると、デバイスを作成せずに pFeatureLevel を確認して、どの機能レベルがサポートされているかを判別できます。

例については、「方法: デバイスと即時コンテキストを作成する」を参照してください。デバイスとスワップチェーンを同時に作成するには、D3D11CreateDeviceAndSwapChain を使用します。

pAdapter パラメーターに NULL 以外の値を設定する場合は、DriverType パラメーターにも D3D_DRIVER_TYPE_UNKNOWN 値を設定する必要があります。pAdapter パラメーターに NULL 以外の値を設定し、DriverType パラメーターに D3D_DRIVER_TYPE_HARDWARE 値を設定した場合、D3D11CreateDevice は E_INVALIDARG の HRESULT を返します。

Direct3D 10 と Direct3D 11 の違い:

Direct3D 10 では、pAdapter の有無によって使用するアダプターが決定され、DriverType はそのアダプターと一致していなくてもかまいませんでした。

Direct3D 11 では、ハードウェアデバイスまたはソフトウェアデバイスを作成しようとする場合、pAdapter != NULL を設定します。これにより、他の入力は次のように制約されます。

  • DriverType は D3D_DRIVER_TYPE_UNKNOWN でなければなりません。
  • Software は NULL でなければなりません。
一方、pAdapter == NULL の場合、DriverType に D3D_DRIVER_TYPE_UNKNOWN を設定することはできません。次のいずれかを設定できます。

関数シグネチャ PFN_D3D11_CREATE_DEVICE は typedef として提供されているため、静的リンクの代わりに動的リンクの手法 (GetProcAddress) を使用できます。

Windows Phone 8: この API はサポートされています。

Windows Phone 8.1: この API はサポートされています。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// d3d11.dll
#include <windows.h>

HRESULT D3D11CreateDevice(
    IDXGIAdapter* pAdapter,   // optional
    D3D_DRIVER_TYPE DriverType,
    HMODULE Software,   // optional
    D3D11_CREATE_DEVICE_FLAG Flags,
    const D3D_FEATURE_LEVEL* pFeatureLevels,   // optional
    DWORD FeatureLevels,
    DWORD SDKVersion,
    ID3D11Device** ppDevice,   // optional
    D3D_FEATURE_LEVEL* pFeatureLevel,   // optional
    ID3D11DeviceContext** ppImmediateContext   // optional
);
[DllImport("d3d11.dll", ExactSpelling = true)]
static extern int D3D11CreateDevice(
    IntPtr pAdapter,   // IDXGIAdapter* optional
    int DriverType,   // D3D_DRIVER_TYPE
    IntPtr Software,   // HMODULE optional
    uint Flags,   // D3D11_CREATE_DEVICE_FLAG
    IntPtr pFeatureLevels,   // D3D_FEATURE_LEVEL* optional
    uint FeatureLevels,   // DWORD
    uint SDKVersion,   // DWORD
    IntPtr ppDevice,   // ID3D11Device** optional, out
    IntPtr pFeatureLevel,   // D3D_FEATURE_LEVEL* optional, out
    IntPtr ppImmediateContext   // ID3D11DeviceContext** optional, out
);
<DllImport("d3d11.dll", ExactSpelling:=True)>
Public Shared Function D3D11CreateDevice(
    pAdapter As IntPtr,   ' IDXGIAdapter* optional
    DriverType As Integer,   ' D3D_DRIVER_TYPE
    Software As IntPtr,   ' HMODULE optional
    Flags As UInteger,   ' D3D11_CREATE_DEVICE_FLAG
    pFeatureLevels As IntPtr,   ' D3D_FEATURE_LEVEL* optional
    FeatureLevels As UInteger,   ' DWORD
    SDKVersion As UInteger,   ' DWORD
    ppDevice As IntPtr,   ' ID3D11Device** optional, out
    pFeatureLevel As IntPtr,   ' D3D_FEATURE_LEVEL* optional, out
    ppImmediateContext As IntPtr   ' ID3D11DeviceContext** optional, out
) As Integer
End Function
' pAdapter : IDXGIAdapter* optional
' DriverType : D3D_DRIVER_TYPE
' Software : HMODULE optional
' Flags : D3D11_CREATE_DEVICE_FLAG
' pFeatureLevels : D3D_FEATURE_LEVEL* optional
' FeatureLevels : DWORD
' SDKVersion : DWORD
' ppDevice : ID3D11Device** optional, out
' pFeatureLevel : D3D_FEATURE_LEVEL* optional, out
' ppImmediateContext : ID3D11DeviceContext** optional, out
Declare PtrSafe Function D3D11CreateDevice Lib "d3d11" ( _
    ByVal pAdapter As LongPtr, _
    ByVal DriverType As Long, _
    ByVal Software As LongPtr, _
    ByVal Flags As Long, _
    ByVal pFeatureLevels As LongPtr, _
    ByVal FeatureLevels As Long, _
    ByVal SDKVersion As Long, _
    ByVal ppDevice As LongPtr, _
    ByVal pFeatureLevel As LongPtr, _
    ByVal ppImmediateContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

D3D11CreateDevice = ctypes.windll.d3d11.D3D11CreateDevice
D3D11CreateDevice.restype = ctypes.c_int
D3D11CreateDevice.argtypes = [
    ctypes.c_void_p,  # pAdapter : IDXGIAdapter* optional
    ctypes.c_int,  # DriverType : D3D_DRIVER_TYPE
    wintypes.HANDLE,  # Software : HMODULE optional
    wintypes.DWORD,  # Flags : D3D11_CREATE_DEVICE_FLAG
    ctypes.c_void_p,  # pFeatureLevels : D3D_FEATURE_LEVEL* optional
    wintypes.DWORD,  # FeatureLevels : DWORD
    wintypes.DWORD,  # SDKVersion : DWORD
    ctypes.c_void_p,  # ppDevice : ID3D11Device** optional, out
    ctypes.c_void_p,  # pFeatureLevel : D3D_FEATURE_LEVEL* optional, out
    ctypes.c_void_p,  # ppImmediateContext : ID3D11DeviceContext** optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('d3d11.dll')
D3D11CreateDevice = Fiddle::Function.new(
  lib['D3D11CreateDevice'],
  [
    Fiddle::TYPE_VOIDP,  # pAdapter : IDXGIAdapter* optional
    Fiddle::TYPE_INT,  # DriverType : D3D_DRIVER_TYPE
    Fiddle::TYPE_VOIDP,  # Software : HMODULE optional
    -Fiddle::TYPE_INT,  # Flags : D3D11_CREATE_DEVICE_FLAG
    Fiddle::TYPE_VOIDP,  # pFeatureLevels : D3D_FEATURE_LEVEL* optional
    -Fiddle::TYPE_INT,  # FeatureLevels : DWORD
    -Fiddle::TYPE_INT,  # SDKVersion : DWORD
    Fiddle::TYPE_VOIDP,  # ppDevice : ID3D11Device** optional, out
    Fiddle::TYPE_VOIDP,  # pFeatureLevel : D3D_FEATURE_LEVEL* optional, out
    Fiddle::TYPE_VOIDP,  # ppImmediateContext : ID3D11DeviceContext** optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "d3d11")]
extern "system" {
    fn D3D11CreateDevice(
        pAdapter: *mut core::ffi::c_void,  // IDXGIAdapter* optional
        DriverType: i32,  // D3D_DRIVER_TYPE
        Software: *mut core::ffi::c_void,  // HMODULE optional
        Flags: u32,  // D3D11_CREATE_DEVICE_FLAG
        pFeatureLevels: *const i32,  // D3D_FEATURE_LEVEL* optional
        FeatureLevels: u32,  // DWORD
        SDKVersion: u32,  // DWORD
        ppDevice: *mut *mut core::ffi::c_void,  // ID3D11Device** optional, out
        pFeatureLevel: *mut i32,  // D3D_FEATURE_LEVEL* optional, out
        ppImmediateContext: *mut *mut core::ffi::c_void  // ID3D11DeviceContext** optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("d3d11.dll")]
public static extern int D3D11CreateDevice(IntPtr pAdapter, int DriverType, IntPtr Software, uint Flags, IntPtr pFeatureLevels, uint FeatureLevels, uint SDKVersion, IntPtr ppDevice, IntPtr pFeatureLevel, IntPtr ppImmediateContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'd3d11_D3D11CreateDevice' -Namespace Win32 -PassThru
# $api::D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext)
#uselib "d3d11.dll"
#func global D3D11CreateDevice "D3D11CreateDevice" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; D3D11CreateDevice pAdapter, DriverType, Software, Flags, varptr(pFeatureLevels), FeatureLevels, SDKVersion, ppDevice, varptr(pFeatureLevel), ppImmediateContext   ; 戻り値は stat
; pAdapter : IDXGIAdapter* optional -> "sptr"
; DriverType : D3D_DRIVER_TYPE -> "sptr"
; Software : HMODULE optional -> "sptr"
; Flags : D3D11_CREATE_DEVICE_FLAG -> "sptr"
; pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "sptr"
; FeatureLevels : DWORD -> "sptr"
; SDKVersion : DWORD -> "sptr"
; ppDevice : ID3D11Device** optional, out -> "sptr"
; pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "sptr"
; ppImmediateContext : ID3D11DeviceContext** optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "d3d11.dll"
#cfunc global D3D11CreateDevice "D3D11CreateDevice" sptr, int, sptr, int, var, int, int, sptr, var, sptr
; res = D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext)
; pAdapter : IDXGIAdapter* optional -> "sptr"
; DriverType : D3D_DRIVER_TYPE -> "int"
; Software : HMODULE optional -> "sptr"
; Flags : D3D11_CREATE_DEVICE_FLAG -> "int"
; pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "var"
; FeatureLevels : DWORD -> "int"
; SDKVersion : DWORD -> "int"
; ppDevice : ID3D11Device** optional, out -> "sptr"
; pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "var"
; ppImmediateContext : ID3D11DeviceContext** optional, out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT D3D11CreateDevice(IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, D3D11_CREATE_DEVICE_FLAG Flags, D3D_FEATURE_LEVEL* pFeatureLevels, DWORD FeatureLevels, DWORD SDKVersion, ID3D11Device** ppDevice, D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext)
#uselib "d3d11.dll"
#cfunc global D3D11CreateDevice "D3D11CreateDevice" intptr, int, intptr, int, var, int, int, intptr, var, intptr
; res = D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext)
; pAdapter : IDXGIAdapter* optional -> "intptr"
; DriverType : D3D_DRIVER_TYPE -> "int"
; Software : HMODULE optional -> "intptr"
; Flags : D3D11_CREATE_DEVICE_FLAG -> "int"
; pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "var"
; FeatureLevels : DWORD -> "int"
; SDKVersion : DWORD -> "int"
; ppDevice : ID3D11Device** optional, out -> "intptr"
; pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "var"
; ppImmediateContext : ID3D11DeviceContext** optional, out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	d3d11 = windows.NewLazySystemDLL("d3d11.dll")
	procD3D11CreateDevice = d3d11.NewProc("D3D11CreateDevice")
)

// pAdapter (IDXGIAdapter* optional), DriverType (D3D_DRIVER_TYPE), Software (HMODULE optional), Flags (D3D11_CREATE_DEVICE_FLAG), pFeatureLevels (D3D_FEATURE_LEVEL* optional), FeatureLevels (DWORD), SDKVersion (DWORD), ppDevice (ID3D11Device** optional, out), pFeatureLevel (D3D_FEATURE_LEVEL* optional, out), ppImmediateContext (ID3D11DeviceContext** optional, out)
r1, _, err := procD3D11CreateDevice.Call(
	uintptr(pAdapter),
	uintptr(DriverType),
	uintptr(Software),
	uintptr(Flags),
	uintptr(pFeatureLevels),
	uintptr(FeatureLevels),
	uintptr(SDKVersion),
	uintptr(ppDevice),
	uintptr(pFeatureLevel),
	uintptr(ppImmediateContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function D3D11CreateDevice(
  pAdapter: Pointer;   // IDXGIAdapter* optional
  DriverType: Integer;   // D3D_DRIVER_TYPE
  Software: THandle;   // HMODULE optional
  Flags: DWORD;   // D3D11_CREATE_DEVICE_FLAG
  pFeatureLevels: Pointer;   // D3D_FEATURE_LEVEL* optional
  FeatureLevels: DWORD;   // DWORD
  SDKVersion: DWORD;   // DWORD
  ppDevice: Pointer;   // ID3D11Device** optional, out
  pFeatureLevel: Pointer;   // D3D_FEATURE_LEVEL* optional, out
  ppImmediateContext: Pointer   // ID3D11DeviceContext** optional, out
): Integer; stdcall;
  external 'd3d11.dll' name 'D3D11CreateDevice';
result := DllCall("d3d11\D3D11CreateDevice"
    , "Ptr", pAdapter   ; IDXGIAdapter* optional
    , "Int", DriverType   ; D3D_DRIVER_TYPE
    , "Ptr", Software   ; HMODULE optional
    , "UInt", Flags   ; D3D11_CREATE_DEVICE_FLAG
    , "Ptr", pFeatureLevels   ; D3D_FEATURE_LEVEL* optional
    , "UInt", FeatureLevels   ; DWORD
    , "UInt", SDKVersion   ; DWORD
    , "Ptr", ppDevice   ; ID3D11Device** optional, out
    , "Ptr", pFeatureLevel   ; D3D_FEATURE_LEVEL* optional, out
    , "Ptr", ppImmediateContext   ; ID3D11DeviceContext** optional, out
    , "Int")   ; return: HRESULT
●D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext) = DLL("d3d11.dll", "int D3D11CreateDevice(void*, int, void*, dword, void*, dword, dword, void*, void*, void*)")
# 呼び出し: D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext)
# pAdapter : IDXGIAdapter* optional -> "void*"
# DriverType : D3D_DRIVER_TYPE -> "int"
# Software : HMODULE optional -> "void*"
# Flags : D3D11_CREATE_DEVICE_FLAG -> "dword"
# pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "void*"
# FeatureLevels : DWORD -> "dword"
# SDKVersion : DWORD -> "dword"
# ppDevice : ID3D11Device** optional, out -> "void*"
# pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "void*"
# ppImmediateContext : ID3D11DeviceContext** optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "d3d11" fn D3D11CreateDevice(
    pAdapter: ?*anyopaque, // IDXGIAdapter* optional
    DriverType: i32, // D3D_DRIVER_TYPE
    Software: ?*anyopaque, // HMODULE optional
    Flags: u32, // D3D11_CREATE_DEVICE_FLAG
    pFeatureLevels: [*c]i32, // D3D_FEATURE_LEVEL* optional
    FeatureLevels: u32, // DWORD
    SDKVersion: u32, // DWORD
    ppDevice: ?*anyopaque, // ID3D11Device** optional, out
    pFeatureLevel: [*c]i32, // D3D_FEATURE_LEVEL* optional, out
    ppImmediateContext: ?*anyopaque // ID3D11DeviceContext** optional, out
) callconv(std.os.windows.WINAPI) i32;
proc D3D11CreateDevice(
    pAdapter: pointer,  # IDXGIAdapter* optional
    DriverType: int32,  # D3D_DRIVER_TYPE
    Software: pointer,  # HMODULE optional
    Flags: uint32,  # D3D11_CREATE_DEVICE_FLAG
    pFeatureLevels: ptr int32,  # D3D_FEATURE_LEVEL* optional
    FeatureLevels: uint32,  # DWORD
    SDKVersion: uint32,  # DWORD
    ppDevice: pointer,  # ID3D11Device** optional, out
    pFeatureLevel: ptr int32,  # D3D_FEATURE_LEVEL* optional, out
    ppImmediateContext: pointer  # ID3D11DeviceContext** optional, out
): int32 {.importc: "D3D11CreateDevice", stdcall, dynlib: "d3d11.dll".}
pragma(lib, "d3d11");
extern(Windows)
int D3D11CreateDevice(
    void* pAdapter,   // IDXGIAdapter* optional
    int DriverType,   // D3D_DRIVER_TYPE
    void* Software,   // HMODULE optional
    uint Flags,   // D3D11_CREATE_DEVICE_FLAG
    int* pFeatureLevels,   // D3D_FEATURE_LEVEL* optional
    uint FeatureLevels,   // DWORD
    uint SDKVersion,   // DWORD
    void* ppDevice,   // ID3D11Device** optional, out
    int* pFeatureLevel,   // D3D_FEATURE_LEVEL* optional, out
    void* ppImmediateContext   // ID3D11DeviceContext** optional, out
);
ccall((:D3D11CreateDevice, "d3d11.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Ptr{Cvoid}, UInt32, Ptr{Int32}, UInt32, UInt32, Ptr{Cvoid}, Ptr{Int32}, Ptr{Cvoid}),
      pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext)
# pAdapter : IDXGIAdapter* optional -> Ptr{Cvoid}
# DriverType : D3D_DRIVER_TYPE -> Int32
# Software : HMODULE optional -> Ptr{Cvoid}
# Flags : D3D11_CREATE_DEVICE_FLAG -> UInt32
# pFeatureLevels : D3D_FEATURE_LEVEL* optional -> Ptr{Int32}
# FeatureLevels : DWORD -> UInt32
# SDKVersion : DWORD -> UInt32
# ppDevice : ID3D11Device** optional, out -> Ptr{Cvoid}
# pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> Ptr{Int32}
# ppImmediateContext : ID3D11DeviceContext** optional, out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t D3D11CreateDevice(
    void* pAdapter,
    int32_t DriverType,
    void* Software,
    uint32_t Flags,
    int32_t* pFeatureLevels,
    uint32_t FeatureLevels,
    uint32_t SDKVersion,
    void* ppDevice,
    int32_t* pFeatureLevel,
    void* ppImmediateContext);
]]
local d3d11 = ffi.load("d3d11")
-- d3d11.D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext)
-- pAdapter : IDXGIAdapter* optional
-- DriverType : D3D_DRIVER_TYPE
-- Software : HMODULE optional
-- Flags : D3D11_CREATE_DEVICE_FLAG
-- pFeatureLevels : D3D_FEATURE_LEVEL* optional
-- FeatureLevels : DWORD
-- SDKVersion : DWORD
-- ppDevice : ID3D11Device** optional, out
-- pFeatureLevel : D3D_FEATURE_LEVEL* optional, out
-- ppImmediateContext : ID3D11DeviceContext** optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('d3d11.dll');
const D3D11CreateDevice = lib.func('__stdcall', 'D3D11CreateDevice', 'int32_t', ['void *', 'int32_t', 'void *', 'uint32_t', 'int32_t *', 'uint32_t', 'uint32_t', 'void *', 'int32_t *', 'void *']);
// D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext)
// pAdapter : IDXGIAdapter* optional -> 'void *'
// DriverType : D3D_DRIVER_TYPE -> 'int32_t'
// Software : HMODULE optional -> 'void *'
// Flags : D3D11_CREATE_DEVICE_FLAG -> 'uint32_t'
// pFeatureLevels : D3D_FEATURE_LEVEL* optional -> 'int32_t *'
// FeatureLevels : DWORD -> 'uint32_t'
// SDKVersion : DWORD -> 'uint32_t'
// ppDevice : ID3D11Device** optional, out -> 'void *'
// pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> 'int32_t *'
// ppImmediateContext : ID3D11DeviceContext** optional, out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("d3d11.dll", {
  D3D11CreateDevice: { parameters: ["pointer", "i32", "pointer", "u32", "pointer", "u32", "u32", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext)
// pAdapter : IDXGIAdapter* optional -> "pointer"
// DriverType : D3D_DRIVER_TYPE -> "i32"
// Software : HMODULE optional -> "pointer"
// Flags : D3D11_CREATE_DEVICE_FLAG -> "u32"
// pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "pointer"
// FeatureLevels : DWORD -> "u32"
// SDKVersion : DWORD -> "u32"
// ppDevice : ID3D11Device** optional, out -> "pointer"
// pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "pointer"
// ppImmediateContext : ID3D11DeviceContext** optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t D3D11CreateDevice(
    void* pAdapter,
    int32_t DriverType,
    void* Software,
    uint32_t Flags,
    int32_t* pFeatureLevels,
    uint32_t FeatureLevels,
    uint32_t SDKVersion,
    void* ppDevice,
    int32_t* pFeatureLevel,
    void* ppImmediateContext);
C, "d3d11.dll");
// $ffi->D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext);
// pAdapter : IDXGIAdapter* optional
// DriverType : D3D_DRIVER_TYPE
// Software : HMODULE optional
// Flags : D3D11_CREATE_DEVICE_FLAG
// pFeatureLevels : D3D_FEATURE_LEVEL* optional
// FeatureLevels : DWORD
// SDKVersion : DWORD
// ppDevice : ID3D11Device** optional, out
// pFeatureLevel : D3D_FEATURE_LEVEL* optional, out
// ppImmediateContext : ID3D11DeviceContext** optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface D3d11 extends StdCallLibrary {
    D3d11 INSTANCE = Native.load("d3d11", D3d11.class);
    int D3D11CreateDevice(
        Pointer pAdapter,   // IDXGIAdapter* optional
        int DriverType,   // D3D_DRIVER_TYPE
        Pointer Software,   // HMODULE optional
        int Flags,   // D3D11_CREATE_DEVICE_FLAG
        IntByReference pFeatureLevels,   // D3D_FEATURE_LEVEL* optional
        int FeatureLevels,   // DWORD
        int SDKVersion,   // DWORD
        Pointer ppDevice,   // ID3D11Device** optional, out
        IntByReference pFeatureLevel,   // D3D_FEATURE_LEVEL* optional, out
        Pointer ppImmediateContext   // ID3D11DeviceContext** optional, out
    );
}
@[Link("d3d11")]
lib Libd3d11
  fun D3D11CreateDevice = D3D11CreateDevice(
    pAdapter : Void*,   # IDXGIAdapter* optional
    DriverType : Int32,   # D3D_DRIVER_TYPE
    Software : Void*,   # HMODULE optional
    Flags : UInt32,   # D3D11_CREATE_DEVICE_FLAG
    pFeatureLevels : Int32*,   # D3D_FEATURE_LEVEL* optional
    FeatureLevels : UInt32,   # DWORD
    SDKVersion : UInt32,   # DWORD
    ppDevice : Void*,   # ID3D11Device** optional, out
    pFeatureLevel : Int32*,   # D3D_FEATURE_LEVEL* optional, out
    ppImmediateContext : Void*   # ID3D11DeviceContext** optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef D3D11CreateDeviceNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Uint32, Pointer<Int32>, Uint32, Uint32, Pointer<Void>, Pointer<Int32>, Pointer<Void>);
typedef D3D11CreateDeviceDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Int32>, int, int, Pointer<Void>, Pointer<Int32>, Pointer<Void>);
final D3D11CreateDevice = DynamicLibrary.open('d3d11.dll')
    .lookupFunction<D3D11CreateDeviceNative, D3D11CreateDeviceDart>('D3D11CreateDevice');
// pAdapter : IDXGIAdapter* optional -> Pointer<Void>
// DriverType : D3D_DRIVER_TYPE -> Int32
// Software : HMODULE optional -> Pointer<Void>
// Flags : D3D11_CREATE_DEVICE_FLAG -> Uint32
// pFeatureLevels : D3D_FEATURE_LEVEL* optional -> Pointer<Int32>
// FeatureLevels : DWORD -> Uint32
// SDKVersion : DWORD -> Uint32
// ppDevice : ID3D11Device** optional, out -> Pointer<Void>
// pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> Pointer<Int32>
// ppImmediateContext : ID3D11DeviceContext** optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function D3D11CreateDevice(
  pAdapter: Pointer;   // IDXGIAdapter* optional
  DriverType: Integer;   // D3D_DRIVER_TYPE
  Software: THandle;   // HMODULE optional
  Flags: DWORD;   // D3D11_CREATE_DEVICE_FLAG
  pFeatureLevels: Pointer;   // D3D_FEATURE_LEVEL* optional
  FeatureLevels: DWORD;   // DWORD
  SDKVersion: DWORD;   // DWORD
  ppDevice: Pointer;   // ID3D11Device** optional, out
  pFeatureLevel: Pointer;   // D3D_FEATURE_LEVEL* optional, out
  ppImmediateContext: Pointer   // ID3D11DeviceContext** optional, out
): Integer; stdcall;
  external 'd3d11.dll' name 'D3D11CreateDevice';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "D3D11CreateDevice"
  c_D3D11CreateDevice :: Ptr () -> Int32 -> Ptr () -> Word32 -> Ptr Int32 -> Word32 -> Word32 -> Ptr () -> Ptr Int32 -> Ptr () -> IO Int32
-- pAdapter : IDXGIAdapter* optional -> Ptr ()
-- DriverType : D3D_DRIVER_TYPE -> Int32
-- Software : HMODULE optional -> Ptr ()
-- Flags : D3D11_CREATE_DEVICE_FLAG -> Word32
-- pFeatureLevels : D3D_FEATURE_LEVEL* optional -> Ptr Int32
-- FeatureLevels : DWORD -> Word32
-- SDKVersion : DWORD -> Word32
-- ppDevice : ID3D11Device** optional, out -> Ptr ()
-- pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> Ptr Int32
-- ppImmediateContext : ID3D11DeviceContext** optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let d3d11createdevice =
  foreign "D3D11CreateDevice"
    ((ptr void) @-> int32_t @-> (ptr void) @-> uint32_t @-> (ptr int32_t) @-> uint32_t @-> uint32_t @-> (ptr void) @-> (ptr int32_t) @-> (ptr void) @-> returning int32_t)
(* pAdapter : IDXGIAdapter* optional -> (ptr void) *)
(* DriverType : D3D_DRIVER_TYPE -> int32_t *)
(* Software : HMODULE optional -> (ptr void) *)
(* Flags : D3D11_CREATE_DEVICE_FLAG -> uint32_t *)
(* pFeatureLevels : D3D_FEATURE_LEVEL* optional -> (ptr int32_t) *)
(* FeatureLevels : DWORD -> uint32_t *)
(* SDKVersion : DWORD -> uint32_t *)
(* ppDevice : ID3D11Device** optional, out -> (ptr void) *)
(* pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> (ptr int32_t) *)
(* ppImmediateContext : ID3D11DeviceContext** optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library d3d11 (t "d3d11.dll"))
(cffi:use-foreign-library d3d11)

(cffi:defcfun ("D3D11CreateDevice" d3-d11-create-device :convention :stdcall) :int32
  (p-adapter :pointer)   ; IDXGIAdapter* optional
  (driver-type :int32)   ; D3D_DRIVER_TYPE
  (software :pointer)   ; HMODULE optional
  (flags :uint32)   ; D3D11_CREATE_DEVICE_FLAG
  (p-feature-levels :pointer)   ; D3D_FEATURE_LEVEL* optional
  (feature-levels :uint32)   ; DWORD
  (sdkversion :uint32)   ; DWORD
  (pp-device :pointer)   ; ID3D11Device** optional, out
  (p-feature-level :pointer)   ; D3D_FEATURE_LEVEL* optional, out
  (pp-immediate-context :pointer))   ; ID3D11DeviceContext** optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $D3D11CreateDevice = Win32::API::More->new('d3d11',
    'int D3D11CreateDevice(LPVOID pAdapter, int DriverType, HANDLE Software, DWORD Flags, LPVOID pFeatureLevels, DWORD FeatureLevels, DWORD SDKVersion, LPVOID ppDevice, LPVOID pFeatureLevel, LPVOID ppImmediateContext)');
# my $ret = $D3D11CreateDevice->Call($pAdapter, $DriverType, $Software, $Flags, $pFeatureLevels, $FeatureLevels, $SDKVersion, $ppDevice, $pFeatureLevel, $ppImmediateContext);
# pAdapter : IDXGIAdapter* optional -> LPVOID
# DriverType : D3D_DRIVER_TYPE -> int
# Software : HMODULE optional -> HANDLE
# Flags : D3D11_CREATE_DEVICE_FLAG -> DWORD
# pFeatureLevels : D3D_FEATURE_LEVEL* optional -> LPVOID
# FeatureLevels : DWORD -> DWORD
# SDKVersion : DWORD -> DWORD
# ppDevice : ID3D11Device** optional, out -> LPVOID
# pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> LPVOID
# ppImmediateContext : ID3D11DeviceContext** optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型