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生成するファクトリのスレッドモデル(単一/マルチ)を示すD2D1_FACTORY_TYPE。
riidGUID*in要求するID2D1Factory系インターフェイスのGUIDへのポインター。
pFactoryOptionsD2D1_FACTORY_OPTIONS*inoptionalデバッグレベル等を指定するD2D1_FACTORY_OPTIONSへのポインター。NULL可。
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)。
const std = @import("std");

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

typedef D2D1CreateFactoryNative = Int32 Function(Int32, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef D2D1CreateFactoryDart = int Function(int, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final D2D1CreateFactory = DynamicLibrary.open('d2d1.dll')
    .lookupFunction<D2D1CreateFactoryNative, D2D1CreateFactoryDart>('D2D1CreateFactory');
// factoryType : D2D1_FACTORY_TYPE -> Int32
// riid : GUID* -> Pointer<Void>
// pFactoryOptions : D2D1_FACTORY_OPTIONS* optional -> Pointer<Void>
// ppIFactory : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "D2D1CreateFactory"
  c_D2D1CreateFactory :: Int32 -> Ptr () -> Ptr () -> Ptr () -> IO Int32
-- factoryType : D2D1_FACTORY_TYPE -> Int32
-- riid : GUID* -> Ptr ()
-- pFactoryOptions : D2D1_FACTORY_OPTIONS* optional -> Ptr ()
-- ppIFactory : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let d2d1createfactory =
  foreign "D2D1CreateFactory"
    (int32_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* factoryType : D2D1_FACTORY_TYPE -> int32_t *)
(* riid : GUID* -> (ptr void) *)
(* pFactoryOptions : D2D1_FACTORY_OPTIONS* optional -> (ptr void) *)
(* ppIFactory : void** 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 ("D2D1CreateFactory" d2-d1-create-factory :convention :stdcall) :int32
  (factory-type :int32)   ; D2D1_FACTORY_TYPE
  (riid :pointer)   ; GUID*
  (p-factory-options :pointer)   ; D2D1_FACTORY_OPTIONS* optional
  (pp-ifactory :pointer))   ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $D2D1CreateFactory = Win32::API::More->new('d2d1',
    'int D2D1CreateFactory(int factoryType, LPVOID riid, LPVOID pFactoryOptions, LPVOID ppIFactory)');
# my $ret = $D2D1CreateFactory->Call($factoryType, $riid, $pFactoryOptions, $ppIFactory);
# factoryType : D2D1_FACTORY_TYPE -> int
# riid : GUID* -> LPVOID
# pFactoryOptions : D2D1_FACTORY_OPTIONS* optional -> LPVOID
# ppIFactory : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型