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

MsiGetFileHashW

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

シグネチャ

// msi.dll  (Unicode / -W)
#include <windows.h>

DWORD MsiGetFileHashW(
    LPCWSTR szFilePath,
    DWORD dwOptions,
    MSIFILEHASHINFO* pHash
);

パラメーター

名前方向
szFilePathLPCWSTRin
dwOptionsDWORDin
pHashMSIFILEHASHINFO*inout

戻り値の型: DWORD

各言語での呼び出し定義

// msi.dll  (Unicode / -W)
#include <windows.h>

DWORD MsiGetFileHashW(
    LPCWSTR szFilePath,
    DWORD dwOptions,
    MSIFILEHASHINFO* pHash
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetFileHashW(
    [MarshalAs(UnmanagedType.LPWStr)] string szFilePath,   // LPCWSTR
    uint dwOptions,   // DWORD
    IntPtr pHash   // MSIFILEHASHINFO* in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetFileHashW(
    <MarshalAs(UnmanagedType.LPWStr)> szFilePath As String,   ' LPCWSTR
    dwOptions As UInteger,   ' DWORD
    pHash As IntPtr   ' MSIFILEHASHINFO* in/out
) As UInteger
End Function
' szFilePath : LPCWSTR
' dwOptions : DWORD
' pHash : MSIFILEHASHINFO* in/out
Declare PtrSafe Function MsiGetFileHashW Lib "msi" ( _
    ByVal szFilePath As LongPtr, _
    ByVal dwOptions As Long, _
    ByVal pHash 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

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

lib = Fiddle.dlopen('msi.dll')
MsiGetFileHashW = Fiddle::Function.new(
  lib['MsiGetFileHashW'],
  [
    Fiddle::TYPE_VOIDP,  # szFilePath : LPCWSTR
    -Fiddle::TYPE_INT,  # dwOptions : DWORD
    Fiddle::TYPE_VOIDP,  # pHash : MSIFILEHASHINFO* in/out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiGetFileHashW(
        szFilePath: *const u16,  // LPCWSTR
        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.Unicode)]
public static extern uint MsiGetFileHashW([MarshalAs(UnmanagedType.LPWStr)] string szFilePath, uint dwOptions, IntPtr pHash);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetFileHashW' -Namespace Win32 -PassThru
# $api::MsiGetFileHashW(szFilePath, dwOptions, pHash)
#uselib "msi.dll"
#func global MsiGetFileHashW "MsiGetFileHashW" wptr, wptr, wptr
; MsiGetFileHashW szFilePath, dwOptions, varptr(pHash)   ; 戻り値は stat
; szFilePath : LPCWSTR -> "wptr"
; dwOptions : DWORD -> "wptr"
; pHash : MSIFILEHASHINFO* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetFileHashW "MsiGetFileHashW" wstr, int, var
; res = MsiGetFileHashW(szFilePath, dwOptions, pHash)
; szFilePath : LPCWSTR -> "wstr"
; dwOptions : DWORD -> "int"
; pHash : MSIFILEHASHINFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiGetFileHashW(LPCWSTR szFilePath, DWORD dwOptions, MSIFILEHASHINFO* pHash)
#uselib "msi.dll"
#cfunc global MsiGetFileHashW "MsiGetFileHashW" wstr, int, var
; res = MsiGetFileHashW(szFilePath, dwOptions, pHash)
; szFilePath : LPCWSTR -> "wstr"
; dwOptions : DWORD -> "int"
; pHash : MSIFILEHASHINFO* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetFileHashW = msi.NewProc("MsiGetFileHashW")
)

// szFilePath (LPCWSTR), dwOptions (DWORD), pHash (MSIFILEHASHINFO* in/out)
r1, _, err := procMsiGetFileHashW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(szFilePath))),
	uintptr(dwOptions),
	uintptr(pHash),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function MsiGetFileHashW(
  szFilePath: PWideChar;   // LPCWSTR
  dwOptions: DWORD;   // DWORD
  pHash: Pointer   // MSIFILEHASHINFO* in/out
): DWORD; stdcall;
  external 'msi.dll' name 'MsiGetFileHashW';
result := DllCall("msi\MsiGetFileHashW"
    , "WStr", szFilePath   ; LPCWSTR
    , "UInt", dwOptions   ; DWORD
    , "Ptr", pHash   ; MSIFILEHASHINFO* in/out
    , "UInt")   ; return: DWORD
●MsiGetFileHashW(szFilePath, dwOptions, pHash) = DLL("msi.dll", "dword MsiGetFileHashW(char*, dword, void*)")
# 呼び出し: MsiGetFileHashW(szFilePath, dwOptions, pHash)
# szFilePath : LPCWSTR -> "char*"
# dwOptions : DWORD -> "dword"
# pHash : MSIFILEHASHINFO* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。