Win32 API 日本語リファレンス
ホームStorage.FileSystem › GetFileVersionInfoA

GetFileVersionInfoA

関数
ファイルのバージョン情報を取得する(ANSI版)。
DLLVERSION.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

BOOL GetFileVersionInfoA(
    LPCSTR lptstrFilename,
    DWORD dwHandle,   // optional
    DWORD dwLen,
    void* lpData
);

パラメーター

名前方向
lptstrFilenameLPCSTRin
dwHandleDWORDoptional
dwLenDWORDin
lpDatavoid*out

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetFileVersionInfoA(
    LPCSTR lptstrFilename,
    DWORD dwHandle,   // optional
    DWORD dwLen,
    void* lpData
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("VERSION.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool GetFileVersionInfoA(
    [MarshalAs(UnmanagedType.LPStr)] string lptstrFilename,   // LPCSTR
    uint dwHandle,   // DWORD optional
    uint dwLen,   // DWORD
    IntPtr lpData   // void* out
);
<DllImport("VERSION.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetFileVersionInfoA(
    <MarshalAs(UnmanagedType.LPStr)> lptstrFilename As String,   ' LPCSTR
    dwHandle As UInteger,   ' DWORD optional
    dwLen As UInteger,   ' DWORD
    lpData As IntPtr   ' void* out
) As Boolean
End Function
' lptstrFilename : LPCSTR
' dwHandle : DWORD optional
' dwLen : DWORD
' lpData : void* out
Declare PtrSafe Function GetFileVersionInfoA Lib "version" ( _
    ByVal lptstrFilename As String, _
    ByVal dwHandle As Long, _
    ByVal dwLen As Long, _
    ByVal lpData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetFileVersionInfoA = ctypes.windll.version.GetFileVersionInfoA
GetFileVersionInfoA.restype = wintypes.BOOL
GetFileVersionInfoA.argtypes = [
    wintypes.LPCSTR,  # lptstrFilename : LPCSTR
    wintypes.DWORD,  # dwHandle : DWORD optional
    wintypes.DWORD,  # dwLen : DWORD
    ctypes.POINTER(None),  # lpData : void* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('VERSION.dll')
GetFileVersionInfoA = Fiddle::Function.new(
  lib['GetFileVersionInfoA'],
  [
    Fiddle::TYPE_VOIDP,  # lptstrFilename : LPCSTR
    -Fiddle::TYPE_INT,  # dwHandle : DWORD optional
    -Fiddle::TYPE_INT,  # dwLen : DWORD
    Fiddle::TYPE_VOIDP,  # lpData : void* out
  ],
  Fiddle::TYPE_INT)
#[link(name = "version")]
extern "system" {
    fn GetFileVersionInfoA(
        lptstrFilename: *const u8,  // LPCSTR
        dwHandle: u32,  // DWORD optional
        dwLen: u32,  // DWORD
        lpData: *mut ()  // void* out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("VERSION.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool GetFileVersionInfoA([MarshalAs(UnmanagedType.LPStr)] string lptstrFilename, uint dwHandle, uint dwLen, IntPtr lpData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'VERSION_GetFileVersionInfoA' -Namespace Win32 -PassThru
# $api::GetFileVersionInfoA(lptstrFilename, dwHandle, dwLen, lpData)
#uselib "VERSION.dll"
#func global GetFileVersionInfoA "GetFileVersionInfoA" sptr, sptr, sptr, sptr
; GetFileVersionInfoA lptstrFilename, dwHandle, dwLen, lpData   ; 戻り値は stat
; lptstrFilename : LPCSTR -> "sptr"
; dwHandle : DWORD optional -> "sptr"
; dwLen : DWORD -> "sptr"
; lpData : void* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "VERSION.dll"
#cfunc global GetFileVersionInfoA "GetFileVersionInfoA" str, int, int, sptr
; res = GetFileVersionInfoA(lptstrFilename, dwHandle, dwLen, lpData)
; lptstrFilename : LPCSTR -> "str"
; dwHandle : DWORD optional -> "int"
; dwLen : DWORD -> "int"
; lpData : void* out -> "sptr"
; BOOL GetFileVersionInfoA(LPCSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, void* lpData)
#uselib "VERSION.dll"
#cfunc global GetFileVersionInfoA "GetFileVersionInfoA" str, int, int, intptr
; res = GetFileVersionInfoA(lptstrFilename, dwHandle, dwLen, lpData)
; lptstrFilename : LPCSTR -> "str"
; dwHandle : DWORD optional -> "int"
; dwLen : DWORD -> "int"
; lpData : void* out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	version = windows.NewLazySystemDLL("VERSION.dll")
	procGetFileVersionInfoA = version.NewProc("GetFileVersionInfoA")
)

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