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

MsiGetFileHashA

関数
指定ファイルのハッシュ値を計算して取得する。
DLLmsi.dll文字セットANSI (-A)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiGetFileHashA(
    LPCSTR szFilePath,
    DWORD dwOptions,
    MSIFILEHASHINFO* pHash
);

パラメーター

名前方向
szFilePathLPCSTRin
dwOptionsDWORDin
pHashMSIFILEHASHINFO*inout

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD MsiGetFileHashA(
    LPCSTR szFilePath,
    DWORD dwOptions,
    MSIFILEHASHINFO* pHash
);
[DllImport("msi.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint MsiGetFileHashA(
    [MarshalAs(UnmanagedType.LPStr)] string szFilePath,   // LPCSTR
    uint dwOptions,   // DWORD
    IntPtr pHash   // MSIFILEHASHINFO* in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function MsiGetFileHashA(
    <MarshalAs(UnmanagedType.LPStr)> szFilePath As String,   ' LPCSTR
    dwOptions As UInteger,   ' DWORD
    pHash As IntPtr   ' MSIFILEHASHINFO* in/out
) As UInteger
End Function
' szFilePath : LPCSTR
' dwOptions : DWORD
' pHash : MSIFILEHASHINFO* in/out
Declare PtrSafe Function MsiGetFileHashA Lib "msi" ( _
    ByVal szFilePath As String, _
    ByVal dwOptions As Long, _
    ByVal pHash As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

MsiGetFileHashA = ctypes.windll.msi.MsiGetFileHashA
MsiGetFileHashA.restype = wintypes.DWORD
MsiGetFileHashA.argtypes = [
    wintypes.LPCSTR,  # szFilePath : LPCSTR
    wintypes.DWORD,  # dwOptions : DWORD
    ctypes.c_void_p,  # pHash : MSIFILEHASHINFO* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiGetFileHashA = Fiddle::Function.new(
  lib['MsiGetFileHashA'],
  [
    Fiddle::TYPE_VOIDP,  # szFilePath : LPCSTR
    -Fiddle::TYPE_INT,  # dwOptions : DWORD
    Fiddle::TYPE_VOIDP,  # pHash : MSIFILEHASHINFO* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "msi")]
extern "system" {
    fn MsiGetFileHashA(
        szFilePath: *const u8,  // LPCSTR
        dwOptions: u32,  // DWORD
        pHash: *mut MSIFILEHASHINFO  // MSIFILEHASHINFO* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Ansi)]
public static extern uint MsiGetFileHashA([MarshalAs(UnmanagedType.LPStr)] string szFilePath, uint dwOptions, IntPtr pHash);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetFileHashA' -Namespace Win32 -PassThru
# $api::MsiGetFileHashA(szFilePath, dwOptions, pHash)
#uselib "msi.dll"
#func global MsiGetFileHashA "MsiGetFileHashA" sptr, sptr, sptr
; MsiGetFileHashA szFilePath, dwOptions, varptr(pHash)   ; 戻り値は stat
; szFilePath : LPCSTR -> "sptr"
; dwOptions : DWORD -> "sptr"
; pHash : MSIFILEHASHINFO* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetFileHashA "MsiGetFileHashA" str, int, var
; res = MsiGetFileHashA(szFilePath, dwOptions, pHash)
; szFilePath : LPCSTR -> "str"
; dwOptions : DWORD -> "int"
; pHash : MSIFILEHASHINFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiGetFileHashA(LPCSTR szFilePath, DWORD dwOptions, MSIFILEHASHINFO* pHash)
#uselib "msi.dll"
#cfunc global MsiGetFileHashA "MsiGetFileHashA" str, int, var
; res = MsiGetFileHashA(szFilePath, dwOptions, pHash)
; szFilePath : LPCSTR -> "str"
; dwOptions : DWORD -> "int"
; pHash : MSIFILEHASHINFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetFileHashA = msi.NewProc("MsiGetFileHashA")
)

// szFilePath (LPCSTR), dwOptions (DWORD), pHash (MSIFILEHASHINFO* in/out)
r1, _, err := procMsiGetFileHashA.Call(
	uintptr(unsafe.Pointer(windows.BytePtrFromString(szFilePath))),
	uintptr(dwOptions),
	uintptr(pHash),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiGetFileHashA(
  szFilePath: PAnsiChar;   // LPCSTR
  dwOptions: DWORD;   // DWORD
  pHash: Pointer   // MSIFILEHASHINFO* in/out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiGetFileHashA';
result := DllCall("msi\MsiGetFileHashA"
    , "AStr", szFilePath   ; LPCSTR
    , "UInt", dwOptions   ; DWORD
    , "Ptr", pHash   ; MSIFILEHASHINFO* in/out
    , "UInt")   ; return: DWORD
●MsiGetFileHashA(szFilePath, dwOptions, pHash) = DLL("msi.dll", "dword MsiGetFileHashA(char*, dword, void*)")
# 呼び出し: MsiGetFileHashA(szFilePath, dwOptions, pHash)
# szFilePath : LPCSTR -> "char*"
# dwOptions : DWORD -> "dword"
# pHash : MSIFILEHASHINFO* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。