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

GetGlyphIndicesA

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

シグネチャ

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

DWORD GetGlyphIndicesA(
    HDC hdc,
    LPCSTR lpstr,
    INT c,
    WORD* pgi,
    DWORD fl
);

パラメーター

名前方向説明
hdcHDCinデバイスコンテキストへのハンドルです。
lpstrLPCSTRin変換する文字列へのポインターです。
cINTinlpstr が指す文字列の長さと、pgi が指すバッファーのサイズ(WORD 単位)の両方を指定します。
pgiWORD*outこのバッファーは次元 c を持つ必要があります。正常に返ると、文字列内の文字に対応するグリフインデックスの配列が格納されます。
flDWORDin

サポートされていないグリフをどのように処理するかを指定します。このパラメーターには次の値を指定できます。

意味
GGI_MARK_NONEXISTING_GLYPHS
サポートされていないグリフを 16 進値 0xffff でマークします。

戻り値の型: DWORD

公式ドキュメント

GetGlyphIndices 関数は、文字列をグリフインデックスの配列に変換します。この関数は、グリフがフォント内に存在するかどうかを判定するために使用できます。(ANSI)

戻り値

関数が成功した場合、変換されたバイト数(ANSI 関数の場合)または WORD 数(Unicode 関数の場合)を返します。

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

解説(Remarks)

この関数は、lpstr が指す文字列内の各文字について、単一グリフによる表現を特定しようとします。これはフォントファイルの操作などの特定の低レベルな目的には有用ですが、文字列をグリフにマップしたい高レベルなアプリケーションでは、通常は Uniscribe 関数を使用するのが望ましいでしょう。

メモ

wingdi.h ヘッダーは、GetGlyphIndices を、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>

DWORD GetGlyphIndicesA(
    HDC hdc,
    LPCSTR lpstr,
    INT c,
    WORD* pgi,
    DWORD fl
);
[DllImport("GDI32.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint GetGlyphIndicesA(
    IntPtr hdc,   // HDC
    [MarshalAs(UnmanagedType.LPStr)] string lpstr,   // LPCSTR
    int c,   // INT
    out ushort pgi,   // WORD* out
    uint fl   // DWORD
);
<DllImport("GDI32.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetGlyphIndicesA(
    hdc As IntPtr,   ' HDC
    <MarshalAs(UnmanagedType.LPStr)> lpstr As String,   ' LPCSTR
    c As Integer,   ' INT
    <Out> ByRef pgi As UShort,   ' WORD* out
    fl As UInteger   ' DWORD
) As UInteger
End Function
' hdc : HDC
' lpstr : LPCSTR
' c : INT
' pgi : WORD* out
' fl : DWORD
Declare PtrSafe Function GetGlyphIndicesA Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal lpstr As String, _
    ByVal c As Long, _
    ByRef pgi As Integer, _
    ByVal fl As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetGlyphIndicesA = ctypes.windll.gdi32.GetGlyphIndicesA
GetGlyphIndicesA.restype = wintypes.DWORD
GetGlyphIndicesA.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.LPCSTR,  # lpstr : LPCSTR
    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')
GetGlyphIndicesA = Fiddle::Function.new(
  lib['GetGlyphIndicesA'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_VOIDP,  # lpstr : LPCSTR
    Fiddle::TYPE_INT,  # c : INT
    Fiddle::TYPE_VOIDP,  # pgi : WORD* out
    -Fiddle::TYPE_INT,  # fl : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn GetGlyphIndicesA(
        hdc: *mut core::ffi::c_void,  // HDC
        lpstr: *const u8,  // LPCSTR
        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.Ansi)]
public static extern uint GetGlyphIndicesA(IntPtr hdc, [MarshalAs(UnmanagedType.LPStr)] string lpstr, int c, out ushort pgi, uint fl);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetGlyphIndicesA' -Namespace Win32 -PassThru
# $api::GetGlyphIndicesA(hdc, lpstr, c, pgi, fl)
#uselib "GDI32.dll"
#func global GetGlyphIndicesA "GetGlyphIndicesA" sptr, sptr, sptr, sptr, sptr
; GetGlyphIndicesA hdc, lpstr, c, varptr(pgi), fl   ; 戻り値は stat
; hdc : HDC -> "sptr"
; lpstr : LPCSTR -> "sptr"
; c : INT -> "sptr"
; pgi : WORD* out -> "sptr"
; fl : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global GetGlyphIndicesA "GetGlyphIndicesA" sptr, str, int, var, int
; res = GetGlyphIndicesA(hdc, lpstr, c, pgi, fl)
; hdc : HDC -> "sptr"
; lpstr : LPCSTR -> "str"
; c : INT -> "int"
; pgi : WORD* out -> "var"
; fl : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetGlyphIndicesA(HDC hdc, LPCSTR lpstr, INT c, WORD* pgi, DWORD fl)
#uselib "GDI32.dll"
#cfunc global GetGlyphIndicesA "GetGlyphIndicesA" intptr, str, int, var, int
; res = GetGlyphIndicesA(hdc, lpstr, c, pgi, fl)
; hdc : HDC -> "intptr"
; lpstr : LPCSTR -> "str"
; 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")
	procGetGlyphIndicesA = gdi32.NewProc("GetGlyphIndicesA")
)

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

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

