ホーム › Graphics.Gdi › AddFontMemResourceEx
AddFontMemResourceEx
関数メモリ上のフォントデータをシステムに追加する。
シグネチャ
// GDI32.dll
#include <windows.h>
HANDLE AddFontMemResourceEx(
void* pFileView,
DWORD cjSize,
void* pvResrved, // optional
DWORD* pNumFonts
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pFileView | void* | in | フォントリソースへのポインター。 |
| cjSize | DWORD | in | pbFont が指すフォントリソースのバイト数。 |
| pvResrved | void* | optional | 予約済み。0 を指定する必要があります。 |
| pNumFonts | DWORD* | in | インストールされたフォントの数を格納する変数へのポインター。 |
戻り値の型: HANDLE
公式ドキュメント
AddFontMemResourceEx 関数は、メモリイメージ上のフォントリソースをシステムに追加します。
戻り値
関数が成功した場合、戻り値は追加されたフォントのハンドルを示します。このハンドルは、システムにインストールされたフォントを一意に識別します。関数が失敗した場合、戻り値は 0 です。拡張エラー情報は提供されません。
解説(Remarks)
この関数を使用すると、アプリケーションはドキュメントや Web ページに埋め込まれたフォントを取得できます。AddFontMemResourceEx によって追加されたフォントは、常に呼び出しを行ったプロセスにプライベートであり、列挙できません。
1 つのメモリイメージには複数のフォントを含めることができます。この関数が成功すると、pcFonts は、この呼び出しの結果としてシステムに追加されたフォントの数を値として持つ DWORD へのポインターになります。たとえば、アジア系フォントの縦書き用と横書き用の字体では、この数が 2 になることがあります。
関数が成功すると、システムはメモリの独自のコピーを作成しているため、この関数の呼び出し元は pbFont が指すメモリを解放できます。インストールされたフォントを削除するには、RemoveFontMemResourceEx を呼び出します。ただし、プロセスが終了すると、RemoveFontMemResource を呼び出していなくても、システムはフォントをアンロードします。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
HANDLE AddFontMemResourceEx(
void* pFileView,
DWORD cjSize,
void* pvResrved, // optional
DWORD* pNumFonts
);[DllImport("GDI32.dll", ExactSpelling = true)]
static extern IntPtr AddFontMemResourceEx(
IntPtr pFileView, // void*
uint cjSize, // DWORD
IntPtr pvResrved, // void* optional
ref uint pNumFonts // DWORD*
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function AddFontMemResourceEx(
pFileView As IntPtr, ' void*
cjSize As UInteger, ' DWORD
pvResrved As IntPtr, ' void* optional
ByRef pNumFonts As UInteger ' DWORD*
) As IntPtr
End Function' pFileView : void*
' cjSize : DWORD
' pvResrved : void* optional
' pNumFonts : DWORD*
Declare PtrSafe Function AddFontMemResourceEx Lib "gdi32" ( _
ByVal pFileView As LongPtr, _
ByVal cjSize As Long, _
ByVal pvResrved As LongPtr, _
ByRef pNumFonts As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
AddFontMemResourceEx = ctypes.windll.gdi32.AddFontMemResourceEx
AddFontMemResourceEx.restype = ctypes.c_void_p
AddFontMemResourceEx.argtypes = [
ctypes.POINTER(None), # pFileView : void*
wintypes.DWORD, # cjSize : DWORD
ctypes.POINTER(None), # pvResrved : void* optional
ctypes.POINTER(wintypes.DWORD), # pNumFonts : DWORD*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
AddFontMemResourceEx = Fiddle::Function.new(
lib['AddFontMemResourceEx'],
[
Fiddle::TYPE_VOIDP, # pFileView : void*
-Fiddle::TYPE_INT, # cjSize : DWORD
Fiddle::TYPE_VOIDP, # pvResrved : void* optional
Fiddle::TYPE_VOIDP, # pNumFonts : DWORD*
],
Fiddle::TYPE_VOIDP)#[link(name = "gdi32")]
extern "system" {
fn AddFontMemResourceEx(
pFileView: *mut (), // void*
cjSize: u32, // DWORD
pvResrved: *mut (), // void* optional
pNumFonts: *mut u32 // DWORD*
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll")]
public static extern IntPtr AddFontMemResourceEx(IntPtr pFileView, uint cjSize, IntPtr pvResrved, ref uint pNumFonts);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_AddFontMemResourceEx' -Namespace Win32 -PassThru
# $api::AddFontMemResourceEx(pFileView, cjSize, pvResrved, pNumFonts)#uselib "GDI32.dll"
#func global AddFontMemResourceEx "AddFontMemResourceEx" sptr, sptr, sptr, sptr
; AddFontMemResourceEx pFileView, cjSize, pvResrved, varptr(pNumFonts) ; 戻り値は stat
; pFileView : void* -> "sptr"
; cjSize : DWORD -> "sptr"
; pvResrved : void* optional -> "sptr"
; pNumFonts : DWORD* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "GDI32.dll" #cfunc global AddFontMemResourceEx "AddFontMemResourceEx" sptr, int, sptr, var ; res = AddFontMemResourceEx(pFileView, cjSize, pvResrved, pNumFonts) ; pFileView : void* -> "sptr" ; cjSize : DWORD -> "int" ; pvResrved : void* optional -> "sptr" ; pNumFonts : DWORD* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global AddFontMemResourceEx "AddFontMemResourceEx" sptr, int, sptr, sptr ; res = AddFontMemResourceEx(pFileView, cjSize, pvResrved, varptr(pNumFonts)) ; pFileView : void* -> "sptr" ; cjSize : DWORD -> "int" ; pvResrved : void* optional -> "sptr" ; pNumFonts : DWORD* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HANDLE AddFontMemResourceEx(void* pFileView, DWORD cjSize, void* pvResrved, DWORD* pNumFonts) #uselib "GDI32.dll" #cfunc global AddFontMemResourceEx "AddFontMemResourceEx" intptr, int, intptr, var ; res = AddFontMemResourceEx(pFileView, cjSize, pvResrved, pNumFonts) ; pFileView : void* -> "intptr" ; cjSize : DWORD -> "int" ; pvResrved : void* optional -> "intptr" ; pNumFonts : DWORD* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HANDLE AddFontMemResourceEx(void* pFileView, DWORD cjSize, void* pvResrved, DWORD* pNumFonts) #uselib "GDI32.dll" #cfunc global AddFontMemResourceEx "AddFontMemResourceEx" intptr, int, intptr, intptr ; res = AddFontMemResourceEx(pFileView, cjSize, pvResrved, varptr(pNumFonts)) ; pFileView : void* -> "intptr" ; cjSize : DWORD -> "int" ; pvResrved : void* optional -> "intptr" ; pNumFonts : DWORD* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procAddFontMemResourceEx = gdi32.NewProc("AddFontMemResourceEx")
)
// pFileView (void*), cjSize (DWORD), pvResrved (void* optional), pNumFonts (DWORD*)
r1, _, err := procAddFontMemResourceEx.Call(
uintptr(pFileView),
uintptr(cjSize),
uintptr(pvResrved),
uintptr(pNumFonts),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction AddFontMemResourceEx(
pFileView: Pointer; // void*
cjSize: DWORD; // DWORD
pvResrved: Pointer; // void* optional
pNumFonts: Pointer // DWORD*
): THandle; stdcall;
external 'GDI32.dll' name 'AddFontMemResourceEx';result := DllCall("GDI32\AddFontMemResourceEx"
, "Ptr", pFileView ; void*
, "UInt", cjSize ; DWORD
, "Ptr", pvResrved ; void* optional
, "Ptr", pNumFonts ; DWORD*
, "Ptr") ; return: HANDLE●AddFontMemResourceEx(pFileView, cjSize, pvResrved, pNumFonts) = DLL("GDI32.dll", "void* AddFontMemResourceEx(void*, dword, void*, void*)")
# 呼び出し: AddFontMemResourceEx(pFileView, cjSize, pvResrved, pNumFonts)
# pFileView : void* -> "void*"
# cjSize : DWORD -> "dword"
# pvResrved : void* optional -> "void*"
# pNumFonts : DWORD* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn AddFontMemResourceEx(
pFileView: ?*anyopaque, // void*
cjSize: u32, // DWORD
pvResrved: ?*anyopaque, // void* optional
pNumFonts: [*c]u32 // DWORD*
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc AddFontMemResourceEx(
pFileView: pointer, # void*
cjSize: uint32, # DWORD
pvResrved: pointer, # void* optional
pNumFonts: ptr uint32 # DWORD*
): pointer {.importc: "AddFontMemResourceEx", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
void* AddFontMemResourceEx(
void* pFileView, // void*
uint cjSize, // DWORD
void* pvResrved, // void* optional
uint* pNumFonts // DWORD*
);ccall((:AddFontMemResourceEx, "GDI32.dll"), stdcall, Ptr{Cvoid},
(Ptr{Cvoid}, UInt32, Ptr{Cvoid}, Ptr{UInt32}),
pFileView, cjSize, pvResrved, pNumFonts)
# pFileView : void* -> Ptr{Cvoid}
# cjSize : DWORD -> UInt32
# pvResrved : void* optional -> Ptr{Cvoid}
# pNumFonts : DWORD* -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* AddFontMemResourceEx(
void* pFileView,
uint32_t cjSize,
void* pvResrved,
uint32_t* pNumFonts);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.AddFontMemResourceEx(pFileView, cjSize, pvResrved, pNumFonts)
-- pFileView : void*
-- cjSize : DWORD
-- pvResrved : void* optional
-- pNumFonts : DWORD*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const AddFontMemResourceEx = lib.func('__stdcall', 'AddFontMemResourceEx', 'void *', ['void *', 'uint32_t', 'void *', 'uint32_t *']);
// AddFontMemResourceEx(pFileView, cjSize, pvResrved, pNumFonts)
// pFileView : void* -> 'void *'
// cjSize : DWORD -> 'uint32_t'
// pvResrved : void* optional -> 'void *'
// pNumFonts : DWORD* -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
AddFontMemResourceEx: { parameters: ["pointer", "u32", "pointer", "pointer"], result: "pointer" },
});
// lib.symbols.AddFontMemResourceEx(pFileView, cjSize, pvResrved, pNumFonts)
// pFileView : void* -> "pointer"
// cjSize : DWORD -> "u32"
// pvResrved : void* optional -> "pointer"
// pNumFonts : DWORD* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* AddFontMemResourceEx(
void* pFileView,
uint32_t cjSize,
void* pvResrved,
uint32_t* pNumFonts);
C, "GDI32.dll");
// $ffi->AddFontMemResourceEx(pFileView, cjSize, pvResrved, pNumFonts);
// pFileView : void*
// cjSize : DWORD
// pvResrved : void* optional
// pNumFonts : 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);
Pointer AddFontMemResourceEx(
Pointer pFileView, // void*
int cjSize, // DWORD
Pointer pvResrved, // void* optional
IntByReference pNumFonts // DWORD*
);
}@[Link("gdi32")]
lib LibGDI32
fun AddFontMemResourceEx = AddFontMemResourceEx(
pFileView : Void*, # void*
cjSize : UInt32, # DWORD
pvResrved : Void*, # void* optional
pNumFonts : UInt32* # DWORD*
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef AddFontMemResourceExNative = Pointer<Void> Function(Pointer<Void>, Uint32, Pointer<Void>, Pointer<Uint32>);
typedef AddFontMemResourceExDart = Pointer<Void> Function(Pointer<Void>, int, Pointer<Void>, Pointer<Uint32>);
final AddFontMemResourceEx = DynamicLibrary.open('GDI32.dll')
.lookupFunction<AddFontMemResourceExNative, AddFontMemResourceExDart>('AddFontMemResourceEx');
// pFileView : void* -> Pointer<Void>
// cjSize : DWORD -> Uint32
// pvResrved : void* optional -> Pointer<Void>
// pNumFonts : DWORD* -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function AddFontMemResourceEx(
pFileView: Pointer; // void*
cjSize: DWORD; // DWORD
pvResrved: Pointer; // void* optional
pNumFonts: Pointer // DWORD*
): THandle; stdcall;
external 'GDI32.dll' name 'AddFontMemResourceEx';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "AddFontMemResourceEx"
c_AddFontMemResourceEx :: Ptr () -> Word32 -> Ptr () -> Ptr Word32 -> IO (Ptr ())
-- pFileView : void* -> Ptr ()
-- cjSize : DWORD -> Word32
-- pvResrved : void* optional -> Ptr ()
-- pNumFonts : DWORD* -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let addfontmemresourceex =
foreign "AddFontMemResourceEx"
((ptr void) @-> uint32_t @-> (ptr void) @-> (ptr uint32_t) @-> returning (ptr void))
(* pFileView : void* -> (ptr void) *)
(* cjSize : DWORD -> uint32_t *)
(* pvResrved : void* optional -> (ptr void) *)
(* pNumFonts : DWORD* -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("AddFontMemResourceEx" add-font-mem-resource-ex :convention :stdcall) :pointer
(p-file-view :pointer) ; void*
(cj-size :uint32) ; DWORD
(pv-resrved :pointer) ; void* optional
(p-num-fonts :pointer)) ; DWORD*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $AddFontMemResourceEx = Win32::API::More->new('GDI32',
'HANDLE AddFontMemResourceEx(LPVOID pFileView, DWORD cjSize, LPVOID pvResrved, LPVOID pNumFonts)');
# my $ret = $AddFontMemResourceEx->Call($pFileView, $cjSize, $pvResrved, $pNumFonts);
# pFileView : void* -> LPVOID
# cjSize : DWORD -> DWORD
# pvResrved : void* optional -> LPVOID
# pNumFonts : DWORD* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- s DESIGNVECTOR
- f RemoveFontMemResourceEx — メモリから追加したフォントリソースを削除する。