Win32 API 日本語リファレンス
ホームGlobalization › ScriptStringAnalyse

ScriptStringAnalyse

関数
文字列を解析し描画用の状態オブジェクトを生成する。
DLLUSP10.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

HRESULT ScriptStringAnalyse(
    HDC hdc,
    const void* pString,
    INT cString,
    INT cGlyphs,
    INT iCharset,
    DWORD dwFlags,
    INT iReqWidth,
    SCRIPT_CONTROL* psControl,   // optional
    SCRIPT_STATE* psState,   // optional
    const INT* piDx,   // optional
    SCRIPT_TABDEF* pTabdef,   // optional
    const BYTE* pbInClass,
    void** pssa
);

パラメーター

名前方向説明
hdcHDCinデバイスコンテキストへのハンドル。dwFlagsSSA_GLYPHS が設定されている場合、デバイスコンテキストハンドルは必須です。dwFlagsSSA_BREAK が設定されている場合、デバイスコンテキストハンドルは省略可能です。デバイスコンテキストハンドルが指定されている場合、この関数はデバイスコンテキスト内の現在のフォントを検査します。現在のフォントがシンボルフォントの場合、この関数は文字列を単一のニュートラルな SCRIPT_UNDEFINED 項目として扱います。
pStringvoid*in解析する文字列へのポインター。文字列には少なくとも 1 文字が含まれている必要があります。Unicode 文字列、または iCharset パラメーターで指定された Windows ANSI コードページ の文字セットを使用する文字列を指定できます。
cStringINTin解析する文字列の長さ。長さは、ANSI 文字列では文字単位、Unicode 文字列ではワイド文字単位で測定されます。長さは少なくとも 1 でなければなりません。
cGlyphsINTinグリフバッファーのサイズ(WORD 値単位)。このサイズは必須です。推奨サイズは (1.5 * cString + 16) です。
iCharsetINTin

文字セット記述子。入力文字列が ANSI 文字列の場合、この記述子には文字セット識別子が設定されます。文字列が Unicode 文字列の場合、この記述子には -1 が設定されます。

次の文字セット識別子が定義されています:

dwFlagsDWORDin

必要な解析を示すフラグ。このパラメーターには、次の表に示す値のいずれかを指定できます。

意味
SSA_BREAK
区切りフラグ(文字および単語の区切り)を取得します。
SSA_CLIP
文字列を iReqWidth でクリップします。
SSA_DZWG
制御文字に対する表現用グリフを提供します。
SSA_FALLBACK
フォールバックフォントを使用します。
SSA_FIT
文字列を iReqWidth に合わせて両端揃えします。
SSA_GCP
GetCharacterPlacement の規約に従って、不足しているグリフと pwLogClust を取得します。
SSA_GLYPHS
グリフ、位置、および属性を生成します。
SSA_HIDEHOTKEY
表示文字列から最初の "&" を削除します。
SSA_HOTKEY
"&" を、その後続のコードポイントへの下線に置き換えます。
SSA_HOTKEYONLY
下線のみを表示します。生成されたビットパターンは、XOR マスクを使用して表示することで、テキストを乱すことなくホットキー下線の表示/非表示を切り替えることができます。
SSA_LINK
非複合テキストに東アジアフォントのリンクおよび関連付けを適用します。
SSA_METAFILE
項目をグリフではなく ExtTextOutW 呼び出しで書き込みます。
SSA_PASSWORD
単一文字を含む入力文字列を cString 回複製します。
SSA_RTL
基底埋め込みレベル 1 を使用します。
SSA_TAB
タブを展開します。
iReqWidthINTinフィッティングまたはクリッピングに必要な幅。
psControlSCRIPT_CONTROL*inoptionalSCRIPT_CONTROL 構造体へのポインター。アプリケーションは、このパラメーターに NULL を設定することで、すべての SCRIPT_CONTROL メンバーを 0 に設定することを示すことができます。
psStateSCRIPT_STATE*inoptionalSCRIPT_STATE 構造体へのポインター。アプリケーションは、このパラメーターに NULL を設定することで、すべての SCRIPT_STATE メンバーを 0 に設定することを示すことができます。SCRIPT_STATEuBidiLevel メンバーは無視されます。使用される値は、SSA_RTL フラグとデバイスコンテキストのレイアウトの組み合わせから導出されます。
piDxINT*inoptional要求される論理 dx 配列へのポインター。
pTabdefSCRIPT_TABDEF*inoptionalSCRIPT_TABDEF 構造体へのポインター。この値は、dwFlagsSSA_TAB が設定されている場合にのみ必要です。
pbInClassBYTE*inGetCharacterPlacement の文字分類を示す BYTE 値へのポインター。
pssavoid**outこの関数が SCRIPT_STRING_ANALYSIS 構造体を取得するバッファーへのポインター。この構造体は、関数の正常な戻り時に動的に割り当てられます。

