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

GetFilePatchSignatureA

関数
パッチ用にファイルの署名値を計算して取得する(ANSI版)。
DLLmspatcha.dll文字セットANSI (-A)呼出規約winapi

シグネチャ

// mspatcha.dll  (ANSI / -A)
#include <windows.h>

BOOL GetFilePatchSignatureA(
    LPCSTR FileName,
    DWORD OptionFlags,
    void* OptionData,   // optional
    DWORD IgnoreRangeCount,
    PATCH_IGNORE_RANGE* IgnoreRangeArray,   // optional
    DWORD RetainRangeCount,
    PATCH_RETAIN_RANGE* RetainRangeArray,   // optional
    DWORD SignatureBufferSize,
    LPSTR SignatureBuffer
);

パラメーター

名前方向説明
FileNameLPCSTRin署名を計算する対象ファイルのパス。ANSI 文字列で指定する。
OptionFlagsDWORDin署名計算の動作を制御するフラグ。PATCH_OPTION_* を指定する。
OptionDatavoid*inoptional追加オプションへのポインタ。通常 NULL を指定する。
IgnoreRangeCountDWORDinIgnoreRangeArray の要素数。署名計算で無視する範囲の個数。
IgnoreRangeArrayPATCH_IGNORE_RANGE*inoptional署名計算時に無視するバイト範囲の配列(PATCH_IGNORE_RANGE)。NULL 可。
RetainRangeCountDWORDinRetainRangeArray の要素数。保持する範囲の個数。
RetainRangeArrayPATCH_RETAIN_RANGE*inoptional署名計算時に保持するバイト範囲の配列(PATCH_RETAIN_RANGE)。NULL 可。
SignatureBufferSizeDWORDinSignatureBuffer のサイズ。文字数(バイト数)で指定する。
SignatureBufferLPSTRout計算された署名文字列を受け取る出力バッファ。ANSI 文字列で返される。

戻り値の型: BOOL

各言語での呼び出し定義

// mspatcha.dll  (ANSI / -A)
#include <windows.h>

