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

GetFontData

関数
フォントファイルのメトリックテーブルを取得する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

DWORD GetFontData(
    HDC hdc,
    DWORD dwTable,
    DWORD dwOffset,
    void* pvBuffer,   // optional
    DWORD cjBuffer
);

パラメーター

名前方向
hdcHDCin
dwTableDWORDin
dwOffsetDWORDin
pvBuffervoid*outoptional
cjBufferDWORDin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetFontData(
    HDC hdc,
    DWORD dwTable,
    DWORD dwOffset,
    void* pvBuffer,   // optional
    DWORD cjBuffer
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern uint GetFontData(
    IntPtr hdc,   // HDC
    uint dwTable,   // DWORD
    uint dwOffset,   // DWORD
    IntPtr pvBuffer,   // void* optional, out
    uint cjBuffer   // DWORD
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function GetFontData(
    hdc As IntPtr,   ' HDC
    dwTable As UInteger,   ' DWORD
    dwOffset As UInteger,   ' DWORD
    pvBuffer As IntPtr,   ' void* optional, out
    cjBuffer As UInteger   ' DWORD
) As UInteger
End Function
' hdc : HDC
' dwTable : DWORD
' dwOffset : DWORD
' pvBuffer : void* optional, out
' cjBuffer : DWORD
Declare PtrSafe Function GetFontData Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal dwTable As Long, _
    ByVal dwOffset As Long, _
    ByVal pvBuffer As LongPtr, _
    ByVal cjBuffer As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetFontData = ctypes.windll.gdi32.GetFontData
GetFontData.restype = wintypes.DWORD
GetFontData.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    wintypes.DWORD,  # dwTable : DWORD
    wintypes.DWORD,  # dwOffset : DWORD
    ctypes.POINTER(None),  # pvBuffer : void* optional, out
    wintypes.DWORD,  # cjBuffer : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
GetFontData = Fiddle::Function.new(
  lib['GetFontData'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    -Fiddle::TYPE_INT,  # dwTable : DWORD
    -Fiddle::TYPE_INT,  # dwOffset : DWORD
    Fiddle::TYPE_VOIDP,  # pvBuffer : void* optional, out
    -Fiddle::TYPE_INT,  # cjBuffer : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn GetFontData(
        hdc: *mut core::ffi::c_void,  // HDC
        dwTable: u32,  // DWORD
        dwOffset: u32,  // DWORD
        pvBuffer: *mut (),  // void* optional, out
        cjBuffer: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll")]
public static extern uint GetFontData(IntPtr hdc, uint dwTable, uint dwOffset, IntPtr pvBuffer, uint cjBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_GetFontData' -Namespace Win32 -PassThru
# $api::GetFontData(hdc, dwTable, dwOffset, pvBuffer, cjBuffer)
#uselib "GDI32.dll"
#func global GetFontData "GetFontData" sptr, sptr, sptr, sptr, sptr
; GetFontData hdc, dwTable, dwOffset, pvBuffer, cjBuffer   ; 戻り値は stat
; hdc : HDC -> "sptr"
; dwTable : DWORD -> "sptr"
; dwOffset : DWORD -> "sptr"
; pvBuffer : void* optional, out -> "sptr"
; cjBuffer : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global GetFontData "GetFontData" sptr, int, int, sptr, int
; res = GetFontData(hdc, dwTable, dwOffset, pvBuffer, cjBuffer)
; hdc : HDC -> "sptr"
; dwTable : DWORD -> "int"
; dwOffset : DWORD -> "int"
; pvBuffer : void* optional, out -> "sptr"
; cjBuffer : DWORD -> "int"
; DWORD GetFontData(HDC hdc, DWORD dwTable, DWORD dwOffset, void* pvBuffer, DWORD cjBuffer)
#uselib "GDI32.dll"
#cfunc global GetFontData "GetFontData" intptr, int, int, intptr, int
; res = GetFontData(hdc, dwTable, dwOffset, pvBuffer, cjBuffer)
; hdc : HDC -> "intptr"
; dwTable : DWORD -> "int"
; dwOffset : DWORD -> "int"
; pvBuffer : void* optional, out -> "intptr"
; cjBuffer : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procGetFontData = gdi32.NewProc("GetFontData")
)

// hdc (HDC), dwTable (DWORD), dwOffset (DWORD), pvBuffer (void* optional, out), cjBuffer (DWORD)
r1, _, err := procGetFontData.Call(
	uintptr(hdc),
	uintptr(dwTable),
	uintptr(dwOffset),
	uintptr(pvBuffer),
	uintptr(cjBuffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetFontData(
  hdc: THandle;   // HDC
  dwTable: DWORD;   // DWORD
  dwOffset: DWORD;   // DWORD
  pvBuffer: Pointer;   // void* optional, out
  cjBuffer: DWORD   // DWORD
): DWORD; stdcall;
  external 'GDI32.dll' name 'GetFontData';
result := DllCall("GDI32\GetFontData"
    , "Ptr", hdc   ; HDC
    , "UInt", dwTable   ; DWORD
    , "UInt", dwOffset   ; DWORD
    , "Ptr", pvBuffer   ; void* optional, out
    , "UInt", cjBuffer   ; DWORD
    , "UInt")   ; return: DWORD
●GetFontData(hdc, dwTable, dwOffset, pvBuffer, cjBuffer) = DLL("GDI32.dll", "dword GetFontData(void*, dword, dword, void*, dword)")
# 呼び出し: GetFontData(hdc, dwTable, dwOffset, pvBuffer, cjBuffer)
# hdc : HDC -> "void*"
# dwTable : DWORD -> "dword"
# dwOffset : DWORD -> "dword"
# pvBuffer : void* optional, out -> "void*"
# cjBuffer : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。