ホーム › Graphics.Direct3D11 › D3D11CreateDeviceAndSwapChain
D3D11CreateDeviceAndSwapChain
関数Direct3D11デバイスとコンテキストおよびスワップチェーンを同時に作成する。
シグネチャ
// d3d11.dll
#include <windows.h>
HRESULT D3D11CreateDeviceAndSwapChain(
IDXGIAdapter* pAdapter, // optional
D3D_DRIVER_TYPE DriverType,
HMODULE Software,
D3D11_CREATE_DEVICE_FLAG Flags,
const D3D_FEATURE_LEVEL* pFeatureLevels, // optional
DWORD FeatureLevels,
DWORD SDKVersion,
const DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, // optional
IDXGISwapChain** ppSwapChain, // optional
ID3D11Device** ppDevice, // optional
D3D_FEATURE_LEVEL* pFeatureLevel, // optional
ID3D11DeviceContext** ppImmediateContext // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pAdapter | IDXGIAdapter* | inoptional |
| DriverType | D3D_DRIVER_TYPE | in |
| Software | HMODULE | in |
| Flags | D3D11_CREATE_DEVICE_FLAG | in |
| pFeatureLevels | D3D_FEATURE_LEVEL* | inoptional |
| FeatureLevels | DWORD | in |
| SDKVersion | DWORD | in |
| pSwapChainDesc | DXGI_SWAP_CHAIN_DESC* | inoptional |
| ppSwapChain | IDXGISwapChain** | outoptional |
| ppDevice | ID3D11Device** | outoptional |
| pFeatureLevel | D3D_FEATURE_LEVEL* | outoptional |
| ppImmediateContext | ID3D11DeviceContext** | outoptional |
戻り値の型: HRESULT
各言語での呼び出し定義
// d3d11.dll
#include <windows.h>
HRESULT D3D11CreateDeviceAndSwapChain(
IDXGIAdapter* pAdapter, // optional
D3D_DRIVER_TYPE DriverType,
HMODULE Software,
D3D11_CREATE_DEVICE_FLAG Flags,
const D3D_FEATURE_LEVEL* pFeatureLevels, // optional
DWORD FeatureLevels,
DWORD SDKVersion,
const DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, // optional
IDXGISwapChain** ppSwapChain, // optional
ID3D11Device** ppDevice, // optional
D3D_FEATURE_LEVEL* pFeatureLevel, // optional
ID3D11DeviceContext** ppImmediateContext // optional
);[DllImport("d3d11.dll", ExactSpelling = true)]
static extern int D3D11CreateDeviceAndSwapChain(
IntPtr pAdapter, // IDXGIAdapter* optional
int DriverType, // D3D_DRIVER_TYPE
IntPtr Software, // HMODULE
uint Flags, // D3D11_CREATE_DEVICE_FLAG
IntPtr pFeatureLevels, // D3D_FEATURE_LEVEL* optional
uint FeatureLevels, // DWORD
uint SDKVersion, // DWORD
IntPtr pSwapChainDesc, // DXGI_SWAP_CHAIN_DESC* optional
IntPtr ppSwapChain, // IDXGISwapChain** optional, out
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 D3D11CreateDeviceAndSwapChain(
pAdapter As IntPtr, ' IDXGIAdapter* optional
DriverType As Integer, ' D3D_DRIVER_TYPE
Software As IntPtr, ' HMODULE
Flags As UInteger, ' D3D11_CREATE_DEVICE_FLAG
pFeatureLevels As IntPtr, ' D3D_FEATURE_LEVEL* optional
FeatureLevels As UInteger, ' DWORD
SDKVersion As UInteger, ' DWORD
pSwapChainDesc As IntPtr, ' DXGI_SWAP_CHAIN_DESC* optional
ppSwapChain As IntPtr, ' IDXGISwapChain** optional, out
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
' Flags : D3D11_CREATE_DEVICE_FLAG
' pFeatureLevels : D3D_FEATURE_LEVEL* optional
' FeatureLevels : DWORD
' SDKVersion : DWORD
' pSwapChainDesc : DXGI_SWAP_CHAIN_DESC* optional
' ppSwapChain : IDXGISwapChain** optional, out
' ppDevice : ID3D11Device** optional, out
' pFeatureLevel : D3D_FEATURE_LEVEL* optional, out
' ppImmediateContext : ID3D11DeviceContext** optional, out
Declare PtrSafe Function D3D11CreateDeviceAndSwapChain 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 pSwapChainDesc As LongPtr, _
ByVal ppSwapChain As LongPtr, _
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
D3D11CreateDeviceAndSwapChain = ctypes.windll.d3d11.D3D11CreateDeviceAndSwapChain
D3D11CreateDeviceAndSwapChain.restype = ctypes.c_int
D3D11CreateDeviceAndSwapChain.argtypes = [
ctypes.c_void_p, # pAdapter : IDXGIAdapter* optional
ctypes.c_int, # DriverType : D3D_DRIVER_TYPE
wintypes.HANDLE, # Software : HMODULE
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, # pSwapChainDesc : DXGI_SWAP_CHAIN_DESC* optional
ctypes.c_void_p, # ppSwapChain : IDXGISwapChain** optional, out
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')
D3D11CreateDeviceAndSwapChain = Fiddle::Function.new(
lib['D3D11CreateDeviceAndSwapChain'],
[
Fiddle::TYPE_VOIDP, # pAdapter : IDXGIAdapter* optional
Fiddle::TYPE_INT, # DriverType : D3D_DRIVER_TYPE
Fiddle::TYPE_VOIDP, # Software : HMODULE
-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, # pSwapChainDesc : DXGI_SWAP_CHAIN_DESC* optional
Fiddle::TYPE_VOIDP, # ppSwapChain : IDXGISwapChain** optional, out
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 D3D11CreateDeviceAndSwapChain(
pAdapter: *mut core::ffi::c_void, // IDXGIAdapter* optional
DriverType: i32, // D3D_DRIVER_TYPE
Software: *mut core::ffi::c_void, // HMODULE
Flags: u32, // D3D11_CREATE_DEVICE_FLAG
pFeatureLevels: *const i32, // D3D_FEATURE_LEVEL* optional
FeatureLevels: u32, // DWORD
SDKVersion: u32, // DWORD
pSwapChainDesc: *const DXGI_SWAP_CHAIN_DESC, // DXGI_SWAP_CHAIN_DESC* optional
ppSwapChain: *mut *mut core::ffi::c_void, // IDXGISwapChain** optional, out
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 D3D11CreateDeviceAndSwapChain(IntPtr pAdapter, int DriverType, IntPtr Software, uint Flags, IntPtr pFeatureLevels, uint FeatureLevels, uint SDKVersion, IntPtr pSwapChainDesc, IntPtr ppSwapChain, IntPtr ppDevice, IntPtr pFeatureLevel, IntPtr ppImmediateContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'd3d11_D3D11CreateDeviceAndSwapChain' -Namespace Win32 -PassThru
# $api::D3D11CreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext)#uselib "d3d11.dll"
#func global D3D11CreateDeviceAndSwapChain "D3D11CreateDeviceAndSwapChain" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; D3D11CreateDeviceAndSwapChain pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, varptr(pSwapChainDesc), ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext ; 戻り値は stat
; pAdapter : IDXGIAdapter* optional -> "sptr"
; DriverType : D3D_DRIVER_TYPE -> "sptr"
; Software : HMODULE -> "sptr"
; Flags : D3D11_CREATE_DEVICE_FLAG -> "sptr"
; pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "sptr"
; FeatureLevels : DWORD -> "sptr"
; SDKVersion : DWORD -> "sptr"
; pSwapChainDesc : DXGI_SWAP_CHAIN_DESC* optional -> "sptr"
; ppSwapChain : IDXGISwapChain** optional, out -> "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 D3D11CreateDeviceAndSwapChain "D3D11CreateDeviceAndSwapChain" sptr, int, sptr, int, int, int, int, var, sptr, sptr, int, sptr ; res = D3D11CreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext) ; pAdapter : IDXGIAdapter* optional -> "sptr" ; DriverType : D3D_DRIVER_TYPE -> "int" ; Software : HMODULE -> "sptr" ; Flags : D3D11_CREATE_DEVICE_FLAG -> "int" ; pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "int" ; FeatureLevels : DWORD -> "int" ; SDKVersion : DWORD -> "int" ; pSwapChainDesc : DXGI_SWAP_CHAIN_DESC* optional -> "var" ; ppSwapChain : IDXGISwapChain** optional, out -> "sptr" ; ppDevice : ID3D11Device** optional, out -> "sptr" ; pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "int" ; ppImmediateContext : ID3D11DeviceContext** optional, out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "d3d11.dll" #cfunc global D3D11CreateDeviceAndSwapChain "D3D11CreateDeviceAndSwapChain" sptr, int, sptr, int, int, int, int, sptr, sptr, sptr, int, sptr ; res = D3D11CreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, varptr(pSwapChainDesc), ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext) ; pAdapter : IDXGIAdapter* optional -> "sptr" ; DriverType : D3D_DRIVER_TYPE -> "int" ; Software : HMODULE -> "sptr" ; Flags : D3D11_CREATE_DEVICE_FLAG -> "int" ; pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "int" ; FeatureLevels : DWORD -> "int" ; SDKVersion : DWORD -> "int" ; pSwapChainDesc : DXGI_SWAP_CHAIN_DESC* optional -> "sptr" ; ppSwapChain : IDXGISwapChain** optional, out -> "sptr" ; ppDevice : ID3D11Device** optional, out -> "sptr" ; pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "int" ; ppImmediateContext : ID3D11DeviceContext** optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HRESULT D3D11CreateDeviceAndSwapChain(IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, D3D11_CREATE_DEVICE_FLAG Flags, D3D_FEATURE_LEVEL* pFeatureLevels, DWORD FeatureLevels, DWORD SDKVersion, DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, IDXGISwapChain** ppSwapChain, ID3D11Device** ppDevice, D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext) #uselib "d3d11.dll" #cfunc global D3D11CreateDeviceAndSwapChain "D3D11CreateDeviceAndSwapChain" intptr, int, intptr, int, int, int, int, var, intptr, intptr, int, intptr ; res = D3D11CreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext) ; pAdapter : IDXGIAdapter* optional -> "intptr" ; DriverType : D3D_DRIVER_TYPE -> "int" ; Software : HMODULE -> "intptr" ; Flags : D3D11_CREATE_DEVICE_FLAG -> "int" ; pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "int" ; FeatureLevels : DWORD -> "int" ; SDKVersion : DWORD -> "int" ; pSwapChainDesc : DXGI_SWAP_CHAIN_DESC* optional -> "var" ; ppSwapChain : IDXGISwapChain** optional, out -> "intptr" ; ppDevice : ID3D11Device** optional, out -> "intptr" ; pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "int" ; ppImmediateContext : ID3D11DeviceContext** optional, out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HRESULT D3D11CreateDeviceAndSwapChain(IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, D3D11_CREATE_DEVICE_FLAG Flags, D3D_FEATURE_LEVEL* pFeatureLevels, DWORD FeatureLevels, DWORD SDKVersion, DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, IDXGISwapChain** ppSwapChain, ID3D11Device** ppDevice, D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext) #uselib "d3d11.dll" #cfunc global D3D11CreateDeviceAndSwapChain "D3D11CreateDeviceAndSwapChain" intptr, int, intptr, int, int, int, int, intptr, intptr, intptr, int, intptr ; res = D3D11CreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, varptr(pSwapChainDesc), ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext) ; pAdapter : IDXGIAdapter* optional -> "intptr" ; DriverType : D3D_DRIVER_TYPE -> "int" ; Software : HMODULE -> "intptr" ; Flags : D3D11_CREATE_DEVICE_FLAG -> "int" ; pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "int" ; FeatureLevels : DWORD -> "int" ; SDKVersion : DWORD -> "int" ; pSwapChainDesc : DXGI_SWAP_CHAIN_DESC* optional -> "intptr" ; ppSwapChain : IDXGISwapChain** optional, out -> "intptr" ; ppDevice : ID3D11Device** optional, out -> "intptr" ; pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "int" ; ppImmediateContext : ID3D11DeviceContext** optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
d3d11 = windows.NewLazySystemDLL("d3d11.dll")
procD3D11CreateDeviceAndSwapChain = d3d11.NewProc("D3D11CreateDeviceAndSwapChain")
)
// pAdapter (IDXGIAdapter* optional), DriverType (D3D_DRIVER_TYPE), Software (HMODULE), Flags (D3D11_CREATE_DEVICE_FLAG), pFeatureLevels (D3D_FEATURE_LEVEL* optional), FeatureLevels (DWORD), SDKVersion (DWORD), pSwapChainDesc (DXGI_SWAP_CHAIN_DESC* optional), ppSwapChain (IDXGISwapChain** optional, out), ppDevice (ID3D11Device** optional, out), pFeatureLevel (D3D_FEATURE_LEVEL* optional, out), ppImmediateContext (ID3D11DeviceContext** optional, out)
r1, _, err := procD3D11CreateDeviceAndSwapChain.Call(
uintptr(pAdapter),
uintptr(DriverType),
uintptr(Software),
uintptr(Flags),
uintptr(pFeatureLevels),
uintptr(FeatureLevels),
uintptr(SDKVersion),
uintptr(pSwapChainDesc),
uintptr(ppSwapChain),
uintptr(ppDevice),
uintptr(pFeatureLevel),
uintptr(ppImmediateContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction D3D11CreateDeviceAndSwapChain(
pAdapter: Pointer; // IDXGIAdapter* optional
DriverType: Integer; // D3D_DRIVER_TYPE
Software: THandle; // HMODULE
Flags: DWORD; // D3D11_CREATE_DEVICE_FLAG
pFeatureLevels: Pointer; // D3D_FEATURE_LEVEL* optional
FeatureLevels: DWORD; // DWORD
SDKVersion: DWORD; // DWORD
pSwapChainDesc: Pointer; // DXGI_SWAP_CHAIN_DESC* optional
ppSwapChain: Pointer; // IDXGISwapChain** optional, out
ppDevice: Pointer; // ID3D11Device** optional, out
pFeatureLevel: Pointer; // D3D_FEATURE_LEVEL* optional, out
ppImmediateContext: Pointer // ID3D11DeviceContext** optional, out
): Integer; stdcall;
external 'd3d11.dll' name 'D3D11CreateDeviceAndSwapChain';result := DllCall("d3d11\D3D11CreateDeviceAndSwapChain"
, "Ptr", pAdapter ; IDXGIAdapter* optional
, "Int", DriverType ; D3D_DRIVER_TYPE
, "Ptr", Software ; HMODULE
, "UInt", Flags ; D3D11_CREATE_DEVICE_FLAG
, "Ptr", pFeatureLevels ; D3D_FEATURE_LEVEL* optional
, "UInt", FeatureLevels ; DWORD
, "UInt", SDKVersion ; DWORD
, "Ptr", pSwapChainDesc ; DXGI_SWAP_CHAIN_DESC* optional
, "Ptr", ppSwapChain ; IDXGISwapChain** optional, out
, "Ptr", ppDevice ; ID3D11Device** optional, out
, "Ptr", pFeatureLevel ; D3D_FEATURE_LEVEL* optional, out
, "Ptr", ppImmediateContext ; ID3D11DeviceContext** optional, out
, "Int") ; return: HRESULT●D3D11CreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext) = DLL("d3d11.dll", "int D3D11CreateDeviceAndSwapChain(void*, int, void*, dword, void*, dword, dword, void*, void*, void*, void*, void*)")
# 呼び出し: D3D11CreateDeviceAndSwapChain(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, ppDevice, pFeatureLevel, ppImmediateContext)
# pAdapter : IDXGIAdapter* optional -> "void*"
# DriverType : D3D_DRIVER_TYPE -> "int"
# Software : HMODULE -> "void*"
# Flags : D3D11_CREATE_DEVICE_FLAG -> "dword"
# pFeatureLevels : D3D_FEATURE_LEVEL* optional -> "void*"
# FeatureLevels : DWORD -> "dword"
# SDKVersion : DWORD -> "dword"
# pSwapChainDesc : DXGI_SWAP_CHAIN_DESC* optional -> "void*"
# ppSwapChain : IDXGISwapChain** optional, out -> "void*"
# 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)。