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

ExtTextOutA

関数
矩形や文字間隔を指定して文字列を描画する(ANSI版)。
DLLGDI32.dll文字セットANSI (-A)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// GDI32.dll  (ANSI / -A)
#include <windows.h>

BOOL ExtTextOutA(
    HDC hdc,
    INT x,
    INT y,
    ETO_OPTIONS options,
    const RECT* lprect,   // optional
    LPCSTR lpString,   // optional
    DWORD c,
    const INT* lpDx   // optional
);

パラメーター

名前方向説明
hdcHDCinデバイスコンテキストへのハンドル。
xINTin文字列の位置決めに使用される基準点の x 座標(論理座標)。
yINTin文字列の位置決めに使用される基準点の y 座標(論理座標)。
optionsETO_OPTIONSin

アプリケーション定義の四角形をどのように使用するかを指定します。このパラメーターには、次の値のうち 1 つ以上を指定できます。

意味
ETO_CLIPPED
テキストは四角形にクリッピングされます。
ETO_GLYPH_INDEX
lpString 配列は GetCharacterPlacement から返された配列を指しており、それ以上の言語固有の処理は不要であるため、GDI によって直接解析されます。グリフインデックス指定は TrueType フォントにのみ適用されますが、このフラグはビットマップフォントやベクターフォントに対しても使用でき、それ以上の言語処理が不要で GDI が文字列を直接処理すべきであることを示します。なお、ラスターフォントの場合、文字列は 8 ビット値の配列とみなされますが、すべてのグリフインデックスは 16 ビット値である点に注意してください。

ExtTextOutW の場合、グリフインデックスはメタファイルに保存されます。ただし、正しい文字を表示するには、同じフォントを使用してメタファイルを再生する必要があります。ExtTextOutA の場合、グリフインデックスは保存されません。

ETO_IGNORELANGUAGE
システム用に予約されています。アプリケーションがこのフラグを設定すると、国際的なスクリプトのサポートが失われ、場合によってはテキストがまったく表示されないことがあります。
ETO_NUMERICSLATIN
数字の表示にヨーロッパ数字を使用します。
ETO_NUMERICSLOCAL
数字の表示にロケールに応じた数字を使用します。
ETO_OPAQUE
現在の背景色を使用して四角形を塗りつぶします。
ETO_PDY
これが設定されている場合、lpDx が指す配列には値のペアが格納されます。各ペアの最初の値は通常どおり隣接する文字セルの原点間の距離ですが、2 番目の値はフォントの垂直方向への変位です。
ETO_RTLREADING
中東言語版の Windows: この値が指定され、ヘブライ語またはアラビア語のフォントがデバイスコンテキストに選択されている場合、文字列は右から左への読み順で出力されます。この値が指定されていない場合、文字列は左から右への順序で出力されます。同じ効果は、SetTextAlignTA_RTLREADING 値を設定することでも得られます。この値は下位互換性のために維持されています。

ETO_GLYPH_INDEXETO_RTLREADING の値を同時に使用することはできません。ETO_GLYPH_INDEX はすべての言語処理が完了していることを意味するため、ETO_RTLREADING フラグも併せて指定されている場合、関数はそれを無視します。

lprectRECT*inoptionalクリッピング、不透明化、またはその両方に使用される四角形の寸法(論理座標)を指定する、任意の RECT 構造体へのポインター。
lpStringLPCSTRinoptional描画するテキストを指定する文字列へのポインター。cbCount が文字列の長さを指定するため、文字列はゼロ終端である必要はありません。
cDWORDin

lpString が指す文字列の長さ

この値は 8192 を超えることはできません。

lpDxINT*inoptional隣接する文字セルの原点間の距離を示す、任意の値の配列へのポインター。たとえば、lpDx[i] 論理単位は、文字セル i と文字セル i + 1 の原点を隔てます。

戻り値の型: BOOL

公式ドキュメント

