BeginUpdateResourceW
関数シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
HANDLE BeginUpdateResourceW(
LPCWSTR pFileName,
BOOL bDeleteExistingResources
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| pFileName | LPCWSTR | in | リソースを更新する対象のバイナリファイルです。アプリケーションはこのファイルへの書き込みアクセスを取得できる必要があり、pFileName が参照するファイルは現在実行中であってはなりません。pFileName がフルパスを指定していない場合、システムは現在のディレクトリでファイルを検索します。 |
| bDeleteExistingResources | BOOL | in | pFileName パラメーターの既存リソースを削除するかどうかを示します。このパラメーターが TRUE の場合、既存リソースは削除され、更新後のファイルには UpdateResource 関数で追加されたリソースのみが含まれます。このパラメーターが FALSE の場合、UpdateResource を使用して明示的に削除または置換されない限り、更新後のファイルには既存リソースが含まれます。 |
戻り値の型: HANDLE
公式ドキュメント
バイナリモジュール内のリソースを追加、削除、または置換するために UpdateResource 関数で使用できるハンドルを取得します。(Unicode)
戻り値
Type: HANDLE
関数が成功すると、戻り値は UpdateResource 関数および EndUpdateResource 関数で使用できるハンドルになります。指定されたファイルが PE でない場合、ファイルが存在しない場合、またはファイルを書き込み用に開けない場合、戻り値は NULL になります。拡張エラー情報を取得するには、GetLastError を呼び出します。
解説(Remarks)
この関数を呼び出す前にリソースファイルを読み込まないことが推奨されます。ただし、そのファイルが既に読み込まれている場合でも、エラーが返されることはありません。
Resource Configuration(RC Config)データを含むファイル、すなわち LN ファイルおよび関連する .mui ファイルでは、リソースの更新にいくつかの制限があります。これらのファイルで更新が許可されるリソースの種類の詳細は、UpdateResource 関数の「解説」セクションに記載されています。
この関数は、コードとリソースの両方を含むモジュール内のリソースを更新できます。前述のとおり、いずれも RC Config データを含む LN ファイルおよび .mui ファイルにおけるリソース更新には制限があります。制限の詳細は UpdateResource 関数のリファレンスに記載されています。
Examples
例については、Updating Resources を参照してください。
winbase.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして BeginUpdateResource を定義します。エンコーディング非依存のエイリアスの使用と、エンコーディング非依存でないコードを混在させると、コンパイルエラーや実行時エラーを引き起こす不整合が生じる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
HANDLE BeginUpdateResourceW(
LPCWSTR pFileName,
BOOL bDeleteExistingResources
);[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr BeginUpdateResourceW(
[MarshalAs(UnmanagedType.LPWStr)] string pFileName, // LPCWSTR
bool bDeleteExistingResources // BOOL
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function BeginUpdateResourceW(
<MarshalAs(UnmanagedType.LPWStr)> pFileName As String, ' LPCWSTR
bDeleteExistingResources As Boolean ' BOOL
) As IntPtr
End Function' pFileName : LPCWSTR
' bDeleteExistingResources : BOOL
Declare PtrSafe Function BeginUpdateResourceW Lib "kernel32" ( _
ByVal pFileName As LongPtr, _
ByVal bDeleteExistingResources As Long) As LongPtr
' 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
BeginUpdateResourceW = ctypes.windll.kernel32.BeginUpdateResourceW
BeginUpdateResourceW.restype = ctypes.c_void_p
BeginUpdateResourceW.argtypes = [
wintypes.LPCWSTR, # pFileName : LPCWSTR
wintypes.BOOL, # bDeleteExistingResources : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
BeginUpdateResourceW = Fiddle::Function.new(
lib['BeginUpdateResourceW'],
[
Fiddle::TYPE_VOIDP, # pFileName : LPCWSTR
Fiddle::TYPE_INT, # bDeleteExistingResources : BOOL
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn BeginUpdateResourceW(
pFileName: *const u16, // LPCWSTR
bDeleteExistingResources: i32 // BOOL
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr BeginUpdateResourceW([MarshalAs(UnmanagedType.LPWStr)] string pFileName, bool bDeleteExistingResources);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_BeginUpdateResourceW' -Namespace Win32 -PassThru
# $api::BeginUpdateResourceW(pFileName, bDeleteExistingResources)#uselib "KERNEL32.dll"
#func global BeginUpdateResourceW "BeginUpdateResourceW" wptr, wptr
; BeginUpdateResourceW pFileName, bDeleteExistingResources ; 戻り値は stat
; pFileName : LPCWSTR -> "wptr"
; bDeleteExistingResources : BOOL -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global BeginUpdateResourceW "BeginUpdateResourceW" wstr, int
; res = BeginUpdateResourceW(pFileName, bDeleteExistingResources)
; pFileName : LPCWSTR -> "wstr"
; bDeleteExistingResources : BOOL -> "int"; HANDLE BeginUpdateResourceW(LPCWSTR pFileName, BOOL bDeleteExistingResources)
#uselib "KERNEL32.dll"
#cfunc global BeginUpdateResourceW "BeginUpdateResourceW" wstr, int
; res = BeginUpdateResourceW(pFileName, bDeleteExistingResources)
; pFileName : LPCWSTR -> "wstr"
; bDeleteExistingResources : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procBeginUpdateResourceW = kernel32.NewProc("BeginUpdateResourceW")
)
// pFileName (LPCWSTR), bDeleteExistingResources (BOOL)
r1, _, err := procBeginUpdateResourceW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pFileName))),
uintptr(bDeleteExistingResources),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction BeginUpdateResourceW(
pFileName: PWideChar; // LPCWSTR
bDeleteExistingResources: BOOL // BOOL
): THandle; stdcall;
external 'KERNEL32.dll' name 'BeginUpdateResourceW';result := DllCall("KERNEL32\BeginUpdateResourceW"
, "WStr", pFileName ; LPCWSTR
, "Int", bDeleteExistingResources ; BOOL
, "Ptr") ; return: HANDLE●BeginUpdateResourceW(pFileName, bDeleteExistingResources) = DLL("KERNEL32.dll", "void* BeginUpdateResourceW(char*, bool)")
# 呼び出し: BeginUpdateResourceW(pFileName, bDeleteExistingResources)
# pFileName : LPCWSTR -> "char*"
# bDeleteExistingResources : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "kernel32" fn BeginUpdateResourceW(
pFileName: [*c]const u16, // LPCWSTR
bDeleteExistingResources: i32 // BOOL
) callconv(std.os.windows.WINAPI) ?*anyopaque;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc BeginUpdateResourceW(
pFileName: WideCString, # LPCWSTR
bDeleteExistingResources: int32 # BOOL
): pointer {.importc: "BeginUpdateResourceW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "kernel32");
extern(Windows)
void* BeginUpdateResourceW(
const(wchar)* pFileName, // LPCWSTR
int bDeleteExistingResources // BOOL
);ccall((:BeginUpdateResourceW, "KERNEL32.dll"), stdcall, Ptr{Cvoid},
(Cwstring, Int32),
pFileName, bDeleteExistingResources)
# pFileName : LPCWSTR -> Cwstring
# bDeleteExistingResources : BOOL -> Int32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
void* BeginUpdateResourceW(
const uint16_t* pFileName,
int32_t bDeleteExistingResources);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.BeginUpdateResourceW(pFileName, bDeleteExistingResources)
-- pFileName : LPCWSTR
-- bDeleteExistingResources : BOOL
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const BeginUpdateResourceW = lib.func('__stdcall', 'BeginUpdateResourceW', 'void *', ['str16', 'int32_t']);
// BeginUpdateResourceW(pFileName, bDeleteExistingResources)
// pFileName : LPCWSTR -> 'str16'
// bDeleteExistingResources : BOOL -> 'int32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
BeginUpdateResourceW: { parameters: ["buffer", "i32"], result: "pointer" },
});
// lib.symbols.BeginUpdateResourceW(pFileName, bDeleteExistingResources)
// pFileName : LPCWSTR -> "buffer"
// bDeleteExistingResources : BOOL -> "i32"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* BeginUpdateResourceW(
const uint16_t* pFileName,
int32_t bDeleteExistingResources);
C, "KERNEL32.dll");
// $ffi->BeginUpdateResourceW(pFileName, bDeleteExistingResources);
// pFileName : LPCWSTR
// bDeleteExistingResources : BOOL
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
Pointer BeginUpdateResourceW(
WString pFileName, // LPCWSTR
boolean bDeleteExistingResources // BOOL
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("kernel32")]
lib LibKERNEL32
fun BeginUpdateResourceW = BeginUpdateResourceW(
pFileName : UInt16*, # LPCWSTR
bDeleteExistingResources : Int32 # BOOL
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef BeginUpdateResourceWNative = Pointer<Void> Function(Pointer<Utf16>, Int32);
typedef BeginUpdateResourceWDart = Pointer<Void> Function(Pointer<Utf16>, int);
final BeginUpdateResourceW = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<BeginUpdateResourceWNative, BeginUpdateResourceWDart>('BeginUpdateResourceW');
// pFileName : LPCWSTR -> Pointer<Utf16>
// bDeleteExistingResources : BOOL -> Int32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function BeginUpdateResourceW(
pFileName: PWideChar; // LPCWSTR
bDeleteExistingResources: BOOL // BOOL
): THandle; stdcall;
external 'KERNEL32.dll' name 'BeginUpdateResourceW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "BeginUpdateResourceW"
c_BeginUpdateResourceW :: CWString -> CInt -> IO (Ptr ())
-- pFileName : LPCWSTR -> CWString
-- bDeleteExistingResources : BOOL -> CInt
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let beginupdateresourcew =
foreign "BeginUpdateResourceW"
((ptr uint16_t) @-> int32_t @-> returning (ptr void))
(* pFileName : LPCWSTR -> (ptr uint16_t) *)
(* bDeleteExistingResources : BOOL -> int32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("BeginUpdateResourceW" begin-update-resource-w :convention :stdcall) :pointer
(p-file-name (:string :encoding :utf-16le)) ; LPCWSTR
(b-delete-existing-resources :int32)) ; BOOL
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $BeginUpdateResourceW = Win32::API::More->new('KERNEL32',
'HANDLE BeginUpdateResourceW(LPCWSTR pFileName, BOOL bDeleteExistingResources)');
# my $ret = $BeginUpdateResourceW->Call($pFileName, $bDeleteExistingResources);
# pFileName : LPCWSTR -> LPCWSTR
# bDeleteExistingResources : BOOL -> BOOL
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f BeginUpdateResourceA (ANSI版) — 実行ファイルのリソース更新をANSI名で開始する。
- f EndUpdateResourceW — リソース更新を確定または破棄して終了する。
- f UpdateResourceW — 実行ファイル内のリソースをUnicode指定で更新する。