BOOL GetFilePatchSignatureA(
    LPCSTR FileName,
    DWORD OptionFlags,
    void* OptionData,   // optional
    DWORD IgnoreRangeCount,
    PATCH_IGNORE_RANGE* IgnoreRangeArray,   // optional
    DWORD RetainRangeCount,
    PATCH_RETAIN_RANGE* RetainRangeArray,   // optional
    DWORD SignatureBufferSize,
    LPSTR SignatureBuffer
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern bool GetFilePatchSignatureA(
    [MarshalAs(UnmanagedType.LPStr)] string FileName,   // LPCSTR
    uint OptionFlags,   // DWORD
    IntPtr OptionData,   // void* optional
    uint IgnoreRangeCount,   // DWORD
    IntPtr IgnoreRangeArray,   // PATCH_IGNORE_RANGE* optional
    uint RetainRangeCount,   // DWORD
    IntPtr RetainRangeArray,   // PATCH_RETAIN_RANGE* optional
    uint SignatureBufferSize,   // DWORD
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder SignatureBuffer   // LPSTR out
);
<DllImport("mspatcha.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function GetFilePatchSignatureA(
    <MarshalAs(UnmanagedType.LPStr)> FileName As String,   ' LPCSTR
    OptionFlags As UInteger,   ' DWORD
    OptionData As IntPtr,   ' void* optional
    IgnoreRangeCount As UInteger,   ' DWORD
    IgnoreRangeArray As IntPtr,   ' PATCH_IGNORE_RANGE* optional
    RetainRangeCount As UInteger,   ' DWORD
    RetainRangeArray As IntPtr,   ' PATCH_RETAIN_RANGE* optional
    SignatureBufferSize As UInteger,   ' DWORD
    <MarshalAs(UnmanagedType.LPStr)> SignatureBuffer As System.Text.StringBuilder   ' LPSTR out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' FileName : LPCSTR
' OptionFlags : DWORD
' OptionData : void* optional
' IgnoreRangeCount : DWORD
' IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
' RetainRangeCount : DWORD
' RetainRangeArray : PATCH_RETAIN_RANGE* optional
' SignatureBufferSize : DWORD
' SignatureBuffer : LPSTR out
Declare PtrSafe Function GetFilePatchSignatureA Lib "mspatcha" ( _
    ByVal FileName As String, _
    ByVal OptionFlags As Long, _
    ByVal OptionData As LongPtr, _
    ByVal IgnoreRangeCount As Long, _
    ByVal IgnoreRangeArray As LongPtr, _
    ByVal RetainRangeCount As Long, _
    ByVal RetainRangeArray As LongPtr, _
    ByVal SignatureBufferSize As Long, _
    ByVal SignatureBuffer As String) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetFilePatchSignatureA = ctypes.windll.mspatcha.GetFilePatchSignatureA
GetFilePatchSignatureA.restype = wintypes.BOOL
GetFilePatchSignatureA.argtypes = [
    wintypes.LPCSTR,  # FileName : LPCSTR
    wintypes.DWORD,  # OptionFlags : DWORD
    ctypes.POINTER(None),  # OptionData : void* optional
    wintypes.DWORD,  # IgnoreRangeCount : DWORD
    ctypes.c_void_p,  # IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
    wintypes.DWORD,  # RetainRangeCount : DWORD
    ctypes.c_void_p,  # RetainRangeArray : PATCH_RETAIN_RANGE* optional
    wintypes.DWORD,  # SignatureBufferSize : DWORD
    wintypes.LPSTR,  # SignatureBuffer : LPSTR out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('mspatcha.dll')
GetFilePatchSignatureA = Fiddle::Function.new(
  lib['GetFilePatchSignatureA'],
  [
    Fiddle::TYPE_VOIDP,  # FileName : LPCSTR
    -Fiddle::TYPE_INT,  # OptionFlags : DWORD
    Fiddle::TYPE_VOIDP,  # OptionData : void* optional
    -Fiddle::TYPE_INT,  # IgnoreRangeCount : DWORD
    Fiddle::TYPE_VOIDP,  # IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
    -Fiddle::TYPE_INT,  # RetainRangeCount : DWORD
    Fiddle::TYPE_VOIDP,  # RetainRangeArray : PATCH_RETAIN_RANGE* optional
    -Fiddle::TYPE_INT,  # SignatureBufferSize : DWORD
    Fiddle::TYPE_VOIDP,  # SignatureBuffer : LPSTR out
  ],
  Fiddle::TYPE_INT)
#[link(name = "mspatcha")]
extern "system" {
    fn GetFilePatchSignatureA(
        FileName: *const u8,  // LPCSTR
        OptionFlags: u32,  // DWORD
        OptionData: *mut (),  // void* optional
        IgnoreRangeCount: u32,  // DWORD
        IgnoreRangeArray: *mut PATCH_IGNORE_RANGE,  // PATCH_IGNORE_RANGE* optional
        RetainRangeCount: u32,  // DWORD
        RetainRangeArray: *mut PATCH_RETAIN_RANGE,  // PATCH_RETAIN_RANGE* optional
        SignatureBufferSize: u32,  // DWORD
        SignatureBuffer: *mut u8  // LPSTR out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll", CharSet = CharSet.Ansi)]
public static extern bool GetFilePatchSignatureA([MarshalAs(UnmanagedType.LPStr)] string FileName, uint OptionFlags, IntPtr OptionData, uint IgnoreRangeCount, IntPtr IgnoreRangeArray, uint RetainRangeCount, IntPtr RetainRangeArray, uint SignatureBufferSize, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder SignatureBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mspatcha_GetFilePatchSignatureA' -Namespace Win32 -PassThru
# $api::GetFilePatchSignatureA(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
#uselib "mspatcha.dll"
#func global GetFilePatchSignatureA "GetFilePatchSignatureA" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; GetFilePatchSignatureA FileName, OptionFlags, OptionData, IgnoreRangeCount, varptr(IgnoreRangeArray), RetainRangeCount, varptr(RetainRangeArray), SignatureBufferSize, varptr(SignatureBuffer)   ; 戻り値は stat
; FileName : LPCSTR -> "sptr"
; OptionFlags : DWORD -> "sptr"
; OptionData : void* optional -> "sptr"
; IgnoreRangeCount : DWORD -> "sptr"
; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "sptr"
; RetainRangeCount : DWORD -> "sptr"
; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "sptr"
; SignatureBufferSize : DWORD -> "sptr"
; SignatureBuffer : LPSTR out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "mspatcha.dll"
#cfunc global GetFilePatchSignatureA "GetFilePatchSignatureA" str, int, sptr, int, var, int, var, int, var
; res = GetFilePatchSignatureA(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
; FileName : LPCSTR -> "str"
; OptionFlags : DWORD -> "int"
; OptionData : void* optional -> "sptr"
; IgnoreRangeCount : DWORD -> "int"
; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "var"
; RetainRangeCount : DWORD -> "int"
; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "var"
; SignatureBufferSize : DWORD -> "int"
; SignatureBuffer : LPSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL GetFilePatchSignatureA(LPCSTR FileName, DWORD OptionFlags, void* OptionData, DWORD IgnoreRangeCount, PATCH_IGNORE_RANGE* IgnoreRangeArray, DWORD RetainRangeCount, PATCH_RETAIN_RANGE* RetainRangeArray, DWORD SignatureBufferSize, LPSTR SignatureBuffer)
#uselib "mspatcha.dll"
#cfunc global GetFilePatchSignatureA "GetFilePatchSignatureA" str, int, intptr, int, var, int, var, int, var
; res = GetFilePatchSignatureA(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
; FileName : LPCSTR -> "str"
; OptionFlags : DWORD -> "int"
; OptionData : void* optional -> "intptr"
; IgnoreRangeCount : DWORD -> "int"
; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "var"
; RetainRangeCount : DWORD -> "int"
; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "var"
; SignatureBufferSize : DWORD -> "int"
; SignatureBuffer : LPSTR out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	mspatcha = windows.NewLazySystemDLL("mspatcha.dll")
	procGetFilePatchSignatureA = mspatcha.NewProc("GetFilePatchSignatureA")
)

// FileName (LPCSTR), OptionFlags (DWORD), OptionData (void* optional), IgnoreRangeCount (DWORD), IgnoreRangeArray (PATCH_IGNORE_RANGE* optional), RetainRangeCount (DWORD), RetainRangeArray (PATCH_RETAIN_RANGE* optional), SignatureBufferSize (DWORD), SignatureBuffer (LPSTR out)
r1, _, err := procGetFilePatchSignatureA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(FileName))),
	uintptr(OptionFlags),
	uintptr(OptionData),
	uintptr(IgnoreRangeCount),
	uintptr(IgnoreRangeArray),
	uintptr(RetainRangeCount),
	uintptr(RetainRangeArray),
	uintptr(SignatureBufferSize),
	uintptr(SignatureBuffer),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetFilePatchSignatureA(
  FileName: PAnsiChar;   // LPCSTR
  OptionFlags: DWORD;   // DWORD
  OptionData: Pointer;   // void* optional
  IgnoreRangeCount: DWORD;   // DWORD
  IgnoreRangeArray: Pointer;   // PATCH_IGNORE_RANGE* optional
  RetainRangeCount: DWORD;   // DWORD
  RetainRangeArray: Pointer;   // PATCH_RETAIN_RANGE* optional
  SignatureBufferSize: DWORD;   // DWORD
  SignatureBuffer: PAnsiChar   // LPSTR out
): BOOL; stdcall;
  external 'mspatcha.dll' name 'GetFilePatchSignatureA';
result := DllCall("mspatcha\GetFilePatchSignatureA"
    , "AStr", FileName   ; LPCSTR
    , "UInt", OptionFlags   ; DWORD
    , "Ptr", OptionData   ; void* optional
    , "UInt", IgnoreRangeCount   ; DWORD
    , "Ptr", IgnoreRangeArray   ; PATCH_IGNORE_RANGE* optional
    , "UInt", RetainRangeCount   ; DWORD
    , "Ptr", RetainRangeArray   ; PATCH_RETAIN_RANGE* optional
    , "UInt", SignatureBufferSize   ; DWORD
    , "Ptr", SignatureBuffer   ; LPSTR out
    , "Int")   ; return: BOOL
●GetFilePatchSignatureA(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer) = DLL("mspatcha.dll", "bool GetFilePatchSignatureA(char*, dword, void*, dword, void*, dword, void*, dword, char*)")
# 呼び出し: GetFilePatchSignatureA(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
# FileName : LPCSTR -> "char*"
# OptionFlags : DWORD -> "dword"
# OptionData : void* optional -> "void*"
# IgnoreRangeCount : DWORD -> "dword"
# IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "void*"
# RetainRangeCount : DWORD -> "dword"
# RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "void*"
# SignatureBufferSize : DWORD -> "dword"
# SignatureBuffer : LPSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "mspatcha" fn GetFilePatchSignatureA(
    FileName: [*c]const u8, // LPCSTR
    OptionFlags: u32, // DWORD
    OptionData: ?*anyopaque, // void* optional
    IgnoreRangeCount: u32, // DWORD
    IgnoreRangeArray: [*c]PATCH_IGNORE_RANGE, // PATCH_IGNORE_RANGE* optional
    RetainRangeCount: u32, // DWORD
    RetainRangeArray: [*c]PATCH_RETAIN_RANGE, // PATCH_RETAIN_RANGE* optional
    SignatureBufferSize: u32, // DWORD
    SignatureBuffer: [*c]u8 // LPSTR out
) callconv(std.os.windows.WINAPI) i32;
proc GetFilePatchSignatureA(
    FileName: cstring,  # LPCSTR
    OptionFlags: uint32,  # DWORD
    OptionData: pointer,  # void* optional
    IgnoreRangeCount: uint32,  # DWORD
    IgnoreRangeArray: ptr PATCH_IGNORE_RANGE,  # PATCH_IGNORE_RANGE* optional
    RetainRangeCount: uint32,  # DWORD
    RetainRangeArray: ptr PATCH_RETAIN_RANGE,  # PATCH_RETAIN_RANGE* optional
    SignatureBufferSize: uint32,  # DWORD
    SignatureBuffer: ptr char  # LPSTR out
): int32 {.importc: "GetFilePatchSignatureA", stdcall, dynlib: "mspatcha.dll".}
pragma(lib, "mspatcha");
extern(Windows)
int GetFilePatchSignatureA(
    const(char)* FileName,   // LPCSTR
    uint OptionFlags,   // DWORD
    void* OptionData,   // void* optional
    uint IgnoreRangeCount,   // DWORD
    PATCH_IGNORE_RANGE* IgnoreRangeArray,   // PATCH_IGNORE_RANGE* optional
    uint RetainRangeCount,   // DWORD
    PATCH_RETAIN_RANGE* RetainRangeArray,   // PATCH_RETAIN_RANGE* optional
    uint SignatureBufferSize,   // DWORD
    char* SignatureBuffer   // LPSTR out
);
ccall((:GetFilePatchSignatureA, "mspatcha.dll"), stdcall, Int32,
      (Cstring, UInt32, Ptr{Cvoid}, UInt32, Ptr{PATCH_IGNORE_RANGE}, UInt32, Ptr{PATCH_RETAIN_RANGE}, UInt32, Ptr{UInt8}),
      FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
# FileName : LPCSTR -> Cstring
# OptionFlags : DWORD -> UInt32
# OptionData : void* optional -> Ptr{Cvoid}
# IgnoreRangeCount : DWORD -> UInt32
# IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> Ptr{PATCH_IGNORE_RANGE}
# RetainRangeCount : DWORD -> UInt32
# RetainRangeArray : PATCH_RETAIN_RANGE* optional -> Ptr{PATCH_RETAIN_RANGE}
# SignatureBufferSize : DWORD -> UInt32
# SignatureBuffer : LPSTR out -> Ptr{UInt8}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetFilePatchSignatureA(
    const char* FileName,
    uint32_t OptionFlags,
    void* OptionData,
    uint32_t IgnoreRangeCount,
    void* IgnoreRangeArray,
    uint32_t RetainRangeCount,
    void* RetainRangeArray,
    uint32_t SignatureBufferSize,
    char* SignatureBuffer);
]]
local mspatcha = ffi.load("mspatcha")
-- mspatcha.GetFilePatchSignatureA(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
-- FileName : LPCSTR
-- OptionFlags : DWORD
-- OptionData : void* optional
-- IgnoreRangeCount : DWORD
-- IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
-- RetainRangeCount : DWORD
-- RetainRangeArray : PATCH_RETAIN_RANGE* optional
-- SignatureBufferSize : DWORD
-- SignatureBuffer : LPSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('mspatcha.dll');
const GetFilePatchSignatureA = lib.func('__stdcall', 'GetFilePatchSignatureA', 'int32_t', ['str', 'uint32_t', 'void *', 'uint32_t', 'void *', 'uint32_t', 'void *', 'uint32_t', 'char *']);
// GetFilePatchSignatureA(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
// FileName : LPCSTR -> 'str'
// OptionFlags : DWORD -> 'uint32_t'
// OptionData : void* optional -> 'void *'
// IgnoreRangeCount : DWORD -> 'uint32_t'
// IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> 'void *'
// RetainRangeCount : DWORD -> 'uint32_t'
// RetainRangeArray : PATCH_RETAIN_RANGE* optional -> 'void *'
// SignatureBufferSize : DWORD -> 'uint32_t'
// SignatureBuffer : LPSTR out -> 'char *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("mspatcha.dll", {
  GetFilePatchSignatureA: { parameters: ["buffer", "u32", "pointer", "u32", "pointer", "u32", "pointer", "u32", "buffer"], result: "i32" },
});
// lib.symbols.GetFilePatchSignatureA(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
// FileName : LPCSTR -> "buffer"
// OptionFlags : DWORD -> "u32"
// OptionData : void* optional -> "pointer"
// IgnoreRangeCount : DWORD -> "u32"
// IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "pointer"
// RetainRangeCount : DWORD -> "u32"
// RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "pointer"
// SignatureBufferSize : DWORD -> "u32"
// SignatureBuffer : LPSTR out -> "buffer"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetFilePatchSignatureA(
    const char* FileName,
    uint32_t OptionFlags,
    void* OptionData,
    uint32_t IgnoreRangeCount,
    void* IgnoreRangeArray,
    uint32_t RetainRangeCount,
    void* RetainRangeArray,
    uint32_t SignatureBufferSize,
    char* SignatureBuffer);
