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

RemoveFontResourceExW

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

シグネチャ

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

BOOL RemoveFontResourceExW(
    LPCWSTR name,
    DWORD fl,
    void* pdv   // optional
);

パラメーター

名前方向説明
nameLPCWSTRinフォントリソースファイルの名前を指定する、null で終わる文字列へのポインター。
flDWORDinシステムから削除するフォントの特性。フォントを削除するには、AddFontResourceEx 関数でフォントを追加したときと同じフラグを使用する必要があります。詳細については、AddFontResourceEx 関数を参照してください。
pdvvoid*optional予約済み。0 を指定する必要があります。

戻り値の型: BOOL

公式ドキュメント

RemoveFontResourceEx 関数は、指定されたファイル内のフォントをシステムフォントテーブルから削除します。(Unicode)

戻り値

関数が成功した場合、戻り値は 0 以外の値です。

関数が失敗した場合、戻り値は 0 です。拡張エラー情報は利用できません。

解説(Remarks)

この関数は、指定されたフラグが AddFontResourceEx 関数でフォントを追加したときと同じである場合にのみ、フォントを削除します。

参照が残っているフォントを含む既存のフォントファイルを置き換えようとすると、RemoveFontResourceEx を呼び出した後でも、元のフォントが使用中であるため削除できないことを示すエラーが発生する場合があります。アプリでフォントファイルの置き換えが必要な場合、元のフォントのリソースカウントを 0 にするには、このサンプルコードのように RemoveFontResourceEx をループ内で呼び出します。それでもエラーが発生し続ける場合は、フォントファイルが他のセッションで読み込まれたままになっていることを示しています。フォントがフォントレジストリに登録されていないことを確認し、システムを再起動して、すべてのセッションからフォントがアンロードされていることを確認してください。

元のフォントファイルを使用しているアプリは、引き続き元のファイルにアクセスでき、フォントが再読み込みされるまで新しいフォントを使用しません。フォントを再読み込みするには AddFontResourceEx を呼び出します。このサンプルコードのように、RemoveFontResourceEx の呼び出しが成功したのと同じ回数だけ AddFontResourceEx を呼び出すことをお勧めします。

int i = 0;
while( RemoveFontResourceEx( FontFile, FR_PRIVATE, 0 ) )
{
    i++;
}

// TODO: Replace font file

while( i-- )
{
    AddFontResourceEx( FontFile, FR_PRIVATE, 0 );
}
メモ

wingdi.h ヘッダーは、RemoveFontResourceEx を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義します。エンコーディング中立のエイリアスの使用を、エンコーディング中立でないコードと混在させると、コンパイルエラーまたは実行時エラーを引き起こす不一致が発生する可能性があります。詳細については、Conventions for Function Prototypes を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

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

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

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procRemoveFontResourceExW = gdi32.NewProc("RemoveFontResourceExW")
)

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

extern "gdi32" fn RemoveFontResourceExW(
    name: [*c]const u16, // LPCWSTR
    fl: u32, // DWORD
    pdv: ?*anyopaque // void* optional
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc RemoveFontResourceExW(
    name: WideCString,  # LPCWSTR
    fl: uint32,  # DWORD
    pdv: pointer  # void* optional
): int32 {.importc: "RemoveFontResourceExW", stdcall, dynlib: "GDI32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "gdi32");
extern(Windows)
int RemoveFontResourceExW(
    const(wchar)* name,   // LPCWSTR
    uint fl,   // DWORD
    void* pdv   // void* optional
);
ccall((:RemoveFontResourceExW, "GDI32.dll"), stdcall, Int32,
      (Cwstring, UInt32, Ptr{Cvoid}),
      name, fl, pdv)
# name : LPCWSTR -> Cwstring
# fl : DWORD -> UInt32
# pdv : void* optional -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t RemoveFontResourceExW(
    const uint16_t* name,
    uint32_t fl,
    void* pdv);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.RemoveFontResourceExW(name, fl, pdv)
-- name : LPCWSTR
-- fl : DWORD
-- pdv : void* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const RemoveFontResourceExW = lib.func('__stdcall', 'RemoveFontResourceExW', 'int32_t', ['str16', 'uint32_t', 'void *']);
// RemoveFontResourceExW(name, fl, pdv)
// name : LPCWSTR -> 'str16'
// fl : DWORD -> 'uint32_t'
// pdv : void* optional -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("GDI32.dll", {
  RemoveFontResourceExW: { parameters: ["buffer", "u32", "pointer"], result: "i32" },
});
// lib.symbols.RemoveFontResourceExW(name, fl, pdv)
// name : LPCWSTR -> "buffer"
// fl : DWORD -> "u32"
// pdv : void* optional -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t RemoveFontResourceExW(
    const uint16_t* name,
    uint32_t fl,
    void* pdv);
C, "GDI32.dll");
// $ffi->RemoveFontResourceExW(name, fl, pdv);
// name : LPCWSTR
// fl : DWORD
// pdv : void* optional
// 構造体/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.UNICODE_OPTIONS);
    boolean RemoveFontResourceExW(
        WString name,   // LPCWSTR
        int fl,   // DWORD
        Pointer pdv   // void* optional
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("gdi32")]
lib LibGDI32
  fun RemoveFontResourceExW = RemoveFontResourceExW(
    name : UInt16*,   # LPCWSTR
    fl : UInt32,   # DWORD
    pdv : Void*   # void* optional
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RemoveFontResourceExWNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Void>);
typedef RemoveFontResourceExWDart = int Function(Pointer<Utf16>, int, Pointer<Void>);
final RemoveFontResourceExW = DynamicLibrary.open('GDI32.dll')
    .lookupFunction<RemoveFontResourceExWNative, RemoveFontResourceExWDart>('RemoveFontResourceExW');
// name : LPCWSTR -> Pointer<Utf16>
// fl : DWORD -> Uint32
// pdv : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RemoveFontResourceExW(
  name: PWideChar;   // LPCWSTR
  fl: DWORD;   // DWORD
  pdv: Pointer   // void* optional
): BOOL; stdcall;
  external 'GDI32.dll' name 'RemoveFontResourceExW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RemoveFontResourceExW"
  c_RemoveFontResourceExW :: CWString -> Word32 -> Ptr () -> IO CInt
-- name : LPCWSTR -> CWString
-- fl : DWORD -> Word32
-- pdv : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let removefontresourceexw =
  foreign "RemoveFontResourceExW"
    ((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* name : LPCWSTR -> (ptr uint16_t) *)
(* fl : DWORD -> uint32_t *)
(* pdv : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)

(cffi:defcfun ("RemoveFontResourceExW" remove-font-resource-ex-w :convention :stdcall) :int32
  (name (:string :encoding :utf-16le))   ; LPCWSTR
  (fl :uint32)   ; DWORD
  (pdv :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RemoveFontResourceExW = Win32::API::More->new('GDI32',
    'BOOL RemoveFontResourceExW(LPCWSTR name, DWORD fl, LPVOID pdv)');
# my $ret = $RemoveFontResourceExW->Call($name, $fl, $pdv);
# name : LPCWSTR -> LPCWSTR
# fl : DWORD -> DWORD
# pdv : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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