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

AddFontResourceW

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

シグネチャ

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

INT AddFontResourceW(
    LPCWSTR param0
);

パラメーター

名前方向
param0LPCWSTRin

戻り値の型: INT

各言語での呼び出し定義

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

INT AddFontResourceW(
    LPCWSTR param0
);
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int AddFontResourceW(
    [MarshalAs(UnmanagedType.LPWStr)] string param0   // LPCWSTR
);
<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function AddFontResourceW(
    <MarshalAs(UnmanagedType.LPWStr)> param0 As String   ' LPCWSTR
) As Integer
End Function
' param0 : LPCWSTR
Declare PtrSafe Function AddFontResourceW Lib "gdi32" ( _
    ByVal param0 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

AddFontResourceW = ctypes.windll.gdi32.AddFontResourceW
AddFontResourceW.restype = ctypes.c_int
AddFontResourceW.argtypes = [
    wintypes.LPCWSTR,  # param0 : LPCWSTR
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procAddFontResourceW = gdi32.NewProc("AddFontResourceW")
)

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