ExtTextOut 関数は、現在選択されているフォント、背景色、テキスト色を使用してテキストを描画します。クリッピング、不透明化、またはその両方に使用する寸法を任意で指定できます。(ANSI)

戻り値

文字列が描画された場合、戻り値は 0 以外です。ただし、ANSI 版の ExtTextOutETO_GLYPH_INDEX を指定して呼び出された場合、関数は何も行いませんが TRUE を返します。

関数が失敗した場合、戻り値は 0 です。

解説(Remarks)

指定されたデバイスコンテキストの現在のテキスト配置設定によって、基準点をテキストの位置決めにどのように使用するかが決まります。テキスト配置設定は GetTextAlign 関数を呼び出して取得します。テキスト配置設定は SetTextAlign 関数を呼び出して変更します。テキスト配置には次の値を使用できます。水平方向および垂直方向の配置に影響を与えるフラグのうち、選択できるのはそれぞれ 1 つだけです。さらに、現在位置を変更する 2 つのフラグのうち、選択できるのは 1 つだけです。

用語 説明
TA_BASELINE 基準点はテキストのベースライン上に置かれます。
TA_BOTTOM 基準点は外接四角形の下端に置かれます。
TA_TOP 基準点は外接四角形の上端に置かれます。
TA_CENTER 基準点は外接四角形の中央に水平方向で揃えられます。
TA_LEFT 基準点は外接四角形の左端に置かれます。
TA_RIGHT 基準点は外接四角形の右端に置かれます。
TA_NOUPDATECP 各テキスト出力呼び出しの後に現在位置は更新されません。基準点はテキスト出力関数に渡されます。
TA_RTLREADING 中東言語版の Windows: テキストは既定の左から右への順序ではなく、右から左への読み順でレイアウトされます。これは、デバイスコンテキストに選択されたフォントがヘブライ語またはアラビア語の場合にのみ適用されます。
TA_UPDATECP 各テキスト出力呼び出しの後に現在位置が更新されます。現在位置が基準点として使用されます。

lpDx パラメーターが NULL の場合、ExtTextOut 関数は文字間の既定の間隔を使用します。文字セルの原点と lpDx パラメーターが指す配列の内容は、論理単位で指定されます。文字セルの原点は、文字セルの左上隅として定義されます。

既定では、現在位置はこの関数によって使用も更新もされません。ただし、アプリケーションは fMode パラメーターを TA_UPDATECP に設定して SetTextAlign 関数を呼び出すことで、指定されたデバイスコンテキストに対してアプリケーションが ExtTextOut を呼び出すたびに、システムが現在位置を使用および更新することを許可できます。このフラグが設定されている場合、システムは以降の ExtTextOut 呼び出しで X および Y パラメーターを無視します。

ANSI 版の ExtTextOut では、lpDx 配列には lpString 内のバイト数と同じ数の INT 値が含まれます。DBCS 文字の場合、2 バイトの合計が目的の dx になる限り、lpDx エントリの dx を先行バイトと後続バイトの間で按分できます。Unicode 版の ExtTextOut で DBCS 文字を扱う場合、各 Unicode グリフは単一の pdx エントリを取得します。

なお、GetTextExtentExPointalpDx 値は、ExtTextOutlpDx 値とは同じではありません。alpDx 値を lpDx で使用するには、まずそれらを処理する必要があります。

ExtTextOut は必要に応じて Uniscribe を使用し、その結果フォントフォールバックが行われます。ETO_IGNORELANGUAGE フラグはこの動作を抑制するため、渡すべきではありません。

さらに、ExtTextOut はカーネルモードに移行する前に呼び出しの内部バッチ処理を行い、PolyTextOutExtTextOut の使用を比較検討する際のパフォーマンス上の懸念の一部を軽減します。

ヒント

ExtTextOut は、異なる言語の表示を処理できる能力があるため、現代の開発では PolyTextOut よりも強く推奨されます。

例については、メニューの使用の「メニュー項目のテキスト文字列にフォントを設定する」を参照してください。

メモ

