ホーム › Graphics.GdiPlus › GdipCreateFontFromLogfontW
GdipCreateFontFromLogfontW
関数LOGFONT構造体からフォントオブジェクトを作成する(Unicode版)。
シグネチャ
// gdiplus.dll (Unicode / -W)
#include <windows.h>
Status GdipCreateFontFromLogfontW(
HDC hdc,
const LOGFONTW* logfont,
GpFont** font
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | 解像度の基準とするデバイスコンテキストハンドル(HDC)。 |
| logfont | LOGFONTW* | in | フォント属性を定義するLOGFONTW構造体(Unicode)へのポインタ。 |
| font | GpFont** | inout | 生成したGpFontオブジェクトを受け取るポインタのポインタ(出力)。 |
戻り値の型: Status
各言語での呼び出し定義
// gdiplus.dll (Unicode / -W)
#include <windows.h>
Status GdipCreateFontFromLogfontW(
HDC hdc,
const LOGFONTW* logfont,
GpFont** font
);[DllImport("gdiplus.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int GdipCreateFontFromLogfontW(
IntPtr hdc, // HDC
IntPtr logfont, // LOGFONTW*
IntPtr font // GpFont** in/out
);<DllImport("gdiplus.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GdipCreateFontFromLogfontW(
hdc As IntPtr, ' HDC
logfont As IntPtr, ' LOGFONTW*
font As IntPtr ' GpFont** in/out
) As Integer
End Function' hdc : HDC
' logfont : LOGFONTW*
' font : GpFont** in/out
Declare PtrSafe Function GdipCreateFontFromLogfontW Lib "gdiplus" ( _
ByVal hdc As LongPtr, _
ByVal logfont As LongPtr, _
ByVal font As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GdipCreateFontFromLogfontW = ctypes.windll.gdiplus.GdipCreateFontFromLogfontW
GdipCreateFontFromLogfontW.restype = ctypes.c_int
GdipCreateFontFromLogfontW.argtypes = [
wintypes.HANDLE, # hdc : HDC
ctypes.c_void_p, # logfont : LOGFONTW*
ctypes.c_void_p, # font : GpFont** in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('gdiplus.dll')
GdipCreateFontFromLogfontW = Fiddle::Function.new(
lib['GdipCreateFontFromLogfontW'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_VOIDP, # logfont : LOGFONTW*
Fiddle::TYPE_VOIDP, # font : GpFont** in/out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "gdiplus")]
extern "system" {
fn GdipCreateFontFromLogfontW(
hdc: *mut core::ffi::c_void, // HDC
logfont: *const LOGFONTW, // LOGFONTW*
font: *mut *mut GpFont // GpFont** in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("gdiplus.dll", CharSet = CharSet.Unicode)]
public static extern int GdipCreateFontFromLogfontW(IntPtr hdc, IntPtr logfont, IntPtr font);
"@
$api = Add-Type -MemberDefinition $sig -Name 'gdiplus_GdipCreateFontFromLogfontW' -Namespace Win32 -PassThru
# $api::GdipCreateFontFromLogfontW(hdc, logfont, font)#uselib "gdiplus.dll"
#func global GdipCreateFontFromLogfontW "GdipCreateFontFromLogfontW" wptr, wptr, wptr
; GdipCreateFontFromLogfontW hdc, varptr(logfont), varptr(font) ; 戻り値は stat
; hdc : HDC -> "wptr"
; logfont : LOGFONTW* -> "wptr"
; font : GpFont** in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "gdiplus.dll" #cfunc global GdipCreateFontFromLogfontW "GdipCreateFontFromLogfontW" sptr, var, var ; res = GdipCreateFontFromLogfontW(hdc, logfont, font) ; hdc : HDC -> "sptr" ; logfont : LOGFONTW* -> "var" ; font : GpFont** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "gdiplus.dll" #cfunc global GdipCreateFontFromLogfontW "GdipCreateFontFromLogfontW" sptr, sptr, sptr ; res = GdipCreateFontFromLogfontW(hdc, varptr(logfont), varptr(font)) ; hdc : HDC -> "sptr" ; logfont : LOGFONTW* -> "sptr" ; font : GpFont** in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; Status GdipCreateFontFromLogfontW(HDC hdc, LOGFONTW* logfont, GpFont** font) #uselib "gdiplus.dll" #cfunc global GdipCreateFontFromLogfontW "GdipCreateFontFromLogfontW" intptr, var, var ; res = GdipCreateFontFromLogfontW(hdc, logfont, font) ; hdc : HDC -> "intptr" ; logfont : LOGFONTW* -> "var" ; font : GpFont** in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; Status GdipCreateFontFromLogfontW(HDC hdc, LOGFONTW* logfont, GpFont** font) #uselib "gdiplus.dll" #cfunc global GdipCreateFontFromLogfontW "GdipCreateFontFromLogfontW" intptr, intptr, intptr ; res = GdipCreateFontFromLogfontW(hdc, varptr(logfont), varptr(font)) ; hdc : HDC -> "intptr" ; logfont : LOGFONTW* -> "intptr" ; font : GpFont** in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
procGdipCreateFontFromLogfontW = gdiplus.NewProc("GdipCreateFontFromLogfontW")
)
// hdc (HDC), logfont (LOGFONTW*), font (GpFont** in/out)
r1, _, err := procGdipCreateFontFromLogfontW.Call(
uintptr(hdc),
uintptr(logfont),
uintptr(font),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // Statusfunction GdipCreateFontFromLogfontW(
hdc: THandle; // HDC
logfont: Pointer; // LOGFONTW*
font: Pointer // GpFont** in/out
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipCreateFontFromLogfontW';result := DllCall("gdiplus\GdipCreateFontFromLogfontW"
, "Ptr", hdc ; HDC
, "Ptr", logfont ; LOGFONTW*
, "Ptr", font ; GpFont** in/out
, "Int") ; return: Status●GdipCreateFontFromLogfontW(hdc, logfont, font) = DLL("gdiplus.dll", "int GdipCreateFontFromLogfontW(void*, void*, void*)")
# 呼び出し: GdipCreateFontFromLogfontW(hdc, logfont, font)
# hdc : HDC -> "void*"
# logfont : LOGFONTW* -> "void*"
# font : GpFont** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "gdiplus" fn GdipCreateFontFromLogfontW(
hdc: ?*anyopaque, // HDC
logfont: [*c]LOGFONTW, // LOGFONTW*
font: [*c][*c]GpFont // GpFont** in/out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc GdipCreateFontFromLogfontW(
hdc: pointer, # HDC
logfont: ptr LOGFONTW, # LOGFONTW*
font: ptr GpFont # GpFont** in/out
): int32 {.importc: "GdipCreateFontFromLogfontW", stdcall, dynlib: "gdiplus.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "gdiplus");
extern(Windows)
int GdipCreateFontFromLogfontW(
void* hdc, // HDC
LOGFONTW* logfont, // LOGFONTW*
GpFont** font // GpFont** in/out
);ccall((:GdipCreateFontFromLogfontW, "gdiplus.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{LOGFONTW}, Ptr{GpFont}),
hdc, logfont, font)
# hdc : HDC -> Ptr{Cvoid}
# logfont : LOGFONTW* -> Ptr{LOGFONTW}
# font : GpFont** in/out -> Ptr{GpFont}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t GdipCreateFontFromLogfontW(
void* hdc,
void* logfont,
void* font);
]]
local gdiplus = ffi.load("gdiplus")
-- gdiplus.GdipCreateFontFromLogfontW(hdc, logfont, font)
-- hdc : HDC
-- logfont : LOGFONTW*
-- font : GpFont** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('gdiplus.dll');
const GdipCreateFontFromLogfontW = lib.func('__stdcall', 'GdipCreateFontFromLogfontW', 'int32_t', ['void *', 'void *', 'void *']);
// GdipCreateFontFromLogfontW(hdc, logfont, font)
// hdc : HDC -> 'void *'
// logfont : LOGFONTW* -> 'void *'
// font : GpFont** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("gdiplus.dll", {
GdipCreateFontFromLogfontW: { parameters: ["pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.GdipCreateFontFromLogfontW(hdc, logfont, font)
// hdc : HDC -> "pointer"
// logfont : LOGFONTW* -> "pointer"
// font : GpFont** in/out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GdipCreateFontFromLogfontW(
void* hdc,
void* logfont,
void* font);
C, "gdiplus.dll");
// $ffi->GdipCreateFontFromLogfontW(hdc, logfont, font);
// hdc : HDC
// logfont : LOGFONTW*
// font : GpFont** 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, W32APIOptions.UNICODE_OPTIONS);
int GdipCreateFontFromLogfontW(
Pointer hdc, // HDC
Pointer logfont, // LOGFONTW*
Pointer font // GpFont** in/out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("gdiplus")]
lib Libgdiplus
fun GdipCreateFontFromLogfontW = GdipCreateFontFromLogfontW(
hdc : Void*, # HDC
logfont : LOGFONTW*, # LOGFONTW*
font : GpFont** # GpFont** 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 GdipCreateFontFromLogfontWNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef GdipCreateFontFromLogfontWDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>);
final GdipCreateFontFromLogfontW = DynamicLibrary.open('gdiplus.dll')
.lookupFunction<GdipCreateFontFromLogfontWNative, GdipCreateFontFromLogfontWDart>('GdipCreateFontFromLogfontW');
// hdc : HDC -> Pointer<Void>
// logfont : LOGFONTW* -> Pointer<Void>
// font : GpFont** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GdipCreateFontFromLogfontW(
hdc: THandle; // HDC
logfont: Pointer; // LOGFONTW*
font: Pointer // GpFont** in/out
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipCreateFontFromLogfontW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GdipCreateFontFromLogfontW"
c_GdipCreateFontFromLogfontW :: Ptr () -> Ptr () -> Ptr () -> IO Int32
-- hdc : HDC -> Ptr ()
-- logfont : LOGFONTW* -> Ptr ()
-- font : GpFont** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gdipcreatefontfromlogfontw =
foreign "GdipCreateFontFromLogfontW"
((ptr void) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* logfont : LOGFONTW* -> (ptr void) *)
(* font : GpFont** 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 ("GdipCreateFontFromLogfontW" gdip-create-font-from-logfont-w :convention :stdcall) :int32
(hdc :pointer) ; HDC
(logfont :pointer) ; LOGFONTW*
(font :pointer)) ; GpFont** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GdipCreateFontFromLogfontW = Win32::API::More->new('gdiplus',
'int GdipCreateFontFromLogfontW(HANDLE hdc, LPVOID logfont, LPVOID font)');
# my $ret = $GdipCreateFontFromLogfontW->Call($hdc, $logfont, $font);
# hdc : HDC -> HANDLE
# logfont : LOGFONTW* -> LPVOID
# font : GpFont** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f GdipCreateFontFromLogfontA (ANSI版) — LOGFONT構造体からフォントオブジェクトを作成する(ANSI版)。