C, "mspatcha.dll");
// $ffi->GetFilePatchSignatureA(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer);
// FileName : LPCSTR
// OptionFlags : DWORD
// OptionData : void* optional
// IgnoreRangeCount : DWORD
// IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
// RetainRangeCount : DWORD
// RetainRangeArray : PATCH_RETAIN_RANGE* optional
// SignatureBufferSize : DWORD
// SignatureBuffer : LPSTR out
// 構造体/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, W32APIOptions.ASCII_OPTIONS);
    boolean GetFilePatchSignatureA(
        String FileName,   // LPCSTR
        int OptionFlags,   // DWORD
        Pointer OptionData,   // void* optional
        int IgnoreRangeCount,   // DWORD
        Pointer IgnoreRangeArray,   // PATCH_IGNORE_RANGE* optional
        int RetainRangeCount,   // DWORD
        Pointer RetainRangeArray,   // PATCH_RETAIN_RANGE* optional
        int SignatureBufferSize,   // DWORD
        byte[] SignatureBuffer   // LPSTR out
    );
}
@[Link("mspatcha")]
lib Libmspatcha
  fun GetFilePatchSignatureA = GetFilePatchSignatureA(
    FileName : UInt8*,   # LPCSTR
    OptionFlags : UInt32,   # DWORD
    OptionData : Void*,   # void* optional
    IgnoreRangeCount : UInt32,   # DWORD
    IgnoreRangeArray : PATCH_IGNORE_RANGE*,   # PATCH_IGNORE_RANGE* optional
    RetainRangeCount : UInt32,   # DWORD
    RetainRangeArray : PATCH_RETAIN_RANGE*,   # PATCH_RETAIN_RANGE* optional
    SignatureBufferSize : UInt32,   # DWORD
    SignatureBuffer : UInt8*   # LPSTR out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef GetFilePatchSignatureANative = Int32 Function(Pointer<Utf8>, Uint32, Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Utf8>);
typedef GetFilePatchSignatureADart = int Function(Pointer<Utf8>, int, Pointer<Void>, int, Pointer<Void>, int, Pointer<Void>, int, Pointer<Utf8>);
final GetFilePatchSignatureA = DynamicLibrary.open('mspatcha.dll')
    .lookupFunction<GetFilePatchSignatureANative, GetFilePatchSignatureADart>('GetFilePatchSignatureA');
// FileName : LPCSTR -> Pointer<Utf8>
// OptionFlags : DWORD -> Uint32
// OptionData : void* optional -> Pointer<Void>
// IgnoreRangeCount : DWORD -> Uint32
// IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> Pointer<Void>
// RetainRangeCount : DWORD -> Uint32
// RetainRangeArray : PATCH_RETAIN_RANGE* optional -> Pointer<Void>
// SignatureBufferSize : DWORD -> Uint32
// SignatureBuffer : LPSTR out -> Pointer<Utf8>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetFilePatchSignatureA(
  FileName: PAnsiChar;   // LPCSTR
  OptionFlags: DWORD;   // DWORD
  OptionData: Pointer;   // void* optional
  IgnoreRangeCount: DWORD;   // DWORD
  IgnoreRangeArray: Pointer;   // PATCH_IGNORE_RANGE* optional
  RetainRangeCount: DWORD;   // DWORD
  RetainRangeArray: Pointer;   // PATCH_RETAIN_RANGE* optional
  SignatureBufferSize: DWORD;   // DWORD
  SignatureBuffer: PAnsiChar   // LPSTR out
): BOOL; stdcall;
  external 'mspatcha.dll' name 'GetFilePatchSignatureA';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetFilePatchSignatureA"
  c_GetFilePatchSignatureA :: CString -> Word32 -> Ptr () -> Word32 -> Ptr () -> Word32 -> Ptr () -> Word32 -> CString -> IO CInt
