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

GetGlyphIndicesW

関数
文字列をグリフインデックスに変換して取得する。
DLLGDI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

// GDI32.dll  (Unicode / -W)
#include <windows.h>

DWORD GetGlyphIndicesW(
    HDC hdc,
    LPCWSTR lpstr,
    INT c,
    WORD* pgi,
    DWORD fl
);

パラメーター

名前方向
hdcHDCin
lpstrLPCWSTRin
cINTin
pgiWORD*out
flDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

// GDI32.dll  (Unicode / -W)
#include <windows.h>

DWORD GetGlyphIndicesW(
    HDC hdc,
    LPCWSTR lpstr,
    INT c,
    WORD* pgi,
    DWORD fl
);
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint GetGlyphIndicesW(
    IntPtr hdc,   // HDC
    [MarshalAs(UnmanagedType.LPWStr)] string lpstr,   // LPCWSTR
    int c,   // INT
    out ushort pgi,   // WORD* out
    uint fl   // DWORD
);
<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetGlyphIndicesW(
    hdc As IntPtr,   ' HDC
    <MarshalAs(UnmanagedType.LPWStr)> lpstr As String,   ' LPCWSTR
    c As Integer,   ' INT
    <Out> ByRef pgi As UShort,   ' WORD* out
    fl As UInteger   ' DWORD
) As UInteger
End Function
' hdc : HDC
' lpstr : LPCWSTR
' c : INT
' pgi : WORD* out
' fl : DWORD
Declare PtrSafe Function GetGlyphIndicesW Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal lpstr As LongPtr, _
    ByVal c As Long, _
    ByRef pgi As Integer, _
    ByVal fl As Long) 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

GetGlyphIndicesW = ctypes.windll.gdi32.GetGlyphIndicesW
GetGlyphIndicesW.restype = wintypes.DWORD
GetGlyphIndicesW.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.LPCWSTR,  # lpstr : LPCWSTR
    ctypes.c_int,  # c : INT
    ctypes.POINTER(ctypes.c_ushort),  # pgi : WORD* out
    wintypes.DWORD,  # fl : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
GetGlyphIndicesW = Fiddle::Function.new(
  lib['GetGlyphIndicesW'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # lpstr : LPCWSTR
    Fiddle::TYPE_INT,  # c : INT
    Fiddle::TYPE_VOIDP,  # pgi : WORD* out
    -Fiddle::TYPE_INT,  # fl : DWORD
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "gdi32")]
extern "system" {
    fn GetGlyphIndicesW(
        hdc: *mut core::ffi::c_void,  // HDC
        lpstr: *const u16,  // LPCWSTR
        c: i32,  // INT
        pgi: *mut u16,  // WORD* out
        fl: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll", CharSet = CharSet.Unicode)]
public static extern uint GetGlyphIndicesW(IntPtr hdc, [MarshalAs(UnmanagedType.LPWStr)] string lpstr, int c, out ushort pgi, uint fl);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetGlyphIndicesW' -Namespace Win32 -PassThru
# $api::GetGlyphIndicesW(hdc, lpstr, c, pgi, fl)
#uselib "GDI32.dll"
#func global GetGlyphIndicesW "GetGlyphIndicesW" wptr, wptr, wptr, wptr, wptr
; GetGlyphIndicesW hdc, lpstr, c, varptr(pgi), fl   ; 戻り値は stat
; hdc : HDC -> "wptr"
; lpstr : LPCWSTR -> "wptr"
; c : INT -> "wptr"
; pgi : WORD* out -> "wptr"
; fl : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global GetGlyphIndicesW "GetGlyphIndicesW" sptr, wstr, int, var, int
; res = GetGlyphIndicesW(hdc, lpstr, c, pgi, fl)
; hdc : HDC -> "sptr"
; lpstr : LPCWSTR -> "wstr"
; c : INT -> "int"
; pgi : WORD* out -> "var"
; fl : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetGlyphIndicesW(HDC hdc, LPCWSTR lpstr, INT c, WORD* pgi, DWORD fl)
#uselib "GDI32.dll"
#cfunc global GetGlyphIndicesW "GetGlyphIndicesW" intptr, wstr, int, var, int
; res = GetGlyphIndicesW(hdc, lpstr, c, pgi, fl)
; hdc : HDC -> "intptr"
; lpstr : LPCWSTR -> "wstr"
; c : INT -> "int"
; pgi : WORD* out -> "var"
; fl : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetGlyphIndicesW = gdi32.NewProc("GetGlyphIndicesW")
)

// hdc (HDC), lpstr (LPCWSTR), c (INT), pgi (WORD* out), fl (DWORD)
r1, _, err := procGetGlyphIndicesW.Call(
	uintptr(hdc),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpstr))),
	uintptr(c),
	uintptr(pgi),
	uintptr(fl),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetGlyphIndicesW(
  hdc: THandle;   // HDC
  lpstr: PWideChar;   // LPCWSTR
  c: Integer;   // INT
  pgi: Pointer;   // WORD* out
  fl: DWORD   // DWORD
): DWORD; stdcall;
  external 'GDI32.dll' name 'GetGlyphIndicesW';
result := DllCall("GDI32\GetGlyphIndicesW"
    , "Ptr", hdc   ; HDC
    , "WStr", lpstr   ; LPCWSTR
    , "Int", c   ; INT
    , "Ptr", pgi   ; WORD* out
    , "UInt", fl   ; DWORD
    , "UInt")   ; return: DWORD
●GetGlyphIndicesW(hdc, lpstr, c, pgi, fl) = DLL("GDI32.dll", "dword GetGlyphIndicesW(void*, char*, int, void*, dword)")
# 呼び出し: GetGlyphIndicesW(hdc, lpstr, c, pgi, fl)
# hdc : HDC -> "void*"
# lpstr : LPCWSTR -> "char*"
# c : INT -> "int"
# pgi : WORD* out -> "void*"
# fl : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。