戻り値の型: HRESULT

公式ドキュメント

プレーンテキスト文字列を解析します。

戻り値

成功した場合は S_OK を返します。成功しなかった場合、この関数は 0 以外の HRESULT 値を返します。

エラーの戻り値には次のものが含まれます:

また、この関数はシステムエラーを HRESULT 型に変換して返す場合もあります。たとえば、メモリ不足やデバイスコンテキストを使用した GDI 呼び出しによって返されるエラーなどです。

解説(Remarks)

この関数の使用は、プレーンテキスト文字列を処理する際の最初のステップです。そのような文字列は、フォント、スタイル、サイズ、色などをそれぞれ 1 つだけ持ちます。ScriptStringAnalyse は、項目解析、グリフ、送り幅などのための一時バッファーを割り当てます。そして、ScriptItemizeScriptShapeScriptPlace、および ScriptBreak を自動的に実行します。結果は、他のすべての ScriptString* 関数を通じて利用できます。

この関数の正常な戻り時には、pssa は動的に割り当てられた構造体を指します。アプリケーションはこの構造体を他の ScriptString* 関数に順次渡すことができます。アプリケーションは最終的に、ScriptStringFree を呼び出してこの構造体を解放する必要があります。

ScriptStringAnalyse の機能は他の関数を直接呼び出すことで実装できますが、この関数自体を使用することで、プレーンテキスト処理のためにアプリケーションに必要なコード量を大幅に削減できます。

重要 Windows 8 以降: Windows 7 上で実行できる機能を維持するには、Uniscribe を使用するモジュールはライブラリリスト内で gdi32.lib より前に Usp10.lib を指定する必要があります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

