ホーム › System.ApplicationInstallationAndServicing › TestApplyPatchToFileByHandles
TestApplyPatchToFileByHandles
関数ハンドル経由でパッチが適用可能かを検証する。
シグネチャ
// mspatcha.dll
#include <windows.h>
BOOL TestApplyPatchToFileByHandles(
HANDLE PatchFileHandle,
HANDLE OldFileHandle,
DWORD ApplyOptionFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| PatchFileHandle | HANDLE | in | 適用可否を検証するパッチファイルのハンドル。読み取り可能で開く。 |
| OldFileHandle | HANDLE | in | パッチ適用先となる旧ファイルのハンドル。読み取り可能で開く。 |
| ApplyOptionFlags | DWORD | in | 適用検証動作を制御するフラグ。APPLY_OPTION_* の組み合わせを指定する。 |
戻り値の型: BOOL
各言語での呼び出し定義
// mspatcha.dll
#include <windows.h>
BOOL TestApplyPatchToFileByHandles(
HANDLE PatchFileHandle,
HANDLE OldFileHandle,
DWORD ApplyOptionFlags
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll", ExactSpelling = true)]
static extern bool TestApplyPatchToFileByHandles(
IntPtr PatchFileHandle, // HANDLE
IntPtr OldFileHandle, // HANDLE
uint ApplyOptionFlags // DWORD
);<DllImport("mspatcha.dll", ExactSpelling:=True)>
Public Shared Function TestApplyPatchToFileByHandles(
PatchFileHandle As IntPtr, ' HANDLE
OldFileHandle As IntPtr, ' HANDLE
ApplyOptionFlags As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' PatchFileHandle : HANDLE
' OldFileHandle : HANDLE
' ApplyOptionFlags : DWORD
Declare PtrSafe Function TestApplyPatchToFileByHandles Lib "mspatcha" ( _
ByVal PatchFileHandle As LongPtr, _
ByVal OldFileHandle 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
TestApplyPatchToFileByHandles = ctypes.windll.mspatcha.TestApplyPatchToFileByHandles
TestApplyPatchToFileByHandles.restype = wintypes.BOOL
TestApplyPatchToFileByHandles.argtypes = [
wintypes.HANDLE, # PatchFileHandle : HANDLE
wintypes.HANDLE, # OldFileHandle : HANDLE
wintypes.DWORD, # ApplyOptionFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mspatcha.dll')
TestApplyPatchToFileByHandles = Fiddle::Function.new(
lib['TestApplyPatchToFileByHandles'],
[
Fiddle::TYPE_VOIDP, # PatchFileHandle : HANDLE
Fiddle::TYPE_VOIDP, # OldFileHandle : HANDLE
-Fiddle::TYPE_INT, # ApplyOptionFlags : DWORD
],
Fiddle::TYPE_INT)#[link(name = "mspatcha")]
extern "system" {
fn TestApplyPatchToFileByHandles(
PatchFileHandle: *mut core::ffi::c_void, // HANDLE
OldFileHandle: *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 TestApplyPatchToFileByHandles(IntPtr PatchFileHandle, IntPtr OldFileHandle, uint ApplyOptionFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mspatcha_TestApplyPatchToFileByHandles' -Namespace Win32 -PassThru
# $api::TestApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, ApplyOptionFlags)#uselib "mspatcha.dll"
#func global TestApplyPatchToFileByHandles "TestApplyPatchToFileByHandles" sptr, sptr, sptr
; TestApplyPatchToFileByHandles PatchFileHandle, OldFileHandle, ApplyOptionFlags ; 戻り値は stat
; PatchFileHandle : HANDLE -> "sptr"
; OldFileHandle : HANDLE -> "sptr"
; ApplyOptionFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "mspatcha.dll"
#cfunc global TestApplyPatchToFileByHandles "TestApplyPatchToFileByHandles" sptr, sptr, int
; res = TestApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, ApplyOptionFlags)
; PatchFileHandle : HANDLE -> "sptr"
; OldFileHandle : HANDLE -> "sptr"
; ApplyOptionFlags : DWORD -> "int"; BOOL TestApplyPatchToFileByHandles(HANDLE PatchFileHandle, HANDLE OldFileHandle, DWORD ApplyOptionFlags)
#uselib "mspatcha.dll"
#cfunc global TestApplyPatchToFileByHandles "TestApplyPatchToFileByHandles" intptr, intptr, int
; res = TestApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, ApplyOptionFlags)
; PatchFileHandle : HANDLE -> "intptr"
; OldFileHandle : HANDLE -> "intptr"
; ApplyOptionFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mspatcha = windows.NewLazySystemDLL("mspatcha.dll")
procTestApplyPatchToFileByHandles = mspatcha.NewProc("TestApplyPatchToFileByHandles")
)
// PatchFileHandle (HANDLE), OldFileHandle (HANDLE), ApplyOptionFlags (DWORD)
r1, _, err := procTestApplyPatchToFileByHandles.Call(
uintptr(PatchFileHandle),
uintptr(OldFileHandle),
uintptr(ApplyOptionFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction TestApplyPatchToFileByHandles(
PatchFileHandle: THandle; // HANDLE
OldFileHandle: THandle; // HANDLE
ApplyOptionFlags: DWORD // DWORD
): BOOL; stdcall;
external 'mspatcha.dll' name 'TestApplyPatchToFileByHandles';result := DllCall("mspatcha\TestApplyPatchToFileByHandles"
, "Ptr", PatchFileHandle ; HANDLE
, "Ptr", OldFileHandle ; HANDLE
, "UInt", ApplyOptionFlags ; DWORD
, "Int") ; return: BOOL●TestApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, ApplyOptionFlags) = DLL("mspatcha.dll", "bool TestApplyPatchToFileByHandles(void*, void*, dword)")
# 呼び出し: TestApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, ApplyOptionFlags)
# PatchFileHandle : HANDLE -> "void*"
# OldFileHandle : HANDLE -> "void*"
# ApplyOptionFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "mspatcha" fn TestApplyPatchToFileByHandles(
PatchFileHandle: ?*anyopaque, // HANDLE
OldFileHandle: ?*anyopaque, // HANDLE
ApplyOptionFlags: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc TestApplyPatchToFileByHandles(
PatchFileHandle: pointer, # HANDLE
OldFileHandle: pointer, # HANDLE
ApplyOptionFlags: uint32 # DWORD
): int32 {.importc: "TestApplyPatchToFileByHandles", stdcall, dynlib: "mspatcha.dll".}pragma(lib, "mspatcha");
extern(Windows)
int TestApplyPatchToFileByHandles(
void* PatchFileHandle, // HANDLE
void* OldFileHandle, // HANDLE
uint ApplyOptionFlags // DWORD
);ccall((:TestApplyPatchToFileByHandles, "mspatcha.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, UInt32),
PatchFileHandle, OldFileHandle, ApplyOptionFlags)
# PatchFileHandle : HANDLE -> Ptr{Cvoid}
# OldFileHandle : HANDLE -> Ptr{Cvoid}
# ApplyOptionFlags : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t TestApplyPatchToFileByHandles(
void* PatchFileHandle,
void* OldFileHandle,
uint32_t ApplyOptionFlags);
]]
local mspatcha = ffi.load("mspatcha")
-- mspatcha.TestApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, ApplyOptionFlags)
-- PatchFileHandle : HANDLE
-- OldFileHandle : HANDLE
-- ApplyOptionFlags : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('mspatcha.dll');
const TestApplyPatchToFileByHandles = lib.func('__stdcall', 'TestApplyPatchToFileByHandles', 'int32_t', ['void *', 'void *', 'uint32_t']);
// TestApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, ApplyOptionFlags)
// PatchFileHandle : HANDLE -> 'void *'
// OldFileHandle : HANDLE -> 'void *'
// ApplyOptionFlags : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("mspatcha.dll", {
TestApplyPatchToFileByHandles: { parameters: ["pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.TestApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, ApplyOptionFlags)
// PatchFileHandle : HANDLE -> "pointer"
// OldFileHandle : HANDLE -> "pointer"
// ApplyOptionFlags : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t TestApplyPatchToFileByHandles(
void* PatchFileHandle,
void* OldFileHandle,
uint32_t ApplyOptionFlags);
C, "mspatcha.dll");
// $ffi->TestApplyPatchToFileByHandles(PatchFileHandle, OldFileHandle, ApplyOptionFlags);
// PatchFileHandle : HANDLE
// OldFileHandle : 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 TestApplyPatchToFileByHandles(
Pointer PatchFileHandle, // HANDLE
Pointer OldFileHandle, // HANDLE
int ApplyOptionFlags // DWORD
);
}@[Link("mspatcha")]
lib Libmspatcha
fun TestApplyPatchToFileByHandles = TestApplyPatchToFileByHandles(
PatchFileHandle : Void*, # HANDLE
OldFileHandle : 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 TestApplyPatchToFileByHandlesNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32);
typedef TestApplyPatchToFileByHandlesDart = int Function(Pointer<Void>, Pointer<Void>, int);
final TestApplyPatchToFileByHandles = DynamicLibrary.open('mspatcha.dll')
.lookupFunction<TestApplyPatchToFileByHandlesNative, TestApplyPatchToFileByHandlesDart>('TestApplyPatchToFileByHandles');
// PatchFileHandle : HANDLE -> Pointer<Void>
// OldFileHandle : HANDLE -> Pointer<Void>
// ApplyOptionFlags : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function TestApplyPatchToFileByHandles(
PatchFileHandle: THandle; // HANDLE
OldFileHandle: THandle; // HANDLE
ApplyOptionFlags: DWORD // DWORD
): BOOL; stdcall;
external 'mspatcha.dll' name 'TestApplyPatchToFileByHandles';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "TestApplyPatchToFileByHandles"
c_TestApplyPatchToFileByHandles :: Ptr () -> Ptr () -> Word32 -> IO CInt
-- PatchFileHandle : HANDLE -> Ptr ()
-- OldFileHandle : HANDLE -> Ptr ()
-- ApplyOptionFlags : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let testapplypatchtofilebyhandles =
foreign "TestApplyPatchToFileByHandles"
((ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* PatchFileHandle : HANDLE -> (ptr void) *)
(* OldFileHandle : 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 ("TestApplyPatchToFileByHandles" test-apply-patch-to-file-by-handles :convention :stdcall) :int32
(patch-file-handle :pointer) ; HANDLE
(old-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 $TestApplyPatchToFileByHandles = Win32::API::More->new('mspatcha',
'BOOL TestApplyPatchToFileByHandles(HANDLE PatchFileHandle, HANDLE OldFileHandle, DWORD ApplyOptionFlags)');
# my $ret = $TestApplyPatchToFileByHandles->Call($PatchFileHandle, $OldFileHandle, $ApplyOptionFlags);
# PatchFileHandle : HANDLE -> HANDLE
# OldFileHandle : HANDLE -> HANDLE
# ApplyOptionFlags : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。