ホーム › System.ApplicationInstallationAndServicing › GetFilePatchSignatureW
GetFilePatchSignatureW
関数パッチ用にファイルの署名値を計算して取得する(Unicode版)。
シグネチャ
// mspatcha.dll (Unicode / -W)
#include <windows.h>
BOOL GetFilePatchSignatureW(
LPCWSTR FileName,
DWORD OptionFlags,
void* OptionData, // optional
DWORD IgnoreRangeCount,
PATCH_IGNORE_RANGE* IgnoreRangeArray, // optional
DWORD RetainRangeCount,
PATCH_RETAIN_RANGE* RetainRangeArray, // optional
DWORD SignatureBufferSize,
LPWSTR SignatureBuffer
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| FileName | LPCWSTR | in | 署名を計算する対象ファイルのパス。Unicode 文字列で指定する。 |
| OptionFlags | DWORD | in | 署名計算の動作を制御するフラグ。PATCH_OPTION_* を指定する。 |
| OptionData | void* | inoptional | 追加オプションへのポインタ。通常 NULL を指定する。 |
| IgnoreRangeCount | DWORD | in | IgnoreRangeArray の要素数。署名計算で無視する範囲の個数。 |
| IgnoreRangeArray | PATCH_IGNORE_RANGE* | inoptional | 署名計算時に無視するバイト範囲の配列(PATCH_IGNORE_RANGE)。NULL 可。 |
| RetainRangeCount | DWORD | in | RetainRangeArray の要素数。保持する範囲の個数。 |
| RetainRangeArray | PATCH_RETAIN_RANGE* | inoptional | 署名計算時に保持するバイト範囲の配列(PATCH_RETAIN_RANGE)。NULL 可。 |
| SignatureBufferSize | DWORD | in | SignatureBuffer のサイズ。文字数で指定する。 |
| SignatureBuffer | LPWSTR | out | 計算された署名文字列を受け取る出力バッファ。Unicode 文字列で返される。 |
戻り値の型: BOOL
各言語での呼び出し定義
// mspatcha.dll (Unicode / -W)
#include <windows.h>
BOOL GetFilePatchSignatureW(
LPCWSTR FileName,
DWORD OptionFlags,
void* OptionData, // optional
DWORD IgnoreRangeCount,
PATCH_IGNORE_RANGE* IgnoreRangeArray, // optional
DWORD RetainRangeCount,
PATCH_RETAIN_RANGE* RetainRangeArray, // optional
DWORD SignatureBufferSize,
LPWSTR SignatureBuffer
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern bool GetFilePatchSignatureW(
[MarshalAs(UnmanagedType.LPWStr)] string FileName, // LPCWSTR
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.LPWStr)] System.Text.StringBuilder SignatureBuffer // LPWSTR out
);<DllImport("mspatcha.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function GetFilePatchSignatureW(
<MarshalAs(UnmanagedType.LPWStr)> FileName As String, ' LPCWSTR
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.LPWStr)> SignatureBuffer As System.Text.StringBuilder ' LPWSTR out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' FileName : LPCWSTR
' OptionFlags : DWORD
' OptionData : void* optional
' IgnoreRangeCount : DWORD
' IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
' RetainRangeCount : DWORD
' RetainRangeArray : PATCH_RETAIN_RANGE* optional
' SignatureBufferSize : DWORD
' SignatureBuffer : LPWSTR out
Declare PtrSafe Function GetFilePatchSignatureW Lib "mspatcha" ( _
ByVal FileName As LongPtr, _
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 LongPtr) As Long
' 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
GetFilePatchSignatureW = ctypes.windll.mspatcha.GetFilePatchSignatureW
GetFilePatchSignatureW.restype = wintypes.BOOL
GetFilePatchSignatureW.argtypes = [
wintypes.LPCWSTR, # FileName : LPCWSTR
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.LPWSTR, # SignatureBuffer : LPWSTR out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('mspatcha.dll')
GetFilePatchSignatureW = Fiddle::Function.new(
lib['GetFilePatchSignatureW'],
[
Fiddle::TYPE_VOIDP, # FileName : LPCWSTR
-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 : LPWSTR out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "mspatcha")]
extern "system" {
fn GetFilePatchSignatureW(
FileName: *const u16, // LPCWSTR
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 u16 // LPWSTR out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("mspatcha.dll", CharSet = CharSet.Unicode)]
public static extern bool GetFilePatchSignatureW([MarshalAs(UnmanagedType.LPWStr)] string FileName, uint OptionFlags, IntPtr OptionData, uint IgnoreRangeCount, IntPtr IgnoreRangeArray, uint RetainRangeCount, IntPtr RetainRangeArray, uint SignatureBufferSize, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder SignatureBuffer);
"@
$api = Add-Type -MemberDefinition $sig -Name 'mspatcha_GetFilePatchSignatureW' -Namespace Win32 -PassThru
# $api::GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)#uselib "mspatcha.dll"
#func global GetFilePatchSignatureW "GetFilePatchSignatureW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; GetFilePatchSignatureW FileName, OptionFlags, OptionData, IgnoreRangeCount, varptr(IgnoreRangeArray), RetainRangeCount, varptr(RetainRangeArray), SignatureBufferSize, varptr(SignatureBuffer) ; 戻り値は stat
; FileName : LPCWSTR -> "wptr"
; OptionFlags : DWORD -> "wptr"
; OptionData : void* optional -> "wptr"
; IgnoreRangeCount : DWORD -> "wptr"
; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "wptr"
; RetainRangeCount : DWORD -> "wptr"
; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "wptr"
; SignatureBufferSize : DWORD -> "wptr"
; SignatureBuffer : LPWSTR out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "mspatcha.dll" #cfunc global GetFilePatchSignatureW "GetFilePatchSignatureW" wstr, int, sptr, int, var, int, var, int, var ; res = GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer) ; FileName : LPCWSTR -> "wstr" ; 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 : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "mspatcha.dll" #cfunc global GetFilePatchSignatureW "GetFilePatchSignatureW" wstr, int, sptr, int, sptr, int, sptr, int, sptr ; res = GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, varptr(IgnoreRangeArray), RetainRangeCount, varptr(RetainRangeArray), SignatureBufferSize, varptr(SignatureBuffer)) ; FileName : LPCWSTR -> "wstr" ; OptionFlags : DWORD -> "int" ; OptionData : void* optional -> "sptr" ; IgnoreRangeCount : DWORD -> "int" ; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "sptr" ; RetainRangeCount : DWORD -> "int" ; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "sptr" ; SignatureBufferSize : DWORD -> "int" ; SignatureBuffer : LPWSTR out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL GetFilePatchSignatureW(LPCWSTR FileName, DWORD OptionFlags, void* OptionData, DWORD IgnoreRangeCount, PATCH_IGNORE_RANGE* IgnoreRangeArray, DWORD RetainRangeCount, PATCH_RETAIN_RANGE* RetainRangeArray, DWORD SignatureBufferSize, LPWSTR SignatureBuffer) #uselib "mspatcha.dll" #cfunc global GetFilePatchSignatureW "GetFilePatchSignatureW" wstr, int, intptr, int, var, int, var, int, var ; res = GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer) ; FileName : LPCWSTR -> "wstr" ; 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 : LPWSTR out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL GetFilePatchSignatureW(LPCWSTR FileName, DWORD OptionFlags, void* OptionData, DWORD IgnoreRangeCount, PATCH_IGNORE_RANGE* IgnoreRangeArray, DWORD RetainRangeCount, PATCH_RETAIN_RANGE* RetainRangeArray, DWORD SignatureBufferSize, LPWSTR SignatureBuffer) #uselib "mspatcha.dll" #cfunc global GetFilePatchSignatureW "GetFilePatchSignatureW" wstr, int, intptr, int, intptr, int, intptr, int, intptr ; res = GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, varptr(IgnoreRangeArray), RetainRangeCount, varptr(RetainRangeArray), SignatureBufferSize, varptr(SignatureBuffer)) ; FileName : LPCWSTR -> "wstr" ; OptionFlags : DWORD -> "int" ; OptionData : void* optional -> "intptr" ; IgnoreRangeCount : DWORD -> "int" ; IgnoreRangeArray : PATCH_IGNORE_RANGE* optional -> "intptr" ; RetainRangeCount : DWORD -> "int" ; RetainRangeArray : PATCH_RETAIN_RANGE* optional -> "intptr" ; SignatureBufferSize : DWORD -> "int" ; SignatureBuffer : LPWSTR out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
mspatcha = windows.NewLazySystemDLL("mspatcha.dll")
procGetFilePatchSignatureW = mspatcha.NewProc("GetFilePatchSignatureW")
)
// FileName (LPCWSTR), OptionFlags (DWORD), OptionData (void* optional), IgnoreRangeCount (DWORD), IgnoreRangeArray (PATCH_IGNORE_RANGE* optional), RetainRangeCount (DWORD), RetainRangeArray (PATCH_RETAIN_RANGE* optional), SignatureBufferSize (DWORD), SignatureBuffer (LPWSTR out)
r1, _, err := procGetFilePatchSignatureW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(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 // BOOLfunction GetFilePatchSignatureW(
FileName: PWideChar; // LPCWSTR
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: PWideChar // LPWSTR out
): BOOL; stdcall;
external 'mspatcha.dll' name 'GetFilePatchSignatureW';result := DllCall("mspatcha\GetFilePatchSignatureW"
, "WStr", FileName ; LPCWSTR
, "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 ; LPWSTR out
, "Int") ; return: BOOL●GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer) = DLL("mspatcha.dll", "bool GetFilePatchSignatureW(char*, dword, void*, dword, void*, dword, void*, dword, char*)")
# 呼び出し: GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
# FileName : LPCWSTR -> "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 : LPWSTR out -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "mspatcha" fn GetFilePatchSignatureW(
FileName: [*c]const u16, // LPCWSTR
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]u16 // LPWSTR out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc GetFilePatchSignatureW(
FileName: WideCString, # LPCWSTR
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 uint16 # LPWSTR out
): int32 {.importc: "GetFilePatchSignatureW", stdcall, dynlib: "mspatcha.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "mspatcha");
extern(Windows)
int GetFilePatchSignatureW(
const(wchar)* FileName, // LPCWSTR
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
wchar* SignatureBuffer // LPWSTR out
);ccall((:GetFilePatchSignatureW, "mspatcha.dll"), stdcall, Int32,
(Cwstring, UInt32, Ptr{Cvoid}, UInt32, Ptr{PATCH_IGNORE_RANGE}, UInt32, Ptr{PATCH_RETAIN_RANGE}, UInt32, Ptr{UInt16}),
FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
# FileName : LPCWSTR -> Cwstring
# 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 : LPWSTR out -> Ptr{UInt16}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t GetFilePatchSignatureW(
const uint16_t* FileName,
uint32_t OptionFlags,
void* OptionData,
uint32_t IgnoreRangeCount,
void* IgnoreRangeArray,
uint32_t RetainRangeCount,
void* RetainRangeArray,
uint32_t SignatureBufferSize,
uint16_t* SignatureBuffer);
]]
local mspatcha = ffi.load("mspatcha")
-- mspatcha.GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
-- FileName : LPCWSTR
-- OptionFlags : DWORD
-- OptionData : void* optional
-- IgnoreRangeCount : DWORD
-- IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
-- RetainRangeCount : DWORD
-- RetainRangeArray : PATCH_RETAIN_RANGE* optional
-- SignatureBufferSize : DWORD
-- SignatureBuffer : LPWSTR out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('mspatcha.dll');
const GetFilePatchSignatureW = lib.func('__stdcall', 'GetFilePatchSignatureW', 'int32_t', ['str16', 'uint32_t', 'void *', 'uint32_t', 'void *', 'uint32_t', 'void *', 'uint32_t', 'uint16_t *']);
// GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
// FileName : LPCWSTR -> 'str16'
// 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 : LPWSTR out -> 'uint16_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("mspatcha.dll", {
GetFilePatchSignatureW: { parameters: ["buffer", "u32", "pointer", "u32", "pointer", "u32", "pointer", "u32", "buffer"], result: "i32" },
});
// lib.symbols.GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer)
// FileName : LPCWSTR -> "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 : LPWSTR out -> "buffer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetFilePatchSignatureW(
const uint16_t* FileName,
uint32_t OptionFlags,
void* OptionData,
uint32_t IgnoreRangeCount,
void* IgnoreRangeArray,
uint32_t RetainRangeCount,
void* RetainRangeArray,
uint32_t SignatureBufferSize,
uint16_t* SignatureBuffer);
C, "mspatcha.dll");
// $ffi->GetFilePatchSignatureW(FileName, OptionFlags, OptionData, IgnoreRangeCount, IgnoreRangeArray, RetainRangeCount, RetainRangeArray, SignatureBufferSize, SignatureBuffer);
// FileName : LPCWSTR
// OptionFlags : DWORD
// OptionData : void* optional
// IgnoreRangeCount : DWORD
// IgnoreRangeArray : PATCH_IGNORE_RANGE* optional
// RetainRangeCount : DWORD
// RetainRangeArray : PATCH_RETAIN_RANGE* optional
// SignatureBufferSize : DWORD
// SignatureBuffer : LPWSTR 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.UNICODE_OPTIONS);
boolean GetFilePatchSignatureW(
WString FileName, // LPCWSTR
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
char[] SignatureBuffer // LPWSTR out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("mspatcha")]
lib Libmspatcha
fun GetFilePatchSignatureW = GetFilePatchSignatureW(
FileName : UInt16*, # LPCWSTR
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 : UInt16* # LPWSTR out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetFilePatchSignatureWNative = Int32 Function(Pointer<Utf16>, Uint32, Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Void>, Uint32, Pointer<Utf16>);
typedef GetFilePatchSignatureWDart = int Function(Pointer<Utf16>, int, Pointer<Void>, int, Pointer<Void>, int, Pointer<Void>, int, Pointer<Utf16>);
final GetFilePatchSignatureW = DynamicLibrary.open('mspatcha.dll')
.lookupFunction<GetFilePatchSignatureWNative, GetFilePatchSignatureWDart>('GetFilePatchSignatureW');
// FileName : LPCWSTR -> Pointer<Utf16>
// 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 : LPWSTR out -> Pointer<Utf16>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetFilePatchSignatureW(
FileName: PWideChar; // LPCWSTR
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: PWideChar // LPWSTR out
): BOOL; stdcall;
external 'mspatcha.dll' name 'GetFilePatchSignatureW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetFilePatchSignatureW"
c_GetFilePatchSignatureW :: CWString -> Word32 -> Ptr () -> Word32 -> Ptr () -> Word32 -> Ptr () -> Word32 -> CWString -> IO CInt
-- FileName : LPCWSTR -> CWString
-- 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 : LPWSTR out -> CWString
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getfilepatchsignaturew =
foreign "GetFilePatchSignatureW"
((ptr uint16_t) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr uint16_t) @-> returning int32_t)
(* FileName : LPCWSTR -> (ptr uint16_t) *)
(* 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 : LPWSTR out -> (ptr uint16_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library mspatcha (t "mspatcha.dll"))
(cffi:use-foreign-library mspatcha)
(cffi:defcfun ("GetFilePatchSignatureW" get-file-patch-signature-w :convention :stdcall) :int32
(file-name (:string :encoding :utf-16le)) ; LPCWSTR
(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)) ; LPWSTR out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetFilePatchSignatureW = Win32::API::More->new('mspatcha',
'BOOL GetFilePatchSignatureW(LPCWSTR FileName, DWORD OptionFlags, LPVOID OptionData, DWORD IgnoreRangeCount, LPVOID IgnoreRangeArray, DWORD RetainRangeCount, LPVOID RetainRangeArray, DWORD SignatureBufferSize, LPWSTR SignatureBuffer)');
# my $ret = $GetFilePatchSignatureW->Call($FileName, $OptionFlags, $OptionData, $IgnoreRangeCount, $IgnoreRangeArray, $RetainRangeCount, $RetainRangeArray, $SignatureBufferSize, $SignatureBuffer);
# FileName : LPCWSTR -> LPCWSTR
# 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 : LPWSTR out -> LPWSTR
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
文字セット違い
- f GetFilePatchSignatureA (ANSI版) — パッチ用にファイルの署名値を計算して取得する(ANSI版)。