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

D2D1CreateFactory

関数
Direct2Dファクトリオブジェクトを生成する。
DLLd2d1.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

HRESULT D2D1CreateFactory(
    D2D1_FACTORY_TYPE factoryType,
    const GUID* riid,
    const D2D1_FACTORY_OPTIONS* pFactoryOptions,   // optional
    void** ppIFactory
);

パラメーター

名前方向
factoryTypeD2D1_FACTORY_TYPEin
riidGUID*in
pFactoryOptionsD2D1_FACTORY_OPTIONS*inoptional
ppIFactoryvoid**out

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

D2D1CreateFactory = ctypes.windll.d2d1.D2D1CreateFactory
D2D1CreateFactory.restype = ctypes.c_int
D2D1CreateFactory.argtypes = [
    ctypes.c_int,  # factoryType : D2D1_FACTORY_TYPE
    ctypes.c_void_p,  # riid : GUID*
    ctypes.c_void_p,  # pFactoryOptions : D2D1_FACTORY_OPTIONS* optional
    ctypes.c_void_p,  # ppIFactory : void** out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	d2d1 = windows.NewLazySystemDLL("d2d1.dll")
	procD2D1CreateFactory = d2d1.NewProc("D2D1CreateFactory")
)

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