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

AddFontResourceExW

関数
指定したフォントリソースをシステムに追加する。
DLLGDI32.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT AddFontResourceExW(
    LPCWSTR name,
    FONT_RESOURCE_CHARACTERISTICS fl,
    void* res   // optional
);

パラメーター

名前方向
nameLPCWSTRin
flFONT_RESOURCE_CHARACTERISTICSin
resvoid*optional

戻り値の型: INT

各言語での呼び出し定義

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

INT AddFontResourceExW(
    LPCWSTR name,
    FONT_RESOURCE_CHARACTERISTICS fl,
    void* res   // optional
);
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int AddFontResourceExW(
    [MarshalAs(UnmanagedType.LPWStr)] string name,   // LPCWSTR
    uint fl,   // FONT_RESOURCE_CHARACTERISTICS
    IntPtr res   // void* optional
);
<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function AddFontResourceExW(
    <MarshalAs(UnmanagedType.LPWStr)> name As String,   ' LPCWSTR
    fl As UInteger,   ' FONT_RESOURCE_CHARACTERISTICS
    res As IntPtr   ' void* optional
) As Integer
End Function
' name : LPCWSTR
' fl : FONT_RESOURCE_CHARACTERISTICS
' res : void* optional
Declare PtrSafe Function AddFontResourceExW Lib "gdi32" ( _
    ByVal name As LongPtr, _
    ByVal fl As Long, _
    ByVal res As LongPtr) 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

AddFontResourceExW = ctypes.windll.gdi32.AddFontResourceExW
AddFontResourceExW.restype = ctypes.c_int
AddFontResourceExW.argtypes = [
    wintypes.LPCWSTR,  # name : LPCWSTR
    wintypes.DWORD,  # fl : FONT_RESOURCE_CHARACTERISTICS
    ctypes.POINTER(None),  # res : void* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
AddFontResourceExW = Fiddle::Function.new(
  lib['AddFontResourceExW'],
  [
    Fiddle::TYPE_VOIDP,  # name : LPCWSTR
    -Fiddle::TYPE_INT,  # fl : FONT_RESOURCE_CHARACTERISTICS
    Fiddle::TYPE_VOIDP,  # res : void* optional
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "gdi32")]
extern "system" {
    fn AddFontResourceExW(
        name: *const u16,  // LPCWSTR
        fl: u32,  // FONT_RESOURCE_CHARACTERISTICS
        res: *mut ()  // void* optional
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("GDI32.dll", CharSet = CharSet.Unicode)]
public static extern int AddFontResourceExW([MarshalAs(UnmanagedType.LPWStr)] string name, uint fl, IntPtr res);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_AddFontResourceExW' -Namespace Win32 -PassThru
# $api::AddFontResourceExW(name, fl, res)
#uselib "GDI32.dll"
#func global AddFontResourceExW "AddFontResourceExW" wptr, wptr, wptr
; AddFontResourceExW name, fl, res   ; 戻り値は stat
; name : LPCWSTR -> "wptr"
; fl : FONT_RESOURCE_CHARACTERISTICS -> "wptr"
; res : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "GDI32.dll"
#cfunc global AddFontResourceExW "AddFontResourceExW" wstr, int, sptr
; res = AddFontResourceExW(name, fl, res)
; name : LPCWSTR -> "wstr"
; fl : FONT_RESOURCE_CHARACTERISTICS -> "int"
; res : void* optional -> "sptr"
; INT AddFontResourceExW(LPCWSTR name, FONT_RESOURCE_CHARACTERISTICS fl, void* res)
#uselib "GDI32.dll"
#cfunc global AddFontResourceExW "AddFontResourceExW" wstr, int, intptr
; res = AddFontResourceExW(name, fl, res)
; name : LPCWSTR -> "wstr"
; fl : FONT_RESOURCE_CHARACTERISTICS -> "int"
; res : void* optional -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procAddFontResourceExW = gdi32.NewProc("AddFontResourceExW")
)

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