ホーム › Graphics.GdiPlus › GdipCreatePen2
GdipCreatePen2
関数指定したブラシ・幅・単位で線描画用のペンを新規作成する。
シグネチャ
// gdiplus.dll
#include <windows.h>
Status GdipCreatePen2(
GpBrush* brush,
FLOAT width,
Unit unit,
GpPen** pen
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| brush | GpBrush* | inout | ペンの塗りに使うブラシへのポインタ。 |
| width | FLOAT | in | ペンの線幅をunit単位で指定するFLOAT。 |
| unit | Unit | in | widthの測定単位を示すUnit列挙値。 |
| pen | GpPen** | inout | 生成されたペンオブジェクトを受け取るGpPen**。 |
戻り値の型: Status
各言語での呼び出し定義
// gdiplus.dll
#include <windows.h>
Status GdipCreatePen2(
GpBrush* brush,
FLOAT width,
Unit unit,
GpPen** pen
);[DllImport("gdiplus.dll", ExactSpelling = true)]
static extern int GdipCreatePen2(
IntPtr brush, // GpBrush* in/out
float width, // FLOAT
int unit, // Unit
IntPtr pen // GpPen** in/out
);<DllImport("gdiplus.dll", ExactSpelling:=True)>
Public Shared Function GdipCreatePen2(
brush As IntPtr, ' GpBrush* in/out
width As Single, ' FLOAT
unit As Integer, ' Unit
pen As IntPtr ' GpPen** in/out
) As Integer
End Function' brush : GpBrush* in/out
' width : FLOAT
' unit : Unit
' pen : GpPen** in/out
Declare PtrSafe Function GdipCreatePen2 Lib "gdiplus" ( _
ByVal brush As LongPtr, _
ByVal width As Single, _
ByVal unit As Long, _
ByVal pen As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GdipCreatePen2 = ctypes.windll.gdiplus.GdipCreatePen2
GdipCreatePen2.restype = ctypes.c_int
GdipCreatePen2.argtypes = [
ctypes.c_void_p, # brush : GpBrush* in/out
ctypes.c_float, # width : FLOAT
ctypes.c_int, # unit : Unit
ctypes.c_void_p, # pen : GpPen** in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('gdiplus.dll')
GdipCreatePen2 = Fiddle::Function.new(
lib['GdipCreatePen2'],
[
Fiddle::TYPE_VOIDP, # brush : GpBrush* in/out
Fiddle::TYPE_FLOAT, # width : FLOAT
Fiddle::TYPE_INT, # unit : Unit
Fiddle::TYPE_VOIDP, # pen : GpPen** in/out
],
Fiddle::TYPE_INT)#[link(name = "gdiplus")]
extern "system" {
fn GdipCreatePen2(
brush: *mut GpBrush, // GpBrush* in/out
width: f32, // FLOAT
unit: i32, // Unit
pen: *mut *mut GpPen // GpPen** in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("gdiplus.dll")]
public static extern int GdipCreatePen2(IntPtr brush, float width, int unit, IntPtr pen);
"@
$api = Add-Type -MemberDefinition $sig -Name 'gdiplus_GdipCreatePen2' -Namespace Win32 -PassThru
# $api::GdipCreatePen2(brush, width, unit, pen)#uselib "gdiplus.dll"
#func global GdipCreatePen2 "GdipCreatePen2" sptr, float, sptr, sptr
; GdipCreatePen2 varptr(brush), width, unit, varptr(pen) ; 戻り値は stat
; brush : GpBrush* in/out -> "sptr"
; width : FLOAT -> "float"
; unit : Unit -> "sptr"
; pen : GpPen** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "gdiplus.dll" #cfunc global GdipCreatePen2 "GdipCreatePen2" var, float, int, var ; res = GdipCreatePen2(brush, width, unit, pen) ; brush : GpBrush* in/out -> "var" ; width : FLOAT -> "float" ; unit : Unit -> "int" ; pen : GpPen** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "gdiplus.dll" #cfunc global GdipCreatePen2 "GdipCreatePen2" sptr, float, int, sptr ; res = GdipCreatePen2(varptr(brush), width, unit, varptr(pen)) ; brush : GpBrush* in/out -> "sptr" ; width : FLOAT -> "float" ; unit : Unit -> "int" ; pen : GpPen** in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; Status GdipCreatePen2(GpBrush* brush, FLOAT width, Unit unit, GpPen** pen) #uselib "gdiplus.dll" #cfunc global GdipCreatePen2 "GdipCreatePen2" var, float, int, var ; res = GdipCreatePen2(brush, width, unit, pen) ; brush : GpBrush* in/out -> "var" ; width : FLOAT -> "float" ; unit : Unit -> "int" ; pen : GpPen** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; Status GdipCreatePen2(GpBrush* brush, FLOAT width, Unit unit, GpPen** pen) #uselib "gdiplus.dll" #cfunc global GdipCreatePen2 "GdipCreatePen2" intptr, float, int, intptr ; res = GdipCreatePen2(varptr(brush), width, unit, varptr(pen)) ; brush : GpBrush* in/out -> "intptr" ; width : FLOAT -> "float" ; unit : Unit -> "int" ; pen : GpPen** in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"math"
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
procGdipCreatePen2 = gdiplus.NewProc("GdipCreatePen2")
)
// brush (GpBrush* in/out), width (FLOAT), unit (Unit), pen (GpPen** in/out)
r1, _, err := procGdipCreatePen2.Call(
uintptr(brush),
uintptr(math.Float32bits(width)),
uintptr(unit),
uintptr(pen),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // Status
// 注意: float/double 引数は proc.Call では XMM レジスタに渡せません。
// windows.SyscallN(proc.Addr(), math.Float64bits(x), ...) もしくは cgo を使用してください。function GdipCreatePen2(
brush: Pointer; // GpBrush* in/out
width: Single; // FLOAT
unit: Integer; // Unit
pen: Pointer // GpPen** in/out
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipCreatePen2';result := DllCall("gdiplus\GdipCreatePen2"
, "Ptr", brush ; GpBrush* in/out
, "Float", width ; FLOAT
, "Int", unit ; Unit
, "Ptr", pen ; GpPen** in/out
, "Int") ; return: Status●GdipCreatePen2(brush, width, unit, pen) = DLL("gdiplus.dll", "int GdipCreatePen2(void*, float, int, void*)")
# 呼び出し: GdipCreatePen2(brush, width, unit, pen)
# brush : GpBrush* in/out -> "void*"
# width : FLOAT -> "float"
# unit : Unit -> "int"
# pen : GpPen** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdiplus" fn GdipCreatePen2(
brush: [*c]GpBrush, // GpBrush* in/out
width: f32, // FLOAT
unit: i32, // Unit
pen: [*c][*c]GpPen // GpPen** in/out
) callconv(std.os.windows.WINAPI) i32;proc GdipCreatePen2(
brush: ptr GpBrush, # GpBrush* in/out
width: float32, # FLOAT
unit: int32, # Unit
pen: ptr GpPen # GpPen** in/out
): int32 {.importc: "GdipCreatePen2", stdcall, dynlib: "gdiplus.dll".}pragma(lib, "gdiplus");
extern(Windows)
int GdipCreatePen2(
GpBrush* brush, // GpBrush* in/out
float width, // FLOAT
int unit, // Unit
GpPen** pen // GpPen** in/out
);ccall((:GdipCreatePen2, "gdiplus.dll"), stdcall, Int32,
(Ptr{GpBrush}, Float32, Int32, Ptr{GpPen}),
brush, width, unit, pen)
# brush : GpBrush* in/out -> Ptr{GpBrush}
# width : FLOAT -> Float32
# unit : Unit -> Int32
# pen : GpPen** in/out -> Ptr{GpPen}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GdipCreatePen2(
void* brush,
float width,
int32_t unit,
void* pen);
]]
local gdiplus = ffi.load("gdiplus")
-- gdiplus.GdipCreatePen2(brush, width, unit, pen)
-- brush : GpBrush* in/out
-- width : FLOAT
-- unit : Unit
-- pen : GpPen** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('gdiplus.dll');
const GdipCreatePen2 = lib.func('__stdcall', 'GdipCreatePen2', 'int32_t', ['void *', 'float', 'int32_t', 'void *']);
// GdipCreatePen2(brush, width, unit, pen)
// brush : GpBrush* in/out -> 'void *'
// width : FLOAT -> 'float'
// unit : Unit -> 'int32_t'
// pen : GpPen** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("gdiplus.dll", {
GdipCreatePen2: { parameters: ["pointer", "f32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.GdipCreatePen2(brush, width, unit, pen)
// brush : GpBrush* in/out -> "pointer"
// width : FLOAT -> "f32"
// unit : Unit -> "i32"
// pen : GpPen** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GdipCreatePen2(
void* brush,
float width,
int32_t unit,
void* pen);
C, "gdiplus.dll");
// $ffi->GdipCreatePen2(brush, width, unit, pen);
// brush : GpBrush* in/out
// width : FLOAT
// unit : Unit
// pen : GpPen** in/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 Gdiplus extends StdCallLibrary {
Gdiplus INSTANCE = Native.load("gdiplus", Gdiplus.class);
int GdipCreatePen2(
Pointer brush, // GpBrush* in/out
float width, // FLOAT
int unit, // Unit
Pointer pen // GpPen** in/out
);
}@[Link("gdiplus")]
lib Libgdiplus
fun GdipCreatePen2 = GdipCreatePen2(
brush : GpBrush*, # GpBrush* in/out
width : Float32, # FLOAT
unit : Int32, # Unit
pen : GpPen** # GpPen** in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GdipCreatePen2Native = Int32 Function(Pointer<Void>, Float, Int32, Pointer<Void>);
typedef GdipCreatePen2Dart = int Function(Pointer<Void>, double, int, Pointer<Void>);
final GdipCreatePen2 = DynamicLibrary.open('gdiplus.dll')
.lookupFunction<GdipCreatePen2Native, GdipCreatePen2Dart>('GdipCreatePen2');
// brush : GpBrush* in/out -> Pointer<Void>
// width : FLOAT -> Float
// unit : Unit -> Int32
// pen : GpPen** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GdipCreatePen2(
brush: Pointer; // GpBrush* in/out
width: Single; // FLOAT
unit: Integer; // Unit
pen: Pointer // GpPen** in/out
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipCreatePen2';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GdipCreatePen2"
c_GdipCreatePen2 :: Ptr () -> CFloat -> Int32 -> Ptr () -> IO Int32
-- brush : GpBrush* in/out -> Ptr ()
-- width : FLOAT -> CFloat
-- unit : Unit -> Int32
-- pen : GpPen** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gdipcreatepen2 =
foreign "GdipCreatePen2"
((ptr void) @-> float @-> int32_t @-> (ptr void) @-> returning int32_t)
(* brush : GpBrush* in/out -> (ptr void) *)
(* width : FLOAT -> float *)
(* unit : Unit -> int32_t *)
(* pen : GpPen** in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdiplus (t "gdiplus.dll"))
(cffi:use-foreign-library gdiplus)
(cffi:defcfun ("GdipCreatePen2" gdip-create-pen2 :convention :stdcall) :int32
(brush :pointer) ; GpBrush* in/out
(width :float) ; FLOAT
(unit :int32) ; Unit
(pen :pointer)) ; GpPen** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GdipCreatePen2 = Win32::API::More->new('gdiplus',
'int GdipCreatePen2(LPVOID brush, float width, int unit, LPVOID pen)');
# my $ret = $GdipCreatePen2->Call($brush, $width, $unit, $pen);
# brush : GpBrush* in/out -> LPVOID
# width : FLOAT -> float
# unit : Unit -> int
# pen : GpPen** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f GdipCreatePen1 — 指定した色・幅・単位で線描画用のペンを新規作成する。