wingdi.h ヘッダーは ExtTextOut を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、コンパイルエラーまたは実行時エラーを引き起こす不一致につながる可能性があります。詳細については、関数プロトタイプの規則を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// GDI32.dll  (ANSI / -A)
#include <windows.h>

BOOL ExtTextOutA(
    HDC hdc,
    INT x,
    INT y,
    ETO_OPTIONS options,
    const RECT* lprect,   // optional
    LPCSTR lpString,   // optional
    DWORD c,
    const INT* lpDx   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool ExtTextOutA(
    IntPtr hdc,   // HDC
    int x,   // INT
    int y,   // INT
    uint options,   // ETO_OPTIONS
    IntPtr lprect,   // RECT* optional
    [MarshalAs(UnmanagedType.LPStr)] string lpString,   // LPCSTR optional
    uint c,   // DWORD
    IntPtr lpDx   // INT* optional
);
<DllImport("GDI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function ExtTextOutA(
    hdc As IntPtr,   ' HDC
    x As Integer,   ' INT
    y As Integer,   ' INT
    options As UInteger,   ' ETO_OPTIONS
    lprect As IntPtr,   ' RECT* optional
    <MarshalAs(UnmanagedType.LPStr)> lpString As String,   ' LPCSTR optional
    c As UInteger,   ' DWORD
    lpDx As IntPtr   ' INT* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hdc : HDC
' x : INT
' y : INT
' options : ETO_OPTIONS
' lprect : RECT* optional
' lpString : LPCSTR optional
' c : DWORD
' lpDx : INT* optional
Declare PtrSafe Function ExtTextOutA Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal x As Long, _
    ByVal y As Long, _
    ByVal options As Long, _
    ByVal lprect As LongPtr, _
    ByVal lpString As String, _
    ByVal c As Long, _
    ByVal lpDx As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ExtTextOutA = ctypes.windll.gdi32.ExtTextOutA
ExtTextOutA.restype = wintypes.BOOL
ExtTextOutA.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # x : INT
    ctypes.c_int,  # y : INT
    wintypes.DWORD,  # options : ETO_OPTIONS
    ctypes.c_void_p,  # lprect : RECT* optional
    wintypes.LPCSTR,  # lpString : LPCSTR optional
    wintypes.DWORD,  # c : DWORD
    ctypes.POINTER(ctypes.c_int),  # lpDx : INT* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
ExtTextOutA = Fiddle::Function.new(
  lib['ExtTextOutA'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # x : INT
    Fiddle::TYPE_INT,  # y : INT
    -Fiddle::TYPE_INT,  # options : ETO_OPTIONS
    Fiddle::TYPE_VOIDP,  # lprect : RECT* optional
    Fiddle::TYPE_VOIDP,  # lpString : LPCSTR optional
    -Fiddle::TYPE_INT,  # c : DWORD
    Fiddle::TYPE_VOIDP,  # lpDx : INT* optional
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn ExtTextOutA(
        hdc: *mut core::ffi::c_void,  // HDC
        x: i32,  // INT
        y: i32,  // INT
        options: u32,  // ETO_OPTIONS
        lprect: *const RECT,  // RECT* optional
        lpString: *const u8,  // LPCSTR optional
        c: u32,  // DWORD
        lpDx: *const i32  // INT* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Ansi)]
public static extern bool ExtTextOutA(IntPtr hdc, int x, int y, uint options, IntPtr lprect, [MarshalAs(UnmanagedType.LPStr)] string lpString, uint c, IntPtr lpDx);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_ExtTextOutA' -Namespace Win32 -PassThru
# $api::ExtTextOutA(hdc, x, y, options, lprect, lpString, c, lpDx)
#uselib "GDI32.dll"
#func global ExtTextOutA "ExtTextOutA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ExtTextOutA hdc, x, y, options, varptr(lprect), lpString, c, varptr(lpDx)   ; 戻り値は stat
; hdc : HDC -> "sptr"
; x : INT -> "sptr"
; y : INT -> "sptr"
; options : ETO_OPTIONS -> "sptr"
; lprect : RECT* optional -> "sptr"
; lpString : LPCSTR optional -> "sptr"
; c : DWORD -> "sptr"
; lpDx : INT* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global ExtTextOutA "ExtTextOutA" sptr, int, int, int, var, str, int, var
; res = ExtTextOutA(hdc, x, y, options, lprect, lpString, c, lpDx)
; hdc : HDC -> "sptr"
; x : INT -> "int"
; y : INT -> "int"
; options : ETO_OPTIONS -> "int"
; lprect : RECT* optional -> "var"
; lpString : LPCSTR optional -> "str"
; c : DWORD -> "int"
; lpDx : INT* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL ExtTextOutA(HDC hdc, INT x, INT y, ETO_OPTIONS options, RECT* lprect, LPCSTR lpString, DWORD c, INT* lpDx)
#uselib "GDI32.dll"
#cfunc global ExtTextOutA "ExtTextOutA" intptr, int, int, int, var, str, int, var
; res = ExtTextOutA(hdc, x, y, options, lprect, lpString, c, lpDx)
; hdc : HDC -> "intptr"
; x : INT -> "int"
; y : INT -> "int"
; options : ETO_OPTIONS -> "int"
; lprect : RECT* optional -> "var"
; lpString : LPCSTR optional -> "str"
; c : DWORD -> "int"
; lpDx : INT* optional -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procExtTextOutA = gdi32.NewProc("ExtTextOutA")
)

// hdc (HDC), x (INT), y (INT), options (ETO_OPTIONS), lprect (RECT* optional), lpString (LPCSTR optional), c (DWORD), lpDx (INT* optional)
r1, _, err := procExtTextOutA.Call(
	uintptr(hdc),
	uintptr(x),
	uintptr(y),
	uintptr(options),
	uintptr(lprect),
	uintptr(unsafe.Pointer(windows.BytePtrFromString(lpString))),
	uintptr(c),
	uintptr(lpDx),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function ExtTextOutA(
  hdc: THandle;   // HDC
  x: Integer;   // INT
  y: Integer;   // INT
  options: DWORD;   // ETO_OPTIONS
  lprect: Pointer;   // RECT* optional
  lpString: PAnsiChar;   // LPCSTR optional
  c: DWORD;   // DWORD
  lpDx: Pointer   // INT* optional
): BOOL; stdcall;
  external 'GDI32.dll' name 'ExtTextOutA';
result := DllCall("GDI32\ExtTextOutA"
    , "Ptr", hdc   ; HDC
    , "Int", x   ; INT
    , "Int", y   ; INT
    , "UInt", options   ; ETO_OPTIONS
    , "Ptr", lprect   ; RECT* optional
    , "AStr", lpString   ; LPCSTR optional
    , "UInt", c   ; DWORD
    , "Ptr", lpDx   ; INT* optional
    , "Int")   ; return: BOOL
●ExtTextOutA(hdc, x, y, options, lprect, lpString, c, lpDx) = DLL("GDI32.dll", "bool ExtTextOutA(void*, int, int, dword, void*, char*, dword, void*)")
# 呼び出し: ExtTextOutA(hdc, x, y, options, lprect, lpString, c, lpDx)
# hdc : HDC -> "void*"
# x : INT -> "int"
# y : INT -> "int"
# options : ETO_OPTIONS -> "dword"
# lprect : RECT* optional -> "void*"
# lpString : LPCSTR optional -> "char*"
# c : DWORD -> "dword"
# lpDx : INT* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "gdi32" fn ExtTextOutA(
    hdc: ?*anyopaque, // HDC
    x: i32, // INT
    y: i32, // INT
    options: u32, // ETO_OPTIONS
    lprect: [*c]RECT, // RECT* optional
    lpString: [*c]const u8, // LPCSTR optional
    c: u32, // DWORD
    lpDx: [*c]i32 // INT* optional
) callconv(std.os.windows.WINAPI) i32;
proc ExtTextOutA(
    hdc: pointer,  # HDC
    x: int32,  # INT
    y: int32,  # INT
    options: uint32,  # ETO_OPTIONS
    lprect: ptr RECT,  # RECT* optional
    lpString: cstring,  # LPCSTR optional
    c: uint32,  # DWORD
    lpDx: ptr int32  # INT* optional
): int32 {.importc: "ExtTextOutA", stdcall, dynlib: "GDI32.dll".}
pragma(lib, "gdi32");
extern(Windows)
int ExtTextOutA(
    void* hdc,   // HDC
    int x,   // INT
    int y,   // INT
    uint options,   // ETO_OPTIONS
    RECT* lprect,   // RECT* optional
    const(char)* lpString,   // LPCSTR optional
    uint c,   // DWORD
    int* lpDx   // INT* optional
);
ccall((:ExtTextOutA, "GDI32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Int32, UInt32, Ptr{RECT}, Cstring, UInt32, Ptr{Int32}),
      hdc, x, y, options, lprect, lpString, c, lpDx)
# hdc : HDC -> Ptr{Cvoid}
# x : INT -> Int32
# y : INT -> Int32
# options : ETO_OPTIONS -> UInt32
# lprect : RECT* optional -> Ptr{RECT}
# lpString : LPCSTR optional -> Cstring
# c : DWORD -> UInt32
# lpDx : INT* optional -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ExtTextOutA(
    void* hdc,
    int32_t x,
    int32_t y,
    uint32_t options,
    void* lprect,
    const char* lpString,
    uint32_t c,
    int32_t* lpDx);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.ExtTextOutA(hdc, x, y, options, lprect, lpString, c, lpDx)
-- hdc : HDC
-- x : INT
-- y : INT
-- options : ETO_OPTIONS
-- lprect : RECT* optional
-- lpString : LPCSTR optional
-- c : DWORD
-- lpDx : INT* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const ExtTextOutA = lib.func('__stdcall', 'ExtTextOutA', 'int32_t', ['void *', 'int32_t', 'int32_t', 'uint32_t', 'void *', 'str', 'uint32_t', 'int32_t *']);
// ExtTextOutA(hdc, x, y, options, lprect, lpString, c, lpDx)
// hdc : HDC -> 'void *'
// x : INT -> 'int32_t'
// y : INT -> 'int32_t'
// options : ETO_OPTIONS -> 'uint32_t'
// lprect : RECT* optional -> 'void *'
// lpString : LPCSTR optional -> 'str'
// c : DWORD -> 'uint32_t'
// lpDx : INT* optional -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  ExtTextOutA: { parameters: ["pointer", "i32", "i32", "u32", "pointer", "buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.ExtTextOutA(hdc, x, y, options, lprect, lpString, c, lpDx)
// hdc : HDC -> "pointer"
// x : INT -> "i32"
// y : INT -> "i32"
// options : ETO_OPTIONS -> "u32"
// lprect : RECT* optional -> "pointer"
// lpString : LPCSTR optional -> "buffer"
// c : DWORD -> "u32"
// lpDx : INT* optional -> "pointer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ExtTextOutA(
    void* hdc,
    int32_t x,
    int32_t y,
    uint32_t options,
    void* lprect,
    const char* lpString,
    uint32_t c,
    int32_t* lpDx);
C, "GDI32.dll");
// $ffi->ExtTextOutA(hdc, x, y, options, lprect, lpString, c, lpDx);
// hdc : HDC
// x : INT
// y : INT
// options : ETO_OPTIONS
// lprect : RECT* optional
// lpString : LPCSTR optional
// c : DWORD
// lpDx : INT* optional
// 構造体/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 Gdi32 extends StdCallLibrary {
    Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class, W32APIOptions.ASCII_OPTIONS);
    boolean ExtTextOutA(
        Pointer hdc,   // HDC
        int x,   // INT
        int y,   // INT
        int options,   // ETO_OPTIONS
        Pointer lprect,   // RECT* optional
        String lpString,   // LPCSTR optional
        int c,   // DWORD
        IntByReference lpDx   // INT* optional
    );
}
@[Link("gdi32")]
lib LibGDI32
  fun ExtTextOutA = ExtTextOutA(
    hdc : Void*,   # HDC
    x : Int32,   # INT
    y : Int32,   # INT
    options : UInt32,   # ETO_OPTIONS
    lprect : RECT*,   # RECT* optional
    lpString : UInt8*,   # LPCSTR optional
    c : UInt32,   # DWORD
    lpDx : Int32*   # INT* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ExtTextOutANative = Int32 Function(Pointer<Void>, Int32, Int32, Uint32, Pointer<Void>, Pointer<Utf8>, Uint32, Pointer<Int32>);
typedef ExtTextOutADart = int Function(Pointer<Void>, int, int, int, Pointer<Void>, Pointer<Utf8>, int, Pointer<Int32>);
final ExtTextOutA = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<ExtTextOutANative, ExtTextOutADart>('ExtTextOutA');
// hdc : HDC -> Pointer<Void>
// x : INT -> Int32
// y : INT -> Int32
// options : ETO_OPTIONS -> Uint32
// lprect : RECT* optional -> Pointer<Void>
// lpString : LPCSTR optional -> Pointer<Utf8>
// c : DWORD -> Uint32
// lpDx : INT* optional -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ExtTextOutA(
  hdc: THandle;   // HDC
  x: Integer;   // INT
  y: Integer;   // INT
  options: DWORD;   // ETO_OPTIONS
  lprect: Pointer;   // RECT* optional
  lpString: PAnsiChar;   // LPCSTR optional
  c: DWORD;   // DWORD
  lpDx: Pointer   // INT* optional
): BOOL; stdcall;
  external 'GDI32.dll' name 'ExtTextOutA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ExtTextOutA"
  c_ExtTextOutA :: Ptr () -> Int32 -> Int32 -> Word32 -> Ptr () -> CString -> Word32 -> Ptr Int32 -> IO CInt
