Win32 API 日本語リファレンス
ホームAI.MachineLearning.DirectML › DMLCreateDevice

DMLCreateDevice

関数
指定したD3D12デバイス上にDirectMLデバイスを作成する。
DLLDirectML.dll呼出規約winapi対応OSWindows 10 以降

シグネチャ

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

HRESULT DMLCreateDevice(
    ID3D12Device* d3d12Device,
    DML_CREATE_DEVICE_FLAGS flags,
    const GUID* riid,
    void** ppv   // optional
);

パラメーター

名前方向
d3d12DeviceID3D12Device*in
flagsDML_CREATE_DEVICE_FLAGSin
riidGUID*in
ppvvoid**outoptional

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT DMLCreateDevice(
    ID3D12Device* d3d12Device,
    DML_CREATE_DEVICE_FLAGS flags,
    const GUID* riid,
    void** ppv   // optional
);
[DllImport("DirectML.dll", ExactSpelling = true)]
static extern int DMLCreateDevice(
    IntPtr d3d12Device,   // ID3D12Device*
    int flags,   // DML_CREATE_DEVICE_FLAGS
    ref Guid riid,   // GUID*
    IntPtr ppv   // void** optional, out
);
<DllImport("DirectML.dll", ExactSpelling:=True)>
Public Shared Function DMLCreateDevice(
    d3d12Device As IntPtr,   ' ID3D12Device*
    flags As Integer,   ' DML_CREATE_DEVICE_FLAGS
    ByRef riid As Guid,   ' GUID*
    ppv As IntPtr   ' void** optional, out
) As Integer
End Function
' d3d12Device : ID3D12Device*
' flags : DML_CREATE_DEVICE_FLAGS
' riid : GUID*
' ppv : void** optional, out
Declare PtrSafe Function DMLCreateDevice Lib "directml" ( _
    ByVal d3d12Device As LongPtr, _
    ByVal flags As Long, _
    ByVal riid As LongPtr, _
    ByVal ppv As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DMLCreateDevice = ctypes.windll.directml.DMLCreateDevice
DMLCreateDevice.restype = ctypes.c_int
DMLCreateDevice.argtypes = [
    ctypes.c_void_p,  # d3d12Device : ID3D12Device*
    ctypes.c_int,  # flags : DML_CREATE_DEVICE_FLAGS
    ctypes.c_void_p,  # riid : GUID*
    ctypes.c_void_p,  # ppv : void** optional, out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DirectML.dll')
DMLCreateDevice = Fiddle::Function.new(
  lib['DMLCreateDevice'],
  [
    Fiddle::TYPE_VOIDP,  # d3d12Device : ID3D12Device*
    Fiddle::TYPE_INT,  # flags : DML_CREATE_DEVICE_FLAGS
    Fiddle::TYPE_VOIDP,  # riid : GUID*
    Fiddle::TYPE_VOIDP,  # ppv : void** optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "directml")]
extern "system" {
    fn DMLCreateDevice(
        d3d12Device: *mut core::ffi::c_void,  // ID3D12Device*
        flags: i32,  // DML_CREATE_DEVICE_FLAGS
        riid: *const GUID,  // GUID*
        ppv: *mut *mut ()  // void** optional, out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DirectML.dll")]
public static extern int DMLCreateDevice(IntPtr d3d12Device, int flags, ref Guid riid, IntPtr ppv);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DirectML_DMLCreateDevice' -Namespace Win32 -PassThru
# $api::DMLCreateDevice(d3d12Device, flags, riid, ppv)
#uselib "DirectML.dll"
#func global DMLCreateDevice "DMLCreateDevice" sptr, sptr, sptr, sptr
; DMLCreateDevice d3d12Device, flags, varptr(riid), ppv   ; 戻り値は stat
; d3d12Device : ID3D12Device* -> "sptr"
; flags : DML_CREATE_DEVICE_FLAGS -> "sptr"
; riid : GUID* -> "sptr"
; ppv : void** optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "DirectML.dll"
#cfunc global DMLCreateDevice "DMLCreateDevice" sptr, int, var, sptr
; res = DMLCreateDevice(d3d12Device, flags, riid, ppv)
; d3d12Device : ID3D12Device* -> "sptr"
; flags : DML_CREATE_DEVICE_FLAGS -> "int"
; riid : GUID* -> "var"
; ppv : void** optional, out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT DMLCreateDevice(ID3D12Device* d3d12Device, DML_CREATE_DEVICE_FLAGS flags, GUID* riid, void** ppv)
#uselib "DirectML.dll"
#cfunc global DMLCreateDevice "DMLCreateDevice" intptr, int, var, intptr
; res = DMLCreateDevice(d3d12Device, flags, riid, ppv)
; d3d12Device : ID3D12Device* -> "intptr"
; flags : DML_CREATE_DEVICE_FLAGS -> "int"
; riid : GUID* -> "var"
; ppv : void** optional, out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	directml = windows.NewLazySystemDLL("DirectML.dll")
	procDMLCreateDevice = directml.NewProc("DMLCreateDevice")
)

// d3d12Device (ID3D12Device*), flags (DML_CREATE_DEVICE_FLAGS), riid (GUID*), ppv (void** optional, out)
r1, _, err := procDMLCreateDevice.Call(
	uintptr(d3d12Device),
	uintptr(flags),
	uintptr(riid),
	uintptr(ppv),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function DMLCreateDevice(
  d3d12Device: Pointer;   // ID3D12Device*
  flags: Integer;   // DML_CREATE_DEVICE_FLAGS
  riid: PGUID;   // GUID*
  ppv: Pointer   // void** optional, out
): Integer; stdcall;
  external 'DirectML.dll' name 'DMLCreateDevice';
result := DllCall("DirectML\DMLCreateDevice"
    , "Ptr", d3d12Device   ; ID3D12Device*
    , "Int", flags   ; DML_CREATE_DEVICE_FLAGS
    , "Ptr", riid   ; GUID*
    , "Ptr", ppv   ; void** optional, out
    , "Int")   ; return: HRESULT
●DMLCreateDevice(d3d12Device, flags, riid, ppv) = DLL("DirectML.dll", "int DMLCreateDevice(void*, int, void*, void*)")
# 呼び出し: DMLCreateDevice(d3d12Device, flags, riid, ppv)
# d3d12Device : ID3D12Device* -> "void*"
# flags : DML_CREATE_DEVICE_FLAGS -> "int"
# riid : GUID* -> "void*"
# ppv : void** optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。