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

D2D1CreateDevice

関数
DXGIデバイスからDirect2Dデバイスを生成する。
DLLd2d1.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT D2D1CreateDevice(
    IDXGIDevice* dxgiDevice,
    const D2D1_CREATION_PROPERTIES* creationProperties,   // optional
    ID2D1Device** d2dDevice
);

パラメーター

名前方向説明
dxgiDeviceIDXGIDevice*inDirect2Dデバイスの基盤となるIDXGIDeviceへのポインター。
creationPropertiesD2D1_CREATION_PROPERTIES*inoptionalデバッグレベルやスレッドモデルを指定するD2D1_CREATION_PROPERTIESへのポインター。NULL可。
d2dDeviceID2D1Device**out生成されたID2D1Deviceを受け取る出力ポインター。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT D2D1CreateDevice(
    IDXGIDevice* dxgiDevice,
    const D2D1_CREATION_PROPERTIES* creationProperties,   // optional
    ID2D1Device** d2dDevice
);
[DllImport("d2d1.dll", ExactSpelling = true)]
static extern int D2D1CreateDevice(
    IntPtr dxgiDevice,   // IDXGIDevice*
    IntPtr creationProperties,   // D2D1_CREATION_PROPERTIES* optional
    IntPtr d2dDevice   // ID2D1Device** out
);
<DllImport("d2d1.dll", ExactSpelling:=True)>
Public Shared Function D2D1CreateDevice(
    dxgiDevice As IntPtr,   ' IDXGIDevice*
    creationProperties As IntPtr,   ' D2D1_CREATION_PROPERTIES* optional
    d2dDevice As IntPtr   ' ID2D1Device** out
) As Integer
End Function
' dxgiDevice : IDXGIDevice*
' creationProperties : D2D1_CREATION_PROPERTIES* optional
' d2dDevice : ID2D1Device** out
Declare PtrSafe Function D2D1CreateDevice Lib "d2d1" ( _
    ByVal dxgiDevice As LongPtr, _
    ByVal creationProperties As LongPtr, _
    ByVal d2dDevice As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

D2D1CreateDevice = ctypes.windll.d2d1.D2D1CreateDevice
D2D1CreateDevice.restype = ctypes.c_int
D2D1CreateDevice.argtypes = [
    ctypes.c_void_p,  # dxgiDevice : IDXGIDevice*
    ctypes.c_void_p,  # creationProperties : D2D1_CREATION_PROPERTIES* optional
    ctypes.c_void_p,  # d2dDevice : ID2D1Device** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	d2d1 = windows.NewLazySystemDLL("d2d1.dll")
	procD2D1CreateDevice = d2d1.NewProc("D2D1CreateDevice")
)

// dxgiDevice (IDXGIDevice*), creationProperties (D2D1_CREATION_PROPERTIES* optional), d2dDevice (ID2D1Device** out)
r1, _, err := procD2D1CreateDevice.Call(
	uintptr(dxgiDevice),
	uintptr(creationProperties),
	uintptr(d2dDevice),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function D2D1CreateDevice(
  dxgiDevice: Pointer;   // IDXGIDevice*
  creationProperties: Pointer;   // D2D1_CREATION_PROPERTIES* optional
  d2dDevice: Pointer   // ID2D1Device** out
): Integer; stdcall;
  external 'd2d1.dll' name 'D2D1CreateDevice';
result := DllCall("d2d1\D2D1CreateDevice"
    , "Ptr", dxgiDevice   ; IDXGIDevice*
    , "Ptr", creationProperties   ; D2D1_CREATION_PROPERTIES* optional
    , "Ptr", d2dDevice   ; ID2D1Device** out
    , "Int")   ; return: HRESULT
●D2D1CreateDevice(dxgiDevice, creationProperties, d2dDevice) = DLL("d2d1.dll", "int D2D1CreateDevice(void*, void*, void*)")
# 呼び出し: D2D1CreateDevice(dxgiDevice, creationProperties, d2dDevice)
# dxgiDevice : IDXGIDevice* -> "void*"
# creationProperties : D2D1_CREATION_PROPERTIES* optional -> "void*"
# d2dDevice : ID2D1Device** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "d2d1" fn D2D1CreateDevice(
    dxgiDevice: ?*anyopaque, // IDXGIDevice*
    creationProperties: [*c]D2D1_CREATION_PROPERTIES, // D2D1_CREATION_PROPERTIES* optional
    d2dDevice: ?*anyopaque // ID2D1Device** out
) callconv(std.os.windows.WINAPI) i32;
proc D2D1CreateDevice(
    dxgiDevice: pointer,  # IDXGIDevice*
    creationProperties: ptr D2D1_CREATION_PROPERTIES,  # D2D1_CREATION_PROPERTIES* optional
    d2dDevice: pointer  # ID2D1Device** out
): int32 {.importc: "D2D1CreateDevice", stdcall, dynlib: "d2d1.dll".}
pragma(lib, "d2d1");
extern(Windows)
int D2D1CreateDevice(
    void* dxgiDevice,   // IDXGIDevice*
    D2D1_CREATION_PROPERTIES* creationProperties,   // D2D1_CREATION_PROPERTIES* optional
    void* d2dDevice   // ID2D1Device** out
);
ccall((:D2D1CreateDevice, "d2d1.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{D2D1_CREATION_PROPERTIES}, Ptr{Cvoid}),
      dxgiDevice, creationProperties, d2dDevice)
# dxgiDevice : IDXGIDevice* -> Ptr{Cvoid}
# creationProperties : D2D1_CREATION_PROPERTIES* optional -> Ptr{D2D1_CREATION_PROPERTIES}
# d2dDevice : ID2D1Device** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t D2D1CreateDevice(
    void* dxgiDevice,
    void* creationProperties,
    void* d2dDevice);
]]
local d2d1 = ffi.load("d2d1")
-- d2d1.D2D1CreateDevice(dxgiDevice, creationProperties, d2dDevice)
-- dxgiDevice : IDXGIDevice*
-- creationProperties : D2D1_CREATION_PROPERTIES* optional
-- d2dDevice : ID2D1Device** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('d2d1.dll');
const D2D1CreateDevice = lib.func('__stdcall', 'D2D1CreateDevice', 'int32_t', ['void *', 'void *', 'void *']);
// D2D1CreateDevice(dxgiDevice, creationProperties, d2dDevice)
// dxgiDevice : IDXGIDevice* -> 'void *'
// creationProperties : D2D1_CREATION_PROPERTIES* optional -> 'void *'
// d2dDevice : ID2D1Device** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("d2d1.dll", {
  D2D1CreateDevice: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.D2D1CreateDevice(dxgiDevice, creationProperties, d2dDevice)
