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
creationPropertiesD2D1_CREATION_PROPERTIES*inoptional
d2dDeviceContextID2D1DeviceContext**out

戻り値の型: 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)。