-- FileName : LPCSTR -> CString
-- OptionFlags : DWORD -> Word32
-- OptionData : void* optional -> Ptr ()
-- IgnoreRangeCount : DWORD -> Word32
-- IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> Ptr ()
-- RetainRangeCount : DWORD -> Word32
-- RetainRangeArray : PATCH_RETAIN_RANGE* optional -> Ptr ()
-- SignatureBufferSize : DWORD -> Word32
-- SignatureBuffer : LPSTR out -> CString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getfilepatchsignaturea =
  foreign "GetFilePatchSignatureA"
    (string @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> string @-> returning int32_t)
(* FileName : LPCSTR -> string *)
(* OptionFlags : DWORD -> uint32_t *)
(* OptionData : void* optional -> (ptr void) *)
(* IgnoreRangeCount : DWORD -> uint32_t *)
(* IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> (ptr void) *)
(* RetainRangeCount : DWORD -> uint32_t *)
(* RetainRangeArray : PATCH_RETAIN_RANGE* optional -> (ptr void) *)
(* SignatureBufferSize : DWORD -> uint32_t *)
(* SignatureBuffer : LPSTR out -> string *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library mspatcha (t "mspatcha.dll"))
(cffi:use-foreign-library mspatcha)

(cffi:defcfun ("GetFilePatchSignatureA" get-file-patch-signature-a :convention :stdcall) :int32
  (file-name :string)   ; LPCSTR
  (option-flags :uint32)   ; DWORD
  (option-data :pointer)   ; void* optional
  (ignore-range-count :uint32)   ; DWORD
  (ignore-range-array :pointer)   ; PATCH_IGNORE_RANGE* optional
  (retain-range-count :uint32)   ; DWORD
  (retain-range-array :pointer)   ; PATCH_RETAIN_RANGE* optional
  (signature-buffer-size :uint32)   ; DWORD
  (signature-buffer :pointer))   ; LPSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetFilePatchSignatureA = Win32::API::More->new('mspatcha',
    'BOOL GetFilePatchSignatureA(LPCSTR FileName, DWORD OptionFlags, LPVOID OptionData, DWORD IgnoreRangeCount, LPVOID IgnoreRangeArray, DWORD RetainRangeCount, LPVOID RetainRangeArray, DWORD SignatureBufferSize, LPSTR SignatureBuffer)');
# my $ret = $GetFilePatchSignatureA->Call($FileName, $OptionFlags, $OptionData, $IgnoreRangeCount, $IgnoreRangeArray, $RetainRangeCount, $RetainRangeArray, $SignatureBufferSize, $SignatureBuffer);
# FileName : LPCSTR -> LPCSTR
# OptionFlags : DWORD -> DWORD
# OptionData : void* optional -> LPVOID
# IgnoreRangeCount : DWORD -> DWORD
# IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> LPVOID
# RetainRangeCount : DWORD -> DWORD
# RetainRangeArray : PATCH_RETAIN_RANGE* optional -> LPVOID
# SignatureBufferSize : DWORD -> DWORD
# SignatureBuffer : LPSTR out -> LPSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

文字セット違い
使用する型