HRESULT ScriptStringAnalyse(
    HDC hdc,
    const void* pString,
    INT cString,
    INT cGlyphs,
    INT iCharset,
    DWORD dwFlags,
    INT iReqWidth,
    SCRIPT_CONTROL* psControl,   // optional
    SCRIPT_STATE* psState,   // optional
    const INT* piDx,   // optional
    SCRIPT_TABDEF* pTabdef,   // optional
    const BYTE* pbInClass,
    void** pssa
);
[DllImport("USP10.dll", ExactSpelling = true)]
static extern int ScriptStringAnalyse(
    IntPtr hdc,   // HDC
    IntPtr pString,   // void*
    int cString,   // INT
    int cGlyphs,   // INT
    int iCharset,   // INT
    uint dwFlags,   // DWORD
    int iReqWidth,   // INT
    IntPtr psControl,   // SCRIPT_CONTROL* optional
    IntPtr psState,   // SCRIPT_STATE* optional
    IntPtr piDx,   // INT* optional
    IntPtr pTabdef,   // SCRIPT_TABDEF* optional
    IntPtr pbInClass,   // BYTE*
    IntPtr pssa   // void** out
);
<DllImport("USP10.dll", ExactSpelling:=True)>
Public Shared Function ScriptStringAnalyse(
    hdc As IntPtr,   ' HDC
    pString As IntPtr,   ' void*
    cString As Integer,   ' INT
    cGlyphs As Integer,   ' INT
    iCharset As Integer,   ' INT
    dwFlags As UInteger,   ' DWORD
    iReqWidth As Integer,   ' INT
    psControl As IntPtr,   ' SCRIPT_CONTROL* optional
    psState As IntPtr,   ' SCRIPT_STATE* optional
    piDx As IntPtr,   ' INT* optional
    pTabdef As IntPtr,   ' SCRIPT_TABDEF* optional
    pbInClass As IntPtr,   ' BYTE*
    pssa As IntPtr   ' void** out
) As Integer
End Function
' hdc : HDC
' pString : void*
' cString : INT
' cGlyphs : INT
' iCharset : INT
' dwFlags : DWORD
' iReqWidth : INT
' psControl : SCRIPT_CONTROL* optional
' psState : SCRIPT_STATE* optional
' piDx : INT* optional
' pTabdef : SCRIPT_TABDEF* optional
' pbInClass : BYTE*
' pssa : void** out
Declare PtrSafe Function ScriptStringAnalyse Lib "usp10" ( _
    ByVal hdc As LongPtr, _
    ByVal pString As LongPtr, _
    ByVal cString As Long, _
    ByVal cGlyphs As Long, _
    ByVal iCharset As Long, _
    ByVal dwFlags As Long, _
    ByVal iReqWidth As Long, _
    ByVal psControl As LongPtr, _
    ByVal psState As LongPtr, _
    ByVal piDx As LongPtr, _
    ByVal pTabdef As LongPtr, _
    ByVal pbInClass As LongPtr, _
    ByVal pssa As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ScriptStringAnalyse = ctypes.windll.usp10.ScriptStringAnalyse
ScriptStringAnalyse.restype = ctypes.c_int
ScriptStringAnalyse.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.POINTER(None),  # pString : void*
    ctypes.c_int,  # cString : INT
    ctypes.c_int,  # cGlyphs : INT
    ctypes.c_int,  # iCharset : INT
    wintypes.DWORD,  # dwFlags : DWORD
    ctypes.c_int,  # iReqWidth : INT
    ctypes.c_void_p,  # psControl : SCRIPT_CONTROL* optional
    ctypes.c_void_p,  # psState : SCRIPT_STATE* optional
    ctypes.POINTER(ctypes.c_int),  # piDx : INT* optional
    ctypes.c_void_p,  # pTabdef : SCRIPT_TABDEF* optional
    ctypes.POINTER(ctypes.c_ubyte),  # pbInClass : BYTE*
    ctypes.c_void_p,  # pssa : void** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('USP10.dll')
ScriptStringAnalyse = Fiddle::Function.new(
  lib['ScriptStringAnalyse'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # pString : void*
    Fiddle::TYPE_INT,  # cString : INT
    Fiddle::TYPE_INT,  # cGlyphs : INT
    Fiddle::TYPE_INT,  # iCharset : INT
    -Fiddle::TYPE_INT,  # dwFlags : DWORD
    Fiddle::TYPE_INT,  # iReqWidth : INT
    Fiddle::TYPE_VOIDP,  # psControl : SCRIPT_CONTROL* optional
    Fiddle::TYPE_VOIDP,  # psState : SCRIPT_STATE* optional
    Fiddle::TYPE_VOIDP,  # piDx : INT* optional
    Fiddle::TYPE_VOIDP,  # pTabdef : SCRIPT_TABDEF* optional
    Fiddle::TYPE_VOIDP,  # pbInClass : BYTE*
    Fiddle::TYPE_VOIDP,  # pssa : void** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "usp10")]
extern "system" {
    fn ScriptStringAnalyse(
        hdc: *mut core::ffi::c_void,  // HDC
        pString: *const (),  // void*
        cString: i32,  // INT
        cGlyphs: i32,  // INT
        iCharset: i32,  // INT
        dwFlags: u32,  // DWORD
        iReqWidth: i32,  // INT
        psControl: *mut SCRIPT_CONTROL,  // SCRIPT_CONTROL* optional
        psState: *mut SCRIPT_STATE,  // SCRIPT_STATE* optional
        piDx: *const i32,  // INT* optional
        pTabdef: *mut SCRIPT_TABDEF,  // SCRIPT_TABDEF* optional
        pbInClass: *const u8,  // BYTE*
        pssa: *mut *mut ()  // void** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("USP10.dll")]
public static extern int ScriptStringAnalyse(IntPtr hdc, IntPtr pString, int cString, int cGlyphs, int iCharset, uint dwFlags, int iReqWidth, IntPtr psControl, IntPtr psState, IntPtr piDx, IntPtr pTabdef, IntPtr pbInClass, IntPtr pssa);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USP10_ScriptStringAnalyse' -Namespace Win32 -PassThru
# $api::ScriptStringAnalyse(hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa)
#uselib "USP10.dll"
#func global ScriptStringAnalyse "ScriptStringAnalyse" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; ScriptStringAnalyse hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, varptr(psControl), varptr(psState), varptr(piDx), varptr(pTabdef), varptr(pbInClass), pssa   ; 戻り値は stat
; hdc : HDC -> "sptr"
; pString : void* -> "sptr"
; cString : INT -> "sptr"
; cGlyphs : INT -> "sptr"
; iCharset : INT -> "sptr"
; dwFlags : DWORD -> "sptr"
; iReqWidth : INT -> "sptr"
; psControl : SCRIPT_CONTROL* optional -> "sptr"
; psState : SCRIPT_STATE* optional -> "sptr"
; piDx : INT* optional -> "sptr"
; pTabdef : SCRIPT_TABDEF* optional -> "sptr"
; pbInClass : BYTE* -> "sptr"
; pssa : void** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "USP10.dll"
#cfunc global ScriptStringAnalyse "ScriptStringAnalyse" sptr, sptr, int, int, int, int, int, var, var, var, var, var, sptr
; res = ScriptStringAnalyse(hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa)
; hdc : HDC -> "sptr"
; pString : void* -> "sptr"
; cString : INT -> "int"
; cGlyphs : INT -> "int"
; iCharset : INT -> "int"
; dwFlags : DWORD -> "int"
; iReqWidth : INT -> "int"
; psControl : SCRIPT_CONTROL* optional -> "var"
; psState : SCRIPT_STATE* optional -> "var"
; piDx : INT* optional -> "var"
; pTabdef : SCRIPT_TABDEF* optional -> "var"
; pbInClass : BYTE* -> "var"
; pssa : void** out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT ScriptStringAnalyse(HDC hdc, void* pString, INT cString, INT cGlyphs, INT iCharset, DWORD dwFlags, INT iReqWidth, SCRIPT_CONTROL* psControl, SCRIPT_STATE* psState, INT* piDx, SCRIPT_TABDEF* pTabdef, BYTE* pbInClass, void** pssa)
#uselib "USP10.dll"
#cfunc global ScriptStringAnalyse "ScriptStringAnalyse" intptr, intptr, int, int, int, int, int, var, var, var, var, var, intptr
; res = ScriptStringAnalyse(hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa)
; hdc : HDC -> "intptr"
; pString : void* -> "intptr"
; cString : INT -> "int"
; cGlyphs : INT -> "int"
; iCharset : INT -> "int"
; dwFlags : DWORD -> "int"
; iReqWidth : INT -> "int"
; psControl : SCRIPT_CONTROL* optional -> "var"
; psState : SCRIPT_STATE* optional -> "var"
; piDx : INT* optional -> "var"
; pTabdef : SCRIPT_TABDEF* optional -> "var"
; pbInClass : BYTE* -> "var"
; pssa : void** out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	usp10 = windows.NewLazySystemDLL("USP10.dll")
	procScriptStringAnalyse = usp10.NewProc("ScriptStringAnalyse")
)

// hdc (HDC), pString (void*), cString (INT), cGlyphs (INT), iCharset (INT), dwFlags (DWORD), iReqWidth (INT), psControl (SCRIPT_CONTROL* optional), psState (SCRIPT_STATE* optional), piDx (INT* optional), pTabdef (SCRIPT_TABDEF* optional), pbInClass (BYTE*), pssa (void** out)
r1, _, err := procScriptStringAnalyse.Call(
	uintptr(hdc),
	uintptr(pString),
	uintptr(cString),
	uintptr(cGlyphs),
	uintptr(iCharset),
	uintptr(dwFlags),
	uintptr(iReqWidth),
	uintptr(psControl),
	uintptr(psState),
	uintptr(piDx),
	uintptr(pTabdef),
	uintptr(pbInClass),
	uintptr(pssa),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function ScriptStringAnalyse(
  hdc: THandle;   // HDC
  pString: Pointer;   // void*
  cString: Integer;   // INT
  cGlyphs: Integer;   // INT
  iCharset: Integer;   // INT
  dwFlags: DWORD;   // DWORD
  iReqWidth: Integer;   // INT
  psControl: Pointer;   // SCRIPT_CONTROL* optional
  psState: Pointer;   // SCRIPT_STATE* optional
  piDx: Pointer;   // INT* optional
  pTabdef: Pointer;   // SCRIPT_TABDEF* optional
  pbInClass: Pointer;   // BYTE*
  pssa: Pointer   // void** out
): Integer; stdcall;
  external 'USP10.dll' name 'ScriptStringAnalyse';
result := DllCall("USP10\ScriptStringAnalyse"
    , "Ptr", hdc   ; HDC
    , "Ptr", pString   ; void*
    , "Int", cString   ; INT
    , "Int", cGlyphs   ; INT
    , "Int", iCharset   ; INT
    , "UInt", dwFlags   ; DWORD
    , "Int", iReqWidth   ; INT
    , "Ptr", psControl   ; SCRIPT_CONTROL* optional
    , "Ptr", psState   ; SCRIPT_STATE* optional
    , "Ptr", piDx   ; INT* optional
    , "Ptr", pTabdef   ; SCRIPT_TABDEF* optional
    , "Ptr", pbInClass   ; BYTE*
    , "Ptr", pssa   ; void** out
    , "Int")   ; return: HRESULT
●ScriptStringAnalyse(hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa) = DLL("USP10.dll", "int ScriptStringAnalyse(void*, void*, int, int, int, dword, int, void*, void*, void*, void*, void*, void*)")
# 呼び出し: ScriptStringAnalyse(hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa)
# hdc : HDC -> "void*"
# pString : void* -> "void*"
# cString : INT -> "int"
# cGlyphs : INT -> "int"
# iCharset : INT -> "int"
# dwFlags : DWORD -> "dword"
# iReqWidth : INT -> "int"
# psControl : SCRIPT_CONTROL* optional -> "void*"
# psState : SCRIPT_STATE* optional -> "void*"
# piDx : INT* optional -> "void*"
# pTabdef : SCRIPT_TABDEF* optional -> "void*"
# pbInClass : BYTE* -> "void*"
# pssa : void** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "usp10" fn ScriptStringAnalyse(
    hdc: ?*anyopaque, // HDC
    pString: ?*anyopaque, // void*
    cString: i32, // INT
    cGlyphs: i32, // INT
    iCharset: i32, // INT
    dwFlags: u32, // DWORD
    iReqWidth: i32, // INT
    psControl: [*c]SCRIPT_CONTROL, // SCRIPT_CONTROL* optional
    psState: [*c]SCRIPT_STATE, // SCRIPT_STATE* optional
    piDx: [*c]i32, // INT* optional
    pTabdef: [*c]SCRIPT_TABDEF, // SCRIPT_TABDEF* optional
    pbInClass: [*c]u8, // BYTE*
    pssa: ?*anyopaque // void** out
) callconv(std.os.windows.WINAPI) i32;
proc ScriptStringAnalyse(
    hdc: pointer,  # HDC
    pString: pointer,  # void*
    cString: int32,  # INT
    cGlyphs: int32,  # INT
    iCharset: int32,  # INT
    dwFlags: uint32,  # DWORD
    iReqWidth: int32,  # INT
    psControl: ptr SCRIPT_CONTROL,  # SCRIPT_CONTROL* optional
    psState: ptr SCRIPT_STATE,  # SCRIPT_STATE* optional
    piDx: ptr int32,  # INT* optional
    pTabdef: ptr SCRIPT_TABDEF,  # SCRIPT_TABDEF* optional
    pbInClass: ptr uint8,  # BYTE*
    pssa: pointer  # void** out
): int32 {.importc: "ScriptStringAnalyse", stdcall, dynlib: "USP10.dll".}
pragma(lib, "usp10");
extern(Windows)
int ScriptStringAnalyse(
    void* hdc,   // HDC
    void* pString,   // void*
    int cString,   // INT
    int cGlyphs,   // INT
    int iCharset,   // INT
    uint dwFlags,   // DWORD
    int iReqWidth,   // INT
    SCRIPT_CONTROL* psControl,   // SCRIPT_CONTROL* optional
    SCRIPT_STATE* psState,   // SCRIPT_STATE* optional
    int* piDx,   // INT* optional
    SCRIPT_TABDEF* pTabdef,   // SCRIPT_TABDEF* optional
    ubyte* pbInClass,   // BYTE*
    void** pssa   // void** out
);
ccall((:ScriptStringAnalyse, "USP10.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{Cvoid}, Int32, Int32, Int32, UInt32, Int32, Ptr{SCRIPT_CONTROL}, Ptr{SCRIPT_STATE}, Ptr{Int32}, Ptr{SCRIPT_TABDEF}, Ptr{UInt8}, Ptr{Cvoid}),
      hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa)
# hdc : HDC -> Ptr{Cvoid}
# pString : void* -> Ptr{Cvoid}
# cString : INT -> Int32
# cGlyphs : INT -> Int32
# iCharset : INT -> Int32
# dwFlags : DWORD -> UInt32
# iReqWidth : INT -> Int32
# psControl : SCRIPT_CONTROL* optional -> Ptr{SCRIPT_CONTROL}
# psState : SCRIPT_STATE* optional -> Ptr{SCRIPT_STATE}
# piDx : INT* optional -> Ptr{Int32}
# pTabdef : SCRIPT_TABDEF* optional -> Ptr{SCRIPT_TABDEF}
# pbInClass : BYTE* -> Ptr{UInt8}
# pssa : void** out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t ScriptStringAnalyse(
    void* hdc,
    void* pString,
    int32_t cString,
    int32_t cGlyphs,
    int32_t iCharset,
    uint32_t dwFlags,
    int32_t iReqWidth,
    void* psControl,
    void* psState,
    int32_t* piDx,
    void* pTabdef,
    uint8_t* pbInClass,
    void** pssa);
]]
local usp10 = ffi.load("usp10")
-- usp10.ScriptStringAnalyse(hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa)
-- hdc : HDC
-- pString : void*
-- cString : INT
-- cGlyphs : INT
-- iCharset : INT
-- dwFlags : DWORD
-- iReqWidth : INT
-- psControl : SCRIPT_CONTROL* optional
-- psState : SCRIPT_STATE* optional
-- piDx : INT* optional
-- pTabdef : SCRIPT_TABDEF* optional
-- pbInClass : BYTE*
-- pssa : void** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('USP10.dll');
const ScriptStringAnalyse = lib.func('__stdcall', 'ScriptStringAnalyse', 'int32_t', ['void *', 'void *', 'int32_t', 'int32_t', 'int32_t', 'uint32_t', 'int32_t', 'void *', 'void *', 'int32_t *', 'void *', 'uint8_t *', 'void *']);
// ScriptStringAnalyse(hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa)
// hdc : HDC -> 'void *'
// pString : void* -> 'void *'
// cString : INT -> 'int32_t'
// cGlyphs : INT -> 'int32_t'
// iCharset : INT -> 'int32_t'
// dwFlags : DWORD -> 'uint32_t'
// iReqWidth : INT -> 'int32_t'
// psControl : SCRIPT_CONTROL* optional -> 'void *'
// psState : SCRIPT_STATE* optional -> 'void *'
// piDx : INT* optional -> 'int32_t *'
// pTabdef : SCRIPT_TABDEF* optional -> 'void *'
// pbInClass : BYTE* -> 'uint8_t *'
// pssa : void** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("USP10.dll", {
  ScriptStringAnalyse: { parameters: ["pointer", "pointer", "i32", "i32", "i32", "u32", "i32", "pointer", "pointer", "pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.ScriptStringAnalyse(hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa)
// hdc : HDC -> "pointer"
// pString : void* -> "pointer"
// cString : INT -> "i32"
// cGlyphs : INT -> "i32"
// iCharset : INT -> "i32"
// dwFlags : DWORD -> "u32"
// iReqWidth : INT -> "i32"
// psControl : SCRIPT_CONTROL* optional -> "pointer"
// psState : SCRIPT_STATE* optional -> "pointer"
// piDx : INT* optional -> "pointer"
// pTabdef : SCRIPT_TABDEF* optional -> "pointer"
// pbInClass : BYTE* -> "pointer"
// pssa : void** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t ScriptStringAnalyse(
    void* hdc,
    void* pString,
    int32_t cString,
    int32_t cGlyphs,
    int32_t iCharset,
    uint32_t dwFlags,
    int32_t iReqWidth,
    void* psControl,
    void* psState,
    int32_t* piDx,
    void* pTabdef,
    uint8_t* pbInClass,
    void** pssa);
C, "USP10.dll");
// $ffi->ScriptStringAnalyse(hdc, pString, cString, cGlyphs, iCharset, dwFlags, iReqWidth, psControl, psState, piDx, pTabdef, pbInClass, pssa);
// hdc : HDC
// pString : void*
// cString : INT
// cGlyphs : INT
// iCharset : INT
// dwFlags : DWORD
// iReqWidth : INT
// psControl : SCRIPT_CONTROL* optional
// psState : SCRIPT_STATE* optional
// piDx : INT* optional
// pTabdef : SCRIPT_TABDEF* optional
// pbInClass : BYTE*
// pssa : 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 Usp10 extends StdCallLibrary {
    Usp10 INSTANCE = Native.load("usp10", Usp10.class);
    int ScriptStringAnalyse(
        Pointer hdc,   // HDC
        Pointer pString,   // void*
        int cString,   // INT
        int cGlyphs,   // INT
        int iCharset,   // INT
        int dwFlags,   // DWORD
        int iReqWidth,   // INT
        Pointer psControl,   // SCRIPT_CONTROL* optional
        Pointer psState,   // SCRIPT_STATE* optional
        IntByReference piDx,   // INT* optional
        Pointer pTabdef,   // SCRIPT_TABDEF* optional
        byte[] pbInClass,   // BYTE*
        Pointer pssa   // void** out
    );
}
@[Link("usp10")]
lib LibUSP10
  fun ScriptStringAnalyse = ScriptStringAnalyse(
    hdc : Void*,   # HDC
    pString : Void*,   # void*
    cString : Int32,   # INT
    cGlyphs : Int32,   # INT
    iCharset : Int32,   # INT
    dwFlags : UInt32,   # DWORD
    iReqWidth : Int32,   # INT
    psControl : SCRIPT_CONTROL*,   # SCRIPT_CONTROL* optional
    psState : SCRIPT_STATE*,   # SCRIPT_STATE* optional
    piDx : Int32*,   # INT* optional
    pTabdef : SCRIPT_TABDEF*,   # SCRIPT_TABDEF* optional
    pbInClass : UInt8*,   # BYTE*
    pssa : 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 ScriptStringAnalyseNative = Int32 Function(Pointer<Void>, Pointer<Void>, Int32, Int32, Int32, Uint32, Int32, Pointer<Void>, Pointer<Void>, Pointer<Int32>, Pointer<Void>, Pointer<Uint8>, Pointer<Void>);
typedef ScriptStringAnalyseDart = int Function(Pointer<Void>, Pointer<Void>, int, int, int, int, int, Pointer<Void>, Pointer<Void>, Pointer<Int32>, Pointer<Void>, Pointer<Uint8>, Pointer<Void>);
final ScriptStringAnalyse = DynamicLibrary.open('USP10.dll')
    .lookupFunction<ScriptStringAnalyseNative, ScriptStringAnalyseDart>('ScriptStringAnalyse');
// hdc : HDC -> Pointer<Void>
// pString : void* -> Pointer<Void>
// cString : INT -> Int32
// cGlyphs : INT -> Int32
// iCharset : INT -> Int32
// dwFlags : DWORD -> Uint32
// iReqWidth : INT -> Int32
// psControl : SCRIPT_CONTROL* optional -> Pointer<Void>
// psState : SCRIPT_STATE* optional -> Pointer<Void>
// piDx : INT* optional -> Pointer<Int32>
// pTabdef : SCRIPT_TABDEF* optional -> Pointer<Void>
// pbInClass : BYTE* -> Pointer<Uint8>
// pssa : void** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ScriptStringAnalyse(
  hdc: THandle;   // HDC
  pString: Pointer;   // void*
  cString: Integer;   // INT
  cGlyphs: Integer;   // INT
  iCharset: Integer;   // INT
  dwFlags: DWORD;   // DWORD
  iReqWidth: Integer;   // INT
  psControl: Pointer;   // SCRIPT_CONTROL* optional
  psState: Pointer;   // SCRIPT_STATE* optional
  piDx: Pointer;   // INT* optional
  pTabdef: Pointer;   // SCRIPT_TABDEF* optional
  pbInClass: Pointer;   // BYTE*
  pssa: Pointer   // void** out
): Integer; stdcall;
  external 'USP10.dll' name 'ScriptStringAnalyse';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ScriptStringAnalyse"
  c_ScriptStringAnalyse :: Ptr () -> Ptr () -> Int32 -> Int32 -> Int32 -> Word32 -> Int32 -> Ptr () -> Ptr () -> Ptr Int32 -> Ptr () -> Ptr Word8 -> Ptr () -> IO Int32
-- hdc : HDC -> Ptr ()
-- pString : void* -> Ptr ()
-- cString : INT -> Int32
-- cGlyphs : INT -> Int32
-- iCharset : INT -> Int32
-- dwFlags : DWORD -> Word32
-- iReqWidth : INT -> Int32
-- psControl : SCRIPT_CONTROL* optional -> Ptr ()
-- psState : SCRIPT_STATE* optional -> Ptr ()
-- piDx : INT* optional -> Ptr Int32
-- pTabdef : SCRIPT_TABDEF* optional -> Ptr ()
-- pbInClass : BYTE* -> Ptr Word8
-- pssa : void** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let scriptstringanalyse =
  foreign "ScriptStringAnalyse"
    ((ptr void) @-> (ptr void) @-> int32_t @-> int32_t @-> int32_t @-> uint32_t @-> int32_t @-> (ptr void) @-> (ptr void) @-> (ptr int32_t) @-> (ptr void) @-> (ptr uint8_t) @-> (ptr void) @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* pString : void* -> (ptr void) *)
(* cString : INT -> int32_t *)
(* cGlyphs : INT -> int32_t *)
(* iCharset : INT -> int32_t *)
(* dwFlags : DWORD -> uint32_t *)
(* iReqWidth : INT -> int32_t *)
(* psControl : SCRIPT_CONTROL* optional -> (ptr void) *)
(* psState : SCRIPT_STATE* optional -> (ptr void) *)
(* piDx : INT* optional -> (ptr int32_t) *)
(* pTabdef : SCRIPT_TABDEF* optional -> (ptr void) *)
(* pbInClass : BYTE* -> (ptr uint8_t) *)
(* pssa : void** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library usp10 (t "USP10.dll"))
(cffi:use-foreign-library usp10)

(cffi:defcfun ("ScriptStringAnalyse" script-string-analyse :convention :stdcall) :int32
  (hdc :pointer)   ; HDC
  (p-string :pointer)   ; void*
  (c-string :int32)   ; INT
  (c-glyphs :int32)   ; INT
  (i-charset :int32)   ; INT
  (dw-flags :uint32)   ; DWORD
  (i-req-width :int32)   ; INT
  (ps-control :pointer)   ; SCRIPT_CONTROL* optional
  (ps-state :pointer)   ; SCRIPT_STATE* optional
  (pi-dx :pointer)   ; INT* optional
  (p-tabdef :pointer)   ; SCRIPT_TABDEF* optional
  (pb-in-class :pointer)   ; BYTE*
  (pssa :pointer))   ; void** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ScriptStringAnalyse = Win32::API::More->new('USP10',
    'int ScriptStringAnalyse(HANDLE hdc, LPVOID pString, int cString, int cGlyphs, int iCharset, DWORD dwFlags, int iReqWidth, LPVOID psControl, LPVOID psState, LPVOID piDx, LPVOID pTabdef, LPVOID pbInClass, LPVOID pssa)');
# my $ret = $ScriptStringAnalyse->Call($hdc, $pString, $cString, $cGlyphs, $iCharset, $dwFlags, $iReqWidth, $psControl, $psState, $piDx, $pTabdef, $pbInClass, $pssa);
# hdc : HDC -> HANDLE
# pString : void* -> LPVOID
# cString : INT -> int
# cGlyphs : INT -> int
# iCharset : INT -> int
# dwFlags : DWORD -> DWORD
# iReqWidth : INT -> int
# psControl : SCRIPT_CONTROL* optional -> LPVOID
# psState : SCRIPT_STATE* optional -> LPVOID
# piDx : INT* optional -> LPVOID
# pTabdef : SCRIPT_TABDEF* optional -> LPVOID
# pbInClass : BYTE* -> LPVOID
# pssa : void** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型