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

MsiGetFileVersionW

関数
指定ファイルのバージョンと言語の情報を取得する。
DLLmsi.dll文字セットUnicode (-W)呼出規約winapi対応OSwindows8.0

シグネチャ

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

DWORD MsiGetFileVersionW(
    LPCWSTR szFilePath,
    LPWSTR lpVersionBuf,   // optional
    DWORD* pcchVersionBuf,   // optional
    LPWSTR lpLangBuf,   // optional
    DWORD* pcchLangBuf   // optional
);

パラメーター

名前方向
szFilePathLPCWSTRin
lpVersionBufLPWSTRoutoptional
pcchVersionBufDWORD*inoutoptional
lpLangBufLPWSTRoutoptional
pcchLangBufDWORD*inoutoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD MsiGetFileVersionW(
    LPCWSTR szFilePath,
    LPWSTR lpVersionBuf,   // optional
    DWORD* pcchVersionBuf,   // optional
    LPWSTR lpLangBuf,   // optional
    DWORD* pcchLangBuf   // optional
);
[DllImport("msi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint MsiGetFileVersionW(
    [MarshalAs(UnmanagedType.LPWStr)] string szFilePath,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpVersionBuf,   // LPWSTR optional, out
    IntPtr pcchVersionBuf,   // DWORD* optional, in/out
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpLangBuf,   // LPWSTR optional, out
    IntPtr pcchLangBuf   // DWORD* optional, in/out
);
<DllImport("msi.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function MsiGetFileVersionW(
    <MarshalAs(UnmanagedType.LPWStr)> szFilePath As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpVersionBuf As System.Text.StringBuilder,   ' LPWSTR optional, out
    pcchVersionBuf As IntPtr,   ' DWORD* optional, in/out
    <MarshalAs(UnmanagedType.LPWStr)> lpLangBuf As System.Text.StringBuilder,   ' LPWSTR optional, out
    pcchLangBuf As IntPtr   ' DWORD* optional, in/out
) As UInteger
End Function
' szFilePath : LPCWSTR
' lpVersionBuf : LPWSTR optional, out
' pcchVersionBuf : DWORD* optional, in/out
' lpLangBuf : LPWSTR optional, out
' pcchLangBuf : DWORD* optional, in/out
Declare PtrSafe Function MsiGetFileVersionW Lib "msi" ( _
    ByVal szFilePath As LongPtr, _
    ByVal lpVersionBuf As LongPtr, _
    ByVal pcchVersionBuf As LongPtr, _
    ByVal lpLangBuf As LongPtr, _
    ByVal pcchLangBuf 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

MsiGetFileVersionW = ctypes.windll.msi.MsiGetFileVersionW
MsiGetFileVersionW.restype = wintypes.DWORD
MsiGetFileVersionW.argtypes = [
    wintypes.LPCWSTR,  # szFilePath : LPCWSTR
    wintypes.LPWSTR,  # lpVersionBuf : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchVersionBuf : DWORD* optional, in/out
    wintypes.LPWSTR,  # lpLangBuf : LPWSTR optional, out
    ctypes.POINTER(wintypes.DWORD),  # pcchLangBuf : DWORD* optional, in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('msi.dll')
MsiGetFileVersionW = Fiddle::Function.new(
  lib['MsiGetFileVersionW'],
  [
    Fiddle::TYPE_VOIDP,  # szFilePath : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpVersionBuf : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchVersionBuf : DWORD* optional, in/out
    Fiddle::TYPE_VOIDP,  # lpLangBuf : LPWSTR optional, out
    Fiddle::TYPE_VOIDP,  # pcchLangBuf : DWORD* optional, in/out
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "msi")]
extern "system" {
    fn MsiGetFileVersionW(
        szFilePath: *const u16,  // LPCWSTR
        lpVersionBuf: *mut u16,  // LPWSTR optional, out
        pcchVersionBuf: *mut u32,  // DWORD* optional, in/out
        lpLangBuf: *mut u16,  // LPWSTR optional, out
        pcchLangBuf: *mut u32  // DWORD* optional, in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("msi.dll", CharSet = CharSet.Unicode)]
public static extern uint MsiGetFileVersionW([MarshalAs(UnmanagedType.LPWStr)] string szFilePath, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpVersionBuf, IntPtr pcchVersionBuf, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder lpLangBuf, IntPtr pcchLangBuf);
"@
$api = Add-Type -MemberDefinition $sig -Name 'msi_MsiGetFileVersionW' -Namespace Win32 -PassThru
# $api::MsiGetFileVersionW(szFilePath, lpVersionBuf, pcchVersionBuf, lpLangBuf, pcchLangBuf)
#uselib "msi.dll"
#func global MsiGetFileVersionW "MsiGetFileVersionW" wptr, wptr, wptr, wptr, wptr
; MsiGetFileVersionW szFilePath, varptr(lpVersionBuf), varptr(pcchVersionBuf), varptr(lpLangBuf), varptr(pcchLangBuf)   ; 戻り値は stat
; szFilePath : LPCWSTR -> "wptr"
; lpVersionBuf : LPWSTR optional, out -> "wptr"
; pcchVersionBuf : DWORD* optional, in/out -> "wptr"
; lpLangBuf : LPWSTR optional, out -> "wptr"
; pcchLangBuf : DWORD* optional, in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "msi.dll"
#cfunc global MsiGetFileVersionW "MsiGetFileVersionW" wstr, var, var, var, var
; res = MsiGetFileVersionW(szFilePath, lpVersionBuf, pcchVersionBuf, lpLangBuf, pcchLangBuf)
; szFilePath : LPCWSTR -> "wstr"
; lpVersionBuf : LPWSTR optional, out -> "var"
; pcchVersionBuf : DWORD* optional, in/out -> "var"
; lpLangBuf : LPWSTR optional, out -> "var"
; pcchLangBuf : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD MsiGetFileVersionW(LPCWSTR szFilePath, LPWSTR lpVersionBuf, DWORD* pcchVersionBuf, LPWSTR lpLangBuf, DWORD* pcchLangBuf)
#uselib "msi.dll"
#cfunc global MsiGetFileVersionW "MsiGetFileVersionW" wstr, var, var, var, var
; res = MsiGetFileVersionW(szFilePath, lpVersionBuf, pcchVersionBuf, lpLangBuf, pcchLangBuf)
; szFilePath : LPCWSTR -> "wstr"
; lpVersionBuf : LPWSTR optional, out -> "var"
; pcchVersionBuf : DWORD* optional, in/out -> "var"
; lpLangBuf : LPWSTR optional, out -> "var"
; pcchLangBuf : DWORD* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	msi = windows.NewLazySystemDLL("msi.dll")
	procMsiGetFileVersionW = msi.NewProc("MsiGetFileVersionW")
)

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