ホーム › Graphics.Direct3D11 › D3D11CreateDevice
D3D11CreateDevice
関数Direct3D11デバイスとイミディエイトコンテキストを作成する。
シグネチャ
// 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
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pAdapter | IDXGIAdapter* | inoptional | 使用するディスプレイアダプターのIDXGIAdapter。NULLで既定を使う。 |
| DriverType | D3D_DRIVER_TYPE | in | ハードウェアやWARP等のドライバー種別を示す列挙値。 |
| Software | HMODULE | optional | ソフトウェアラスタライザーDLLのモジュールハンドル。通常NULL。 |
| Flags | D3D11_CREATE_DEVICE_FLAG | in | デバイス生成時の動作を制御するD3D11_CREATE_DEVICE_FLAGの組み合わせ。 |
| pFeatureLevels | D3D_FEATURE_LEVEL* | inoptional | 試行する機能レベルの優先順位付き配列。NULLで既定順を使う。 |
| FeatureLevels | DWORD | in | pFeatureLevels配列の要素数を指定する。 |
| SDKVersion | DWORD | in | ビルド対象のSDKバージョン。D3D11_SDK_VERSIONを指定する。 |
| ppDevice | ID3D11Device** | outoptional | 生成されたID3D11Deviceを受け取る出力先。NULL可。 |
| pFeatureLevel | D3D_FEATURE_LEVEL* | outoptional | 実際に採用された機能レベルを受け取る出力先。NULL可。 |
| ppImmediateContext | ID3D11DeviceContext** | outoptional | 生成された即時実行コンテキストを受け取る出力先。NULL可。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "d3d11.dll" #cfunc global D3D11CreateDevice "D3D11CreateDevice" sptr, int, sptr, int, sptr, int, int, sptr, sptr, sptr ; res = D3D11CreateDevice(pAdapter, DriverType, Software, Flags, varptr(pFeatureLevels), FeatureLevels, SDKVersion, ppDevice, varptr(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 -> "sptr" ; FeatureLevels : DWORD -> "int" ; SDKVersion : DWORD -> "int" ; ppDevice : ID3D11Device** optional, out -> "sptr" ; pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "sptr" ; ppImmediateContext : ID3D11DeviceContext** optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; 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, intptr, int, int, intptr, intptr, intptr ; res = D3D11CreateDevice(pAdapter, DriverType, Software, Flags, varptr(pFeatureLevels), FeatureLevels, SDKVersion, ppDevice, varptr(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 -> "intptr" ; FeatureLevels : DWORD -> "int" ; SDKVersion : DWORD -> "int" ; ppDevice : ID3D11Device** optional, out -> "intptr" ; pFeatureLevel : D3D_FEATURE_LEVEL* optional, out -> "intptr" ; ppImmediateContext : ID3D11DeviceContext** optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // HRESULTfunction 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 を使用。