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

CreateScalableFontResourceW

関数
スケーラブルフォント用のリソースファイルを作成する。
DLLGDI32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL CreateScalableFontResourceW(
    DWORD fdwHidden,
    LPCWSTR lpszFont,
    LPCWSTR lpszFile,
    LPCWSTR lpszPath   // optional
);

パラメーター

名前方向説明
fdwHiddenDWORDin

フォントが読み取り専用フォントかどうかを指定します。このパラメーターには、次のいずれかの値を指定できます。

意味
0
フォントは読み取り/書き込み権限を持ちます。
1
フォントは読み取り専用権限を持ち、システム内の他のアプリケーションから隠されます。このフラグが設定されている場合、フォントは EnumFonts 関数や EnumFontFamilies 関数によって列挙されません。
lpszFontLPCWSTRin作成するフォントリソースファイルの名前を指定する、null で終わる文字列へのポインター。このパラメーターが既存のフォントリソースファイルを指定している場合、関数は失敗します。
lpszFileLPCWSTRinフォントリソースファイルを作成するためにこの関数が使用するスケーラブルフォントファイルの名前を指定する、null で終わる文字列へのポインター。
lpszPathLPCWSTRinoptionalスケーラブルフォントファイルへのパスを指定する、null で終わる文字列へのポインター。

戻り値の型: BOOL

公式ドキュメント

CreateScalableFontResource 関数は、スケーラブルフォント用のフォントリソースファイルを作成します。(Unicode)

戻り値

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

関数が失敗した場合、戻り値は 0 です。

lpszFontRes が既存のフォントファイルを指定している場合、GetLastErrorERROR_FILE_EXISTS を返します。

解説(Remarks)

CreateScalableFontResource 関数は、TrueType フォントをインストールするアプリケーションによって使用されます。アプリケーションは CreateScalableFontResource 関数を使用してフォントリソースファイル(通常は .fot のファイル名拡張子を持つ)を作成し、その後 AddFontResource 関数を使用してフォントをインストールします。TrueType フォントファイル(通常は .ttf のファイル名拡張子を持つ)は、AddFontResource 関数で使用するために、Windows ディレクトリの System サブディレクトリに置かれている必要があります。

CreateScalableFontResource 関数は、現在 TrueType テクノロジのスケーラブルフォントのみをサポートしています。

lpszFontFile パラメーターでファイル名と拡張子のみを指定する場合、lpszCurrentPath パラメーターでパスを指定する必要があります。lpszFontFile パラメーターでフルパスを指定する場合、lpszCurrentPath パラメーターは NULL または NULL へのポインターである必要があります。

lpszFontFile パラメーターにファイル名と拡張子のみが指定され、lpszCurrentPath パラメーターにパスが指定されている場合、lpszFontFile の文字列は、このリソースに属する .ttf ファイルとして .fot ファイルにコピーされます。AddFontResource 関数が呼び出されると、オペレーティングシステムは .ttf ファイルが System ディレクトリ(ネットワークインストールの場合はメインの Windows ディレクトリ)にコピーされていると想定します。lpszCurrentPath パラメーターにディレクトリ情報が含まれているため、CreateScalableFontResource 関数が呼び出される時点では .ttf ファイルがこのディレクトリに存在する必要はありません。この方法で作成されたリソースは絶対パス情報を含まないため、任意のインストール環境で使用できます。

lpszFontFile パラメーターにパスが指定され、lpszCurrentPath パラメーターに NULL が指定されている場合、lpszFontFile の文字列が .fot ファイルにコピーされます。この場合、AddFontResource 関数が呼び出されるとき、.ttf ファイルは CreateScalableFontResource 関数が呼び出された時点で lpszFontFile パラメーターに指定された場所に存在する必要があります。lpszCurrentPath パラメーターは必要ありません。この方法で作成されたリソースはパスとドライブへの絶対参照を含むため、.ttf ファイルが別の場所に移動された場合は機能しません。

メモ

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

出典・ライセンス: 上記「公式ドキュメント」の内容は 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 CreateScalableFontResourceW(
    DWORD fdwHidden,
    LPCWSTR lpszFont,
    LPCWSTR lpszFile,
    LPCWSTR lpszPath   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool CreateScalableFontResourceW(
    uint fdwHidden,   // DWORD
    [MarshalAs(UnmanagedType.LPWStr)] string lpszFont,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpszFile,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpszPath   // LPCWSTR optional
);
<DllImport("GDI32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateScalableFontResourceW(
    fdwHidden As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPWStr)> lpszFont As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpszFile As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpszPath As String   ' LPCWSTR optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' fdwHidden : DWORD
' lpszFont : LPCWSTR
' lpszFile : LPCWSTR
' lpszPath : LPCWSTR optional
Declare PtrSafe Function CreateScalableFontResourceW Lib "gdi32" ( _
    ByVal fdwHidden As Long, _
    ByVal lpszFont As LongPtr, _
    ByVal lpszFile As LongPtr, _
    ByVal lpszPath 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

CreateScalableFontResourceW = ctypes.windll.gdi32.CreateScalableFontResourceW
CreateScalableFontResourceW.restype = wintypes.BOOL
CreateScalableFontResourceW.argtypes = [
    wintypes.DWORD,  # fdwHidden : DWORD
    wintypes.LPCWSTR,  # lpszFont : LPCWSTR
    wintypes.LPCWSTR,  # lpszFile : LPCWSTR
    wintypes.LPCWSTR,  # lpszPath : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procCreateScalableFontResourceW = gdi32.NewProc("CreateScalableFontResourceW")
)

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

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

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

foreign import stdcall safe "CreateScalableFontResourceW"
  c_CreateScalableFontResourceW :: Word32 -> CWString -> CWString -> CWString -> IO CInt
-- fdwHidden : DWORD -> Word32
-- lpszFont : LPCWSTR -> CWString
-- lpszFile : LPCWSTR -> CWString
-- lpszPath : LPCWSTR optional -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

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

(cffi:defcfun ("CreateScalableFontResourceW" create-scalable-font-resource-w :convention :stdcall) :int32
  (fdw-hidden :uint32)   ; DWORD
  (lpsz-font (:string :encoding :utf-16le))   ; LPCWSTR
  (lpsz-file (:string :encoding :utf-16le))   ; LPCWSTR
  (lpsz-path (:string :encoding :utf-16le)))   ; LPCWSTR optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateScalableFontResourceW = Win32::API::More->new('GDI32',
    'BOOL CreateScalableFontResourceW(DWORD fdwHidden, LPCWSTR lpszFont, LPCWSTR lpszFile, LPCWSTR lpszPath)');
# my $ret = $CreateScalableFontResourceW->Call($fdwHidden, $lpszFont, $lpszFile, $lpszPath);
# fdwHidden : DWORD -> DWORD
# lpszFont : LPCWSTR -> LPCWSTR
# lpszFile : LPCWSTR -> LPCWSTR
# lpszPath : LPCWSTR optional -> LPCWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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