// dxgiDevice : IDXGIDevice* -> "pointer"
// creationProperties : D2D1_CREATION_PROPERTIES* optional -> "pointer"
// d2dDevice : ID2D1Device** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t D2D1CreateDevice(
    void* dxgiDevice,
    void* creationProperties,
    void* d2dDevice);
C, "d2d1.dll");
// $ffi->D2D1CreateDevice(dxgiDevice, creationProperties, d2dDevice);
// dxgiDevice : IDXGIDevice*
// creationProperties : D2D1_CREATION_PROPERTIES* optional
// d2dDevice : ID2D1Device** 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 D2d1 extends StdCallLibrary {
    D2d1 INSTANCE = Native.load("d2d1", D2d1.class);
    int D2D1CreateDevice(
        Pointer dxgiDevice,   // IDXGIDevice*
        Pointer creationProperties,   // D2D1_CREATION_PROPERTIES* optional
        Pointer d2dDevice   // ID2D1Device** out
    );
}
@[Link("d2d1")]
lib Libd2d1
  fun D2D1CreateDevice = D2D1CreateDevice(
    dxgiDevice : Void*,   # IDXGIDevice*
    creationProperties : D2D1_CREATION_PROPERTIES*,   # D2D1_CREATION_PROPERTIES* optional
    d2dDevice : Void*   # ID2D1Device** out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef D2D1CreateDeviceNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef D2D1CreateDeviceDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
final D2D1CreateDevice = DynamicLibrary.open('d2d1.dll')
    .lookupFunction<D2D1CreateDeviceNative, D2D1CreateDeviceDart>('D2D1CreateDevice');
// dxgiDevice : IDXGIDevice* -> Pointer<Void>
// creationProperties : D2D1_CREATION_PROPERTIES* optional -> Pointer<Void>
// d2dDevice : ID2D1Device** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function D2D1CreateDevice(
  dxgiDevice: Pointer;   // IDXGIDevice*
  creationProperties: Pointer;   // D2D1_CREATION_PROPERTIES* optional
  d2dDevice: Pointer   // ID2D1Device** out
): Integer; stdcall;
  external 'd2d1.dll' name 'D2D1CreateDevice';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "D2D1CreateDevice"
  c_D2D1CreateDevice :: Ptr () -> Ptr () -> Ptr () -> IO Int32
-- dxgiDevice : IDXGIDevice* -> Ptr ()
-- creationProperties : D2D1_CREATION_PROPERTIES* optional -> Ptr ()
-- d2dDevice : ID2D1Device** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let d2d1createdevice =
  foreign "D2D1CreateDevice"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* dxgiDevice : IDXGIDevice* -> (ptr void) *)
(* creationProperties : D2D1_CREATION_PROPERTIES* optional -> (ptr void) *)
(* d2dDevice : ID2D1Device** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library d2d1 (t "d2d1.dll"))
(cffi:use-foreign-library d2d1)

(cffi:defcfun ("D2D1CreateDevice" d2-d1-create-device :convention :stdcall) :int32
  (dxgi-device :pointer)   ; IDXGIDevice*
  (creation-properties :pointer)   ; D2D1_CREATION_PROPERTIES* optional
  (d2d-device :pointer))   ; ID2D1Device** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $D2D1CreateDevice = Win32::API::More->new('d2d1',
    'int D2D1CreateDevice(LPVOID dxgiDevice, LPVOID creationProperties, LPVOID d2dDevice)');
# my $ret = $D2D1CreateDevice->Call($dxgiDevice, $creationProperties, $d2dDevice);
# dxgiDevice : IDXGIDevice* -> LPVOID
# creationProperties : D2D1_CREATION_PROPERTIES* optional -> LPVOID
# d2dDevice : ID2D1Device** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型