Win32 API 日本語リファレンス
ホームSystem.ApplicationInstallationAndServicing › TestApplyPatchToFileByBuffers

TestApplyPatchToFileByBuffers

関数
メモリバッファ上のパッチが適用可能かを検証する。
DLLmspatcha.dll呼出規約winapi

シグネチャ

// mspatcha.dll
#include <windows.h>

BOOL TestApplyPatchToFileByBuffers(
    BYTE* PatchFileBuffer,
    DWORD PatchFileSize,
    BYTE* OldFileBuffer,   // optional
    DWORD OldFileSize,
    DWORD* NewFileSize,   // optional
    DWORD ApplyOptionFlags
);

パラメーター

名前方向
PatchFileBufferBYTE*in
PatchFileSizeDWORDin
OldFileBufferBYTE*inoptional
OldFileSizeDWORDin
NewFileSizeDWORD*outoptional
ApplyOptionFlagsDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// mspatcha.dll
#include <windows.h>

BOOL TestApplyPatchToFileByBuffers(
    BYTE* PatchFileBuffer,
    DWORD PatchFileSize,
    BYTE* OldFileBuffer,   // optional
    DWORD OldFileSize,
    DWORD* NewFileSize,   // optional
    DWORD ApplyOptionFlags
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll", ExactSpelling = true)]
static extern bool TestApplyPatchToFileByBuffers(
    IntPtr PatchFileBuffer,   // BYTE*
    uint PatchFileSize,   // DWORD
    IntPtr OldFileBuffer,   // BYTE* optional
    uint OldFileSize,   // DWORD
    IntPtr NewFileSize,   // DWORD* optional, out
    uint ApplyOptionFlags   // DWORD
);
<DllImport("mspatcha.dll", ExactSpelling:=True)>
Public Shared Function TestApplyPatchToFileByBuffers(
    PatchFileBuffer As IntPtr,   ' BYTE*
    PatchFileSize As UInteger,   ' DWORD
    OldFileBuffer As IntPtr,   ' BYTE* optional
    OldFileSize As UInteger,   ' DWORD
    NewFileSize As IntPtr,   ' DWORD* optional, out
    ApplyOptionFlags As UInteger   ' DWORD
) As Boolean
End Function
' PatchFileBuffer : BYTE*
' PatchFileSize : DWORD
' OldFileBuffer : BYTE* optional
' OldFileSize : DWORD
' NewFileSize : DWORD* optional, out
' ApplyOptionFlags : DWORD
Declare PtrSafe Function TestApplyPatchToFileByBuffers Lib "mspatcha" ( _
    ByVal PatchFileBuffer As LongPtr, _
    ByVal PatchFileSize As Long, _
    ByVal OldFileBuffer As LongPtr, _
    ByVal OldFileSize As Long, _
    ByVal NewFileSize 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

TestApplyPatchToFileByBuffers = ctypes.windll.mspatcha.TestApplyPatchToFileByBuffers
TestApplyPatchToFileByBuffers.restype = wintypes.BOOL
TestApplyPatchToFileByBuffers.argtypes = [
    ctypes.POINTER(ctypes.c_ubyte),  # PatchFileBuffer : BYTE*
    wintypes.DWORD,  # PatchFileSize : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # OldFileBuffer : BYTE* optional
    wintypes.DWORD,  # OldFileSize : DWORD
    ctypes.POINTER(wintypes.DWORD),  # NewFileSize : DWORD* optional, out
    wintypes.DWORD,  # ApplyOptionFlags : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('mspatcha.dll')
TestApplyPatchToFileByBuffers = Fiddle::Function.new(
  lib['TestApplyPatchToFileByBuffers'],
  [
    Fiddle::TYPE_VOIDP,  # PatchFileBuffer : BYTE*
    -Fiddle::TYPE_INT,  # PatchFileSize : DWORD
    Fiddle::TYPE_VOIDP,  # OldFileBuffer : BYTE* optional
    -Fiddle::TYPE_INT,  # OldFileSize : DWORD
    Fiddle::TYPE_VOIDP,  # NewFileSize : DWORD* optional, out
    -Fiddle::TYPE_INT,  # ApplyOptionFlags : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "mspatcha")]
extern "system" {
    fn TestApplyPatchToFileByBuffers(
        PatchFileBuffer: *mut u8,  // BYTE*
        PatchFileSize: u32,  // DWORD
        OldFileBuffer: *mut u8,  // BYTE* optional
        OldFileSize: u32,  // DWORD
        NewFileSize: *mut u32,  // DWORD* optional, out
        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 TestApplyPatchToFileByBuffers(IntPtr PatchFileBuffer, uint PatchFileSize, IntPtr OldFileBuffer, uint OldFileSize, IntPtr NewFileSize, uint ApplyOptionFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mspatcha_TestApplyPatchToFileByBuffers' -Namespace Win32 -PassThru
# $api::TestApplyPatchToFileByBuffers(PatchFileBuffer, PatchFileSize, OldFileBuffer, OldFileSize, NewFileSize, ApplyOptionFlags)
#uselib "mspatcha.dll"
#func global TestApplyPatchToFileByBuffers "TestApplyPatchToFileByBuffers" sptr, sptr, sptr, sptr, sptr, sptr
; TestApplyPatchToFileByBuffers varptr(PatchFileBuffer), PatchFileSize, varptr(OldFileBuffer), OldFileSize, varptr(NewFileSize), ApplyOptionFlags   ; 戻り値は stat
; PatchFileBuffer : BYTE* -> "sptr"
; PatchFileSize : DWORD -> "sptr"
; OldFileBuffer : BYTE* optional -> "sptr"
; OldFileSize : DWORD -> "sptr"
; NewFileSize : DWORD* optional, out -> "sptr"
; ApplyOptionFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "mspatcha.dll"
#cfunc global TestApplyPatchToFileByBuffers "TestApplyPatchToFileByBuffers" var, int, var, int, var, int
; res = TestApplyPatchToFileByBuffers(PatchFileBuffer, PatchFileSize, OldFileBuffer, OldFileSize, NewFileSize, ApplyOptionFlags)
; PatchFileBuffer : BYTE* -> "var"
; PatchFileSize : DWORD -> "int"
; OldFileBuffer : BYTE* optional -> "var"
; OldFileSize : DWORD -> "int"
; NewFileSize : DWORD* optional, out -> "var"
; ApplyOptionFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL TestApplyPatchToFileByBuffers(BYTE* PatchFileBuffer, DWORD PatchFileSize, BYTE* OldFileBuffer, DWORD OldFileSize, DWORD* NewFileSize, DWORD ApplyOptionFlags)
#uselib "mspatcha.dll"
#cfunc global TestApplyPatchToFileByBuffers "TestApplyPatchToFileByBuffers" var, int, var, int, var, int
; res = TestApplyPatchToFileByBuffers(PatchFileBuffer, PatchFileSize, OldFileBuffer, OldFileSize, NewFileSize, ApplyOptionFlags)
; PatchFileBuffer : BYTE* -> "var"
; PatchFileSize : DWORD -> "int"
; OldFileBuffer : BYTE* optional -> "var"
; OldFileSize : DWORD -> "int"
; NewFileSize : DWORD* optional, out -> "var"
; ApplyOptionFlags : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mspatcha = windows.NewLazySystemDLL("mspatcha.dll")
	procTestApplyPatchToFileByBuffers = mspatcha.NewProc("TestApplyPatchToFileByBuffers")
)

// PatchFileBuffer (BYTE*), PatchFileSize (DWORD), OldFileBuffer (BYTE* optional), OldFileSize (DWORD), NewFileSize (DWORD* optional, out), ApplyOptionFlags (DWORD)
r1, _, err := procTestApplyPatchToFileByBuffers.Call(
	uintptr(PatchFileBuffer),
	uintptr(PatchFileSize),
	uintptr(OldFileBuffer),
	uintptr(OldFileSize),
	uintptr(NewFileSize),
	uintptr(ApplyOptionFlags),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function TestApplyPatchToFileByBuffers(
  PatchFileBuffer: Pointer;   // BYTE*
  PatchFileSize: DWORD;   // DWORD
  OldFileBuffer: Pointer;   // BYTE* optional
  OldFileSize: DWORD;   // DWORD
  NewFileSize: Pointer;   // DWORD* optional, out
  ApplyOptionFlags: DWORD   // DWORD
): BOOL; stdcall;
  external 'mspatcha.dll' name 'TestApplyPatchToFileByBuffers';
result := DllCall("mspatcha\TestApplyPatchToFileByBuffers"
    , "Ptr", PatchFileBuffer   ; BYTE*
    , "UInt", PatchFileSize   ; DWORD
    , "Ptr", OldFileBuffer   ; BYTE* optional
    , "UInt", OldFileSize   ; DWORD
    , "Ptr", NewFileSize   ; DWORD* optional, out
    , "UInt", ApplyOptionFlags   ; DWORD
    , "Int")   ; return: BOOL
●TestApplyPatchToFileByBuffers(PatchFileBuffer, PatchFileSize, OldFileBuffer, OldFileSize, NewFileSize, ApplyOptionFlags) = DLL("mspatcha.dll", "bool TestApplyPatchToFileByBuffers(void*, dword, void*, dword, void*, dword)")
# 呼び出し: TestApplyPatchToFileByBuffers(PatchFileBuffer, PatchFileSize, OldFileBuffer, OldFileSize, NewFileSize, ApplyOptionFlags)
# PatchFileBuffer : BYTE* -> "void*"
# PatchFileSize : DWORD -> "dword"
# OldFileBuffer : BYTE* optional -> "void*"
# OldFileSize : DWORD -> "dword"
# NewFileSize : DWORD* optional, out -> "void*"
# ApplyOptionFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。