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

D2D1CreateDeviceContext

関数
DXGIサーフェスからデバイスコンテキストを生成する。
DLLd2d1.dll呼出規約winapi対応OSwindows8.0

シグネチャ

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

HRESULT D2D1CreateDeviceContext(
    IDXGISurface* dxgiSurface,
    const D2D1_CREATION_PROPERTIES* creationProperties,   // optional
    ID2D1DeviceContext** d2dDeviceContext
);

パラメーター

名前方向説明
dxgiSurfaceIDXGISurface*in描画先となるIDXGISurfaceへのポインター。
creationPropertiesD2D1_CREATION_PROPERTIES*inoptionalデバッグレベルやスレッドモデルを指定するD2D1_CREATION_PROPERTIESへのポインター。NULL可。
d2dDeviceContextID2D1DeviceContext**out生成されたID2D1DeviceContextを受け取る出力ポインター。

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

D2D1CreateDeviceContext = ctypes.windll.d2d1.D2D1CreateDeviceContext
D2D1CreateDeviceContext.restype = ctypes.c_int
D2D1CreateDeviceContext.argtypes = [
    ctypes.c_void_p,  # dxgiSurface : IDXGISurface*
    ctypes.c_void_p,  # creationProperties : D2D1_CREATION_PROPERTIES* optional
    ctypes.c_void_p,  # d2dDeviceContext : ID2D1DeviceContext** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	d2d1 = windows.NewLazySystemDLL("d2d1.dll")
	procD2D1CreateDeviceContext = d2d1.NewProc("D2D1CreateDeviceContext")
)

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

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

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

foreign import stdcall safe "D2D1CreateDeviceContext"
  c_D2D1CreateDeviceContext :: Ptr () -> Ptr () -> Ptr () -> IO Int32
-- dxgiSurface : IDXGISurface* -> Ptr ()
-- creationProperties : D2D1_CREATION_PROPERTIES* optional -> Ptr ()
-- d2dDeviceContext : ID2D1DeviceContext** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let d2d1createdevicecontext =
  foreign "D2D1CreateDeviceContext"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* dxgiSurface : IDXGISurface* -> (ptr void) *)
(* creationProperties : D2D1_CREATION_PROPERTIES* optional -> (ptr void) *)
(* d2dDeviceContext : ID2D1DeviceContext** 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 ("D2D1CreateDeviceContext" d2-d1-create-device-context :convention :stdcall) :int32
  (dxgi-surface :pointer)   ; IDXGISurface*
  (creation-properties :pointer)   ; D2D1_CREATION_PROPERTIES* optional
  (d2d-device-context :pointer))   ; ID2D1DeviceContext** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $D2D1CreateDeviceContext = Win32::API::More->new('d2d1',
    'int D2D1CreateDeviceContext(LPVOID dxgiSurface, LPVOID creationProperties, LPVOID d2dDeviceContext)');
# my $ret = $D2D1CreateDeviceContext->Call($dxgiSurface, $creationProperties, $d2dDeviceContext);
# dxgiSurface : IDXGISurface* -> LPVOID
# creationProperties : D2D1_CREATION_PROPERTIES* optional -> LPVOID
# d2dDeviceContext : ID2D1DeviceContext** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型