ホーム › System.ApplicationInstallationAndServicing › ApplyPatchToFileByHandles
ApplyPatchToFileByHandles
関数ハンドル経由で旧ファイルにパッチを適用して新ファイルを生成する。
シグネチャ
// mspatcha.dll
#include <windows.h>
BOOL ApplyPatchToFileByHandles(
HANDLE PatchFileHandle,
HANDLE OldFileHandle, // optional
HANDLE NewFileHandle,
DWORD ApplyOptionFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| PatchFileHandle | HANDLE | in | 適用するパッチファイルのハンドル。読み取り可能で開く。 |
| OldFileHandle | HANDLE | inoptional | パッチ適用先となる旧ファイルのハンドル。読み取り可能で開く。 |
| NewFileHandle | HANDLE | in | 適用結果を書き込む新ファイルのハンドル。書き込み可能で開く。 |
| ApplyOptionFlags | DWORD | in | 適用動作を制御するフラグ。APPLY_OPTION_* の組み合わせを指定する。 |
戻り値の型: BOOL
各言語での呼び出し定義
// mspatcha.dll
#include <windows.h>
BOOL ApplyPatchToFileByHandles(
HANDLE PatchFileHandle,
HANDLE OldFileHandle, // optional
HANDLE NewFileHandle,
DWORD ApplyOptionFlags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll", ExactSpelling = true)]
static extern bool ApplyPatchToFileByHandles(
IntPtr PatchFileHandle, // HANDLE
IntPtr OldFileHandle, // HANDLE optional
IntPtr NewFileHandle, // HANDLE
uint ApplyOptionFlags // DWORD
);<DllImport("mspatcha.dll", ExactSpelling:=True)>
Public Shared Function ApplyPatchToFileByHandles(
PatchFileHandle As IntPtr, ' HANDLE
OldFileHandle As IntPtr, ' HANDLE optional
NewFileHandle As IntPtr, ' HANDLE
ApplyOptionFlags As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' PatchFileHandle : HANDLE
' OldFileHandle : HANDLE optional
' NewFileHandle : HANDLE
' ApplyOptionFlags : DWORD
Declare PtrSafe Function ApplyPatchToFileByHandles Lib "mspatcha" ( _
ByVal PatchFileHandle As LongPtr, _
ByVal OldFileHandle As LongPtr, _
ByVal NewFileHandle As LongPtr, _
ByVal ApplyOptionFlags As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ApplyPatchToFileByHandles = ctypes.windll.mspatcha.ApplyPatchToFileByHandles
ApplyPatchToFileByHandles.restype = wintypes.BOOL
ApplyPatchToFileByHandles.argtypes = [
wintypes.HANDLE, # PatchFileHandle : HANDLE
wintypes.HANDLE, # OldFileHandle : HANDLE optional
wintypes.HANDLE, # NewFileHandle : HANDLE
wintypes.DWORD, # ApplyOptionFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mspatcha.dll')
ApplyPatchToFileByHandles = Fiddle::Function.new(
lib['ApplyPatchToFileByHandles'],
[
Fiddle::TYPE_VOIDP, # PatchFileHandle : HANDLE
Fiddle::TYPE_VOIDP, # OldFileHandle : HANDLE optional
Fiddle::TYPE_VOIDP, # NewFileHandle : HANDLE
-Fiddle::TYPE_INT, # ApplyOptionFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "mspatcha")]
extern "system" {
fn ApplyPatchToFileByHandles(
PatchFileHandle: *mut core::ffi::c_void, // HANDLE
OldFileHandle: *mut core::ffi::c_void, // HANDLE optional
NewFileHandle: *mut core::ffi::c_void, // HANDLE
ApplyOptionFlags: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll")]
public static extern bool ApplyPatchToFileByHandles(IntPtr PatchFileHandle, IntPtr OldFileHandle, IntPtr NewFileHandle, uint ApplyOptionFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mspatcha_ApplyPatchToFileByHandles' -Namespace Win32 -PassThru
# $api::ApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags)#uselib "mspatcha.dll"
#func global ApplyPatchToFileByHandles "ApplyPatchToFileByHandles" sptr, sptr, sptr, sptr
; ApplyPatchToFileByHandles PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags ; 戻り値は stat
; PatchFileHandle : HANDLE -> "sptr"
; OldFileHandle : HANDLE optional -> "sptr"
; NewFileHandle : HANDLE -> "sptr"
; ApplyOptionFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "mspatcha.dll"
#cfunc global ApplyPatchToFileByHandles "ApplyPatchToFileByHandles" sptr, sptr, sptr, int
; res = ApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags)
; PatchFileHandle : HANDLE -> "sptr"
; OldFileHandle : HANDLE optional -> "sptr"
; NewFileHandle : HANDLE -> "sptr"
; ApplyOptionFlags : DWORD -> "int"; BOOL ApplyPatchToFileByHandles(HANDLE PatchFileHandle, HANDLE OldFileHandle, HANDLE NewFileHandle, DWORD ApplyOptionFlags)
#uselib "mspatcha.dll"
#cfunc global ApplyPatchToFileByHandles "ApplyPatchToFileByHandles" intptr, intptr, intptr, int
; res = ApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags)
; PatchFileHandle : HANDLE -> "intptr"
; OldFileHandle : HANDLE optional -> "intptr"
; NewFileHandle : HANDLE -> "intptr"
; ApplyOptionFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mspatcha = windows.NewLazySystemDLL("mspatcha.dll")
procApplyPatchToFileByHandles = mspatcha.NewProc("ApplyPatchToFileByHandles")
)
// PatchFileHandle (HANDLE), OldFileHandle (HANDLE optional), NewFileHandle (HANDLE), ApplyOptionFlags (DWORD)
r1, _, err := procApplyPatchToFileByHandles.Call(
uintptr(PatchFileHandle),
uintptr(OldFileHandle),
uintptr(NewFileHandle),
uintptr(ApplyOptionFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction ApplyPatchToFileByHandles(
PatchFileHandle: THandle; // HANDLE
OldFileHandle: THandle; // HANDLE optional
NewFileHandle: THandle; // HANDLE
ApplyOptionFlags: DWORD // DWORD
): BOOL; stdcall;
external 'mspatcha.dll' name 'ApplyPatchToFileByHandles';result := DllCall("mspatcha\ApplyPatchToFileByHandles"
, "Ptr", PatchFileHandle ; HANDLE
, "Ptr", OldFileHandle ; HANDLE optional
, "Ptr", NewFileHandle ; HANDLE
, "UInt", ApplyOptionFlags ; DWORD
, "Int") ; return: BOOL●ApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags) = DLL("mspatcha.dll", "bool ApplyPatchToFileByHandles(void*, void*, void*, dword)")
# 呼び出し: ApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags)
# PatchFileHandle : HANDLE -> "void*"
# OldFileHandle : HANDLE optional -> "void*"
# NewFileHandle : HANDLE -> "void*"
# ApplyOptionFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mspatcha" fn ApplyPatchToFileByHandles(
PatchFileHandle: ?*anyopaque, // HANDLE
OldFileHandle: ?*anyopaque, // HANDLE optional
NewFileHandle: ?*anyopaque, // HANDLE
ApplyOptionFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc ApplyPatchToFileByHandles(
PatchFileHandle: pointer, # HANDLE
OldFileHandle: pointer, # HANDLE optional
NewFileHandle: pointer, # HANDLE
ApplyOptionFlags: uint32 # DWORD
): int32 {.importc: "ApplyPatchToFileByHandles", stdcall, dynlib: "mspatcha.dll".}pragma(lib, "mspatcha");
extern(Windows)
int ApplyPatchToFileByHandles(
void* PatchFileHandle, // HANDLE
void* OldFileHandle, // HANDLE optional
void* NewFileHandle, // HANDLE
uint ApplyOptionFlags // DWORD
);ccall((:ApplyPatchToFileByHandles, "mspatcha.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}, UInt32),
PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags)
# PatchFileHandle : HANDLE -> Ptr{Cvoid}
# OldFileHandle : HANDLE optional -> Ptr{Cvoid}
# NewFileHandle : HANDLE -> Ptr{Cvoid}
# ApplyOptionFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t ApplyPatchToFileByHandles(
void* PatchFileHandle,
void* OldFileHandle,
void* NewFileHandle,
uint32_t ApplyOptionFlags);
]]
local mspatcha = ffi.load("mspatcha")
-- mspatcha.ApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags)
-- PatchFileHandle : HANDLE
-- OldFileHandle : HANDLE optional
-- NewFileHandle : HANDLE
-- ApplyOptionFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('mspatcha.dll');
const ApplyPatchToFileByHandles = lib.func('__stdcall', 'ApplyPatchToFileByHandles', 'int32_t', ['void *', 'void *', 'void *', 'uint32_t']);
// ApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags)
// PatchFileHandle : HANDLE -> 'void *'
// OldFileHandle : HANDLE optional -> 'void *'
// NewFileHandle : HANDLE -> 'void *'
// ApplyOptionFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("mspatcha.dll", {
ApplyPatchToFileByHandles: { parameters: ["pointer", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.ApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags)
// PatchFileHandle : HANDLE -> "pointer"
// OldFileHandle : HANDLE optional -> "pointer"
// NewFileHandle : HANDLE -> "pointer"
// ApplyOptionFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t ApplyPatchToFileByHandles(
void* PatchFileHandle,
void* OldFileHandle,
void* NewFileHandle,
uint32_t ApplyOptionFlags);
C, "mspatcha.dll");
// $ffi->ApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, NewFileHandle, ApplyOptionFlags);
// PatchFileHandle : HANDLE
// OldFileHandle : HANDLE optional
// NewFileHandle : HANDLE
// ApplyOptionFlags : 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 Mspatcha extends StdCallLibrary {
Mspatcha INSTANCE = Native.load("mspatcha", Mspatcha.class);
boolean ApplyPatchToFileByHandles(
Pointer PatchFileHandle, // HANDLE
Pointer OldFileHandle, // HANDLE optional
Pointer NewFileHandle, // HANDLE
int ApplyOptionFlags // DWORD
);
}@[Link("mspatcha")]
lib Libmspatcha
fun ApplyPatchToFileByHandles = ApplyPatchToFileByHandles(
PatchFileHandle : Void*, # HANDLE
OldFileHandle : Void*, # HANDLE optional
NewFileHandle : Void*, # HANDLE
ApplyOptionFlags : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ApplyPatchToFileByHandlesNative = Int32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Uint32);
typedef ApplyPatchToFileByHandlesDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, int);
final ApplyPatchToFileByHandles = DynamicLibrary.open('mspatcha.dll')
.lookupFunction<ApplyPatchToFileByHandlesNative, ApplyPatchToFileByHandlesDart>('ApplyPatchToFileByHandles');
// PatchFileHandle : HANDLE -> Pointer<Void>
// OldFileHandle : HANDLE optional -> Pointer<Void>
// NewFileHandle : HANDLE -> Pointer<Void>
// ApplyOptionFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ApplyPatchToFileByHandles(
PatchFileHandle: THandle; // HANDLE
OldFileHandle: THandle; // HANDLE optional
NewFileHandle: THandle; // HANDLE
ApplyOptionFlags: DWORD // DWORD
): BOOL; stdcall;
external 'mspatcha.dll' name 'ApplyPatchToFileByHandles';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ApplyPatchToFileByHandles"
c_ApplyPatchToFileByHandles :: Ptr () -> Ptr () -> Ptr () -> Word32 -> IO CInt
-- PatchFileHandle : HANDLE -> Ptr ()
-- OldFileHandle : HANDLE optional -> Ptr ()
-- NewFileHandle : HANDLE -> Ptr ()
-- ApplyOptionFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let applypatchtofilebyhandles =
foreign "ApplyPatchToFileByHandles"
((ptr void) @-> (ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* PatchFileHandle : HANDLE -> (ptr void) *)
(* OldFileHandle : HANDLE optional -> (ptr void) *)
(* NewFileHandle : HANDLE -> (ptr void) *)
(* ApplyOptionFlags : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mspatcha (t "mspatcha.dll"))
(cffi:use-foreign-library mspatcha)
(cffi:defcfun ("ApplyPatchToFileByHandles" apply-patch-to-file-by-handles :convention :stdcall) :int32
(patch-file-handle :pointer) ; HANDLE
(old-file-handle :pointer) ; HANDLE optional
(new-file-handle :pointer) ; HANDLE
(apply-option-flags :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ApplyPatchToFileByHandles = Win32::API::More->new('mspatcha',
'BOOL ApplyPatchToFileByHandles(HANDLE PatchFileHandle, HANDLE OldFileHandle, HANDLE NewFileHandle, DWORD ApplyOptionFlags)');
# my $ret = $ApplyPatchToFileByHandles->Call($PatchFileHandle, $OldFileHandle, $NewFileHandle, $ApplyOptionFlags);
# PatchFileHandle : HANDLE -> HANDLE
# OldFileHandle : HANDLE optional -> HANDLE
# NewFileHandle : HANDLE -> HANDLE
# ApplyOptionFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f ApplyPatchToFileByHandlesEx — ハンドルと進捗コールバックで旧ファイルにパッチを適用する。