-- hdc : HDC -> Ptr ()
-- x : INT -> Int32
-- y : INT -> Int32
-- options : ETO_OPTIONS -> Word32
-- lprect : RECT* optional -> Ptr ()
-- lpString : LPCSTR optional -> CString
-- c : DWORD -> Word32
-- lpDx : INT* optional -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let exttextouta =
  foreign "ExtTextOutA"
    ((ptr void) @-> int32_t @-> int32_t @-> uint32_t @-> (ptr void) @-> string @-> uint32_t @-> (ptr int32_t) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* x : INT -> int32_t *)
(* y : INT -> int32_t *)
(* options : ETO_OPTIONS -> uint32_t *)
(* lprect : RECT* optional -> (ptr void) *)
(* lpString : LPCSTR optional -> string *)
(* c : DWORD -> uint32_t *)
(* lpDx : INT* optional -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("ExtTextOutA" ext-text-out-a :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (x :int32)   ; INT
  (y :int32)   ; INT
  (options :uint32)   ; ETO_OPTIONS
  (lprect :pointer)   ; RECT* optional
  (lp-string :string)   ; LPCSTR optional
  (c :uint32)   ; DWORD
  (lp-dx :pointer))   ; INT* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ExtTextOutA = Win32::API::More->new('GDI32',
    'BOOL ExtTextOutA(HANDLE hdc, int x, int y, DWORD options, LPVOID lprect, LPCSTR lpString, DWORD c, LPVOID lpDx)');
# my $ret = $ExtTextOutA->Call($hdc, $x, $y, $options, $lprect, $lpString, $c, $lpDx);
# hdc : HDC -> HANDLE
# x : INT -> int
# y : INT -> int
# options : ETO_OPTIONS -> DWORD
# lprect : RECT* optional -> LPVOID
# lpString : LPCSTR optional -> LPCSTR
# c : DWORD -> DWORD
# lpDx : INT* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目
使用する型