typedef GetGlyphIndicesANative = Uint32 Function(Pointer<Void>, Pointer<Utf8>, Int32, Pointer<Uint16>, Uint32);
typedef GetGlyphIndicesADart = int Function(Pointer<Void>, Pointer<Utf8>, int, Pointer<Uint16>, int);
final GetGlyphIndicesA = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<GetGlyphIndicesANative, GetGlyphIndicesADart>('GetGlyphIndicesA');
// hdc : HDC -> Pointer<Void>
// lpstr : LPCSTR -> Pointer<Utf8>
// c : INT -> Int32
// pgi : WORD* out -> Pointer<Uint16>
// fl : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetGlyphIndicesA(
  hdc: THandle;   // HDC
  lpstr: PAnsiChar;   // LPCSTR
  c: Integer;   // INT
  pgi: Pointer;   // WORD* out
  fl: DWORD   // DWORD
): DWORD; stdcall;
  external 'GDI32.dll' name 'GetGlyphIndicesA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetGlyphIndicesA"
  c_GetGlyphIndicesA :: Ptr () -> CString -> Int32 -> Ptr Word16 -> Word32 -> IO Word32
-- hdc : HDC -> Ptr ()
-- lpstr : LPCSTR -> CString
-- c : INT -> Int32
-- pgi : WORD* out -> Ptr Word16
-- fl : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getglyphindicesa =
  foreign "GetGlyphIndicesA"
    ((ptr void) @-> string @-> int32_t @-> (ptr uint16_t) @-> uint32_t @-> returning uint32_t)
(* hdc : HDC -> (ptr void) *)
(* lpstr : LPCSTR -> string *)
(* c : INT -> int32_t *)
(* pgi : WORD* out -> (ptr uint16_t) *)
(* fl : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("GetGlyphIndicesA" get-glyph-indices-a :convention :stdcall) :uint32
  (hdc :pointer)   ; HDC
  (lpstr :string)   ; LPCSTR
  (c :int32)   ; INT
  (pgi :pointer)   ; WORD* out
  (fl :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetGlyphIndicesA = Win32::API::More->new('GDI32',
    'DWORD GetGlyphIndicesA(HANDLE hdc, LPCSTR lpstr, int c, LPVOID pgi, DWORD fl)');
# my $ret = $GetGlyphIndicesA->Call($hdc, $lpstr, $c, $pgi, $fl);
# hdc : HDC -> HANDLE
# lpstr : LPCSTR -> LPCSTR
# c : INT -> int
# pgi : WORD* out -> LPVOID
# fl : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
公式の関連項目