GetFileVersionInfoW
関数シグネチャ
// VERSION.dll (Unicode / -W)
#include <windows.h>
BOOL GetFileVersionInfoW(
LPCWSTR lptstrFilename,
DWORD dwHandle, // optional
DWORD dwLen,
void* lpData
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lptstrFilename | LPCWSTR | in | ファイルの名前です。フルパスが指定されていない場合、この関数は LoadLibrary 関数で指定される検索順序を使用します。 |
| dwHandle | DWORD | optional | このパラメーターは無視されます。 |
| dwLen | DWORD | in | lpData パラメーターが指すバッファーのサイズ(バイト単位)です。 まず GetFileVersionInfoSize 関数を呼び出して、ファイルのバージョン情報のサイズ(バイト単位)を判定してください。dwLen メンバーはその値以上である必要があります。 lpData が指すバッファーが十分に大きくない場合、この関数はファイルのバージョン情報をバッファーのサイズに切り詰めます。 |
| lpData | void* | out | ファイルのバージョン情報を受け取るバッファーへのポインターです。 この値は、後続の VerQueryValue 関数の呼び出しでバッファーからデータを取得するために使用できます。 |
戻り値の型: BOOL
公式ドキュメント
指定されたファイルのバージョン情報を取得します。(GetFileVersionInfoW)
戻り値
解説(Remarks)
ファイルのバージョン情報には、固定部分と非固定部分があります。固定部分にはバージョン番号などの情報が含まれます。非固定部分には文字列などが含まれます。以前は GetFileVersionInfo はバイナリ(exe/dll)からバージョン情報を取得していました。現在では、固定バージョンを言語ニュートラルなファイル(exe/dll)から、非固定部分を mui ファイルから照会し、それらをマージしてユーザーに返します。 指定されたバイナリに mui ファイルがない場合は、以前のバージョンと同じ動作になります。
GetFileVersionInfo 関数を呼び出す前に、GetFileVersionInfoSize 関数を呼び出してください。ファイルのバージョン情報バッファーから情報を取得するには、VerQueryValue 関数を使用してください。
winver.h ヘッダーは GetFileVersionInfo を、UNICODE プリプロセッサ定数の定義に基づいてこの関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして定義しています。エンコーディングニュートラルなエイリアスの使用を、エンコーディングニュートラルでないコードと混在させると、コンパイルエラーや実行時エラーを引き起こす不一致につながる可能性があります。詳細については、Conventions for Function Prototypes を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// VERSION.dll (Unicode / -W)
#include <windows.h>
BOOL GetFileVersionInfoW(
LPCWSTR lptstrFilename,
DWORD dwHandle, // optional
DWORD dwLen,
void* lpData
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("VERSION.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool GetFileVersionInfoW(
[MarshalAs(UnmanagedType.LPWStr)] string lptstrFilename, // LPCWSTR
uint dwHandle, // DWORD optional
uint dwLen, // DWORD
IntPtr lpData // void* out
);<DllImport("VERSION.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetFileVersionInfoW(
<MarshalAs(UnmanagedType.LPWStr)> lptstrFilename As String, ' LPCWSTR
dwHandle As UInteger, ' DWORD optional
dwLen As UInteger, ' DWORD
lpData As IntPtr ' void* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' lptstrFilename : LPCWSTR
' dwHandle : DWORD optional
' dwLen : DWORD
' lpData : void* out
Declare PtrSafe Function GetFileVersionInfoW Lib "version" ( _
ByVal lptstrFilename As LongPtr, _
ByVal dwHandle As Long, _
ByVal dwLen As Long, _
ByVal lpData 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
GetFileVersionInfoW = ctypes.windll.version.GetFileVersionInfoW
GetFileVersionInfoW.restype = wintypes.BOOL
GetFileVersionInfoW.argtypes = [
wintypes.LPCWSTR, # lptstrFilename : LPCWSTR
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')
GetFileVersionInfoW = Fiddle::Function.new(
lib['GetFileVersionInfoW'],
[
Fiddle::TYPE_VOIDP, # lptstrFilename : LPCWSTR
-Fiddle::TYPE_INT, # dwHandle : DWORD optional
-Fiddle::TYPE_INT, # dwLen : DWORD
Fiddle::TYPE_VOIDP, # lpData : void* out
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "version")]
extern "system" {
fn GetFileVersionInfoW(
lptstrFilename: *const u16, // LPCWSTR
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.Unicode, SetLastError = true)]
public static extern bool GetFileVersionInfoW([MarshalAs(UnmanagedType.LPWStr)] string lptstrFilename, uint dwHandle, uint dwLen, IntPtr lpData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'VERSION_GetFileVersionInfoW' -Namespace Win32 -PassThru
# $api::GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData)#uselib "VERSION.dll"
#func global GetFileVersionInfoW "GetFileVersionInfoW" wptr, wptr, wptr, wptr
; GetFileVersionInfoW lptstrFilename, dwHandle, dwLen, lpData ; 戻り値は stat
; lptstrFilename : LPCWSTR -> "wptr"
; dwHandle : DWORD optional -> "wptr"
; dwLen : DWORD -> "wptr"
; lpData : void* out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "VERSION.dll"
#cfunc global GetFileVersionInfoW "GetFileVersionInfoW" wstr, int, int, sptr
; res = GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData)
; lptstrFilename : LPCWSTR -> "wstr"
; dwHandle : DWORD optional -> "int"
; dwLen : DWORD -> "int"
; lpData : void* out -> "sptr"; BOOL GetFileVersionInfoW(LPCWSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, void* lpData)
#uselib "VERSION.dll"
#cfunc global GetFileVersionInfoW "GetFileVersionInfoW" wstr, int, int, intptr
; res = GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData)
; lptstrFilename : LPCWSTR -> "wstr"
; dwHandle : DWORD optional -> "int"
; dwLen : DWORD -> "int"
; lpData : void* out -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
version = windows.NewLazySystemDLL("VERSION.dll")
procGetFileVersionInfoW = version.NewProc("GetFileVersionInfoW")
)
// lptstrFilename (LPCWSTR), dwHandle (DWORD optional), dwLen (DWORD), lpData (void* out)
r1, _, err := procGetFileVersionInfoW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lptstrFilename))),
uintptr(dwHandle),
uintptr(dwLen),
uintptr(lpData),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction GetFileVersionInfoW(
lptstrFilename: PWideChar; // LPCWSTR
dwHandle: DWORD; // DWORD optional
dwLen: DWORD; // DWORD
lpData: Pointer // void* out
): BOOL; stdcall;
external 'VERSION.dll' name 'GetFileVersionInfoW';result := DllCall("VERSION\GetFileVersionInfoW"
, "WStr", lptstrFilename ; LPCWSTR
, "UInt", dwHandle ; DWORD optional
, "UInt", dwLen ; DWORD
, "Ptr", lpData ; void* out
, "Int") ; return: BOOL●GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData) = DLL("VERSION.dll", "bool GetFileVersionInfoW(char*, dword, dword, void*)")
# 呼び出し: GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData)
# lptstrFilename : LPCWSTR -> "char*"
# dwHandle : DWORD optional -> "dword"
# dwLen : DWORD -> "dword"
# lpData : void* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。const std = @import("std");
extern "version" fn GetFileVersionInfoW(
lptstrFilename: [*c]const u16, // LPCWSTR
dwHandle: u32, // DWORD optional
dwLen: u32, // DWORD
lpData: ?*anyopaque // void* out
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc GetFileVersionInfoW(
lptstrFilename: WideCString, # LPCWSTR
dwHandle: uint32, # DWORD optional
dwLen: uint32, # DWORD
lpData: pointer # void* out
): int32 {.importc: "GetFileVersionInfoW", stdcall, dynlib: "VERSION.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "version");
extern(Windows)
int GetFileVersionInfoW(
const(wchar)* lptstrFilename, // LPCWSTR
uint dwHandle, // DWORD optional
uint dwLen, // DWORD
void* lpData // void* out
);ccall((:GetFileVersionInfoW, "VERSION.dll"), stdcall, Int32,
(Cwstring, UInt32, UInt32, Ptr{Cvoid}),
lptstrFilename, dwHandle, dwLen, lpData)
# lptstrFilename : LPCWSTR -> Cwstring
# dwHandle : DWORD optional -> UInt32
# dwLen : DWORD -> UInt32
# lpData : void* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
int32_t GetFileVersionInfoW(
const uint16_t* lptstrFilename,
uint32_t dwHandle,
uint32_t dwLen,
void* lpData);
]]
local version = ffi.load("version")
-- version.GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData)
-- lptstrFilename : LPCWSTR
-- dwHandle : DWORD optional
-- dwLen : DWORD
-- lpData : void* 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('VERSION.dll');
const GetFileVersionInfoW = lib.func('__stdcall', 'GetFileVersionInfoW', 'int32_t', ['str16', 'uint32_t', 'uint32_t', 'void *']);
// GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData)
// lptstrFilename : LPCWSTR -> 'str16'
// dwHandle : DWORD optional -> 'uint32_t'
// dwLen : DWORD -> 'uint32_t'
// lpData : void* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("VERSION.dll", {
GetFileVersionInfoW: { parameters: ["buffer", "u32", "u32", "pointer"], result: "i32" },
});
// lib.symbols.GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData)
// lptstrFilename : LPCWSTR -> "buffer"
// dwHandle : DWORD optional -> "u32"
// dwLen : DWORD -> "u32"
// lpData : void* out -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GetFileVersionInfoW(
const uint16_t* lptstrFilename,
uint32_t dwHandle,
uint32_t dwLen,
void* lpData);
C, "VERSION.dll");
// $ffi->GetFileVersionInfoW(lptstrFilename, dwHandle, dwLen, lpData);
// lptstrFilename : LPCWSTR
// dwHandle : DWORD optional
// dwLen : DWORD
// lpData : void* 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 Version extends StdCallLibrary {
Version INSTANCE = Native.load("version", Version.class, W32APIOptions.UNICODE_OPTIONS);
boolean GetFileVersionInfoW(
WString lptstrFilename, // LPCWSTR
int dwHandle, // DWORD optional
int dwLen, // DWORD
Pointer lpData // void* out
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("version")]
lib LibVERSION
fun GetFileVersionInfoW = GetFileVersionInfoW(
lptstrFilename : UInt16*, # LPCWSTR
dwHandle : UInt32, # DWORD optional
dwLen : UInt32, # DWORD
lpData : Void* # void* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetFileVersionInfoWNative = Int32 Function(Pointer<Utf16>, Uint32, Uint32, Pointer<Void>);
typedef GetFileVersionInfoWDart = int Function(Pointer<Utf16>, int, int, Pointer<Void>);
final GetFileVersionInfoW = DynamicLibrary.open('VERSION.dll')
.lookupFunction<GetFileVersionInfoWNative, GetFileVersionInfoWDart>('GetFileVersionInfoW');
// lptstrFilename : LPCWSTR -> Pointer<Utf16>
// dwHandle : DWORD optional -> Uint32
// dwLen : DWORD -> Uint32
// lpData : void* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetFileVersionInfoW(
lptstrFilename: PWideChar; // LPCWSTR
dwHandle: DWORD; // DWORD optional
dwLen: DWORD; // DWORD
lpData: Pointer // void* out
): BOOL; stdcall;
external 'VERSION.dll' name 'GetFileVersionInfoW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetFileVersionInfoW"
c_GetFileVersionInfoW :: CWString -> Word32 -> Word32 -> Ptr () -> IO CInt
-- lptstrFilename : LPCWSTR -> CWString
-- dwHandle : DWORD optional -> Word32
-- dwLen : DWORD -> Word32
-- lpData : void* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getfileversioninfow =
foreign "GetFileVersionInfoW"
((ptr uint16_t) @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning int32_t)
(* lptstrFilename : LPCWSTR -> (ptr uint16_t) *)
(* dwHandle : DWORD optional -> uint32_t *)
(* dwLen : DWORD -> uint32_t *)
(* lpData : void* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library version (t "VERSION.dll"))
(cffi:use-foreign-library version)
(cffi:defcfun ("GetFileVersionInfoW" get-file-version-info-w :convention :stdcall) :int32
(lptstr-filename (:string :encoding :utf-16le)) ; LPCWSTR
(dw-handle :uint32) ; DWORD optional
(dw-len :uint32) ; DWORD
(lp-data :pointer)) ; void* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetFileVersionInfoW = Win32::API::More->new('VERSION',
'BOOL GetFileVersionInfoW(LPCWSTR lptstrFilename, DWORD dwHandle, DWORD dwLen, LPVOID lpData)');
# my $ret = $GetFileVersionInfoW->Call($lptstrFilename, $dwHandle, $dwLen, $lpData);
# lptstrFilename : LPCWSTR -> LPCWSTR
# dwHandle : DWORD optional -> DWORD
# dwLen : DWORD -> DWORD
# lpData : void* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f GetFileVersionInfoA (ANSI版) — ファイルのバージョン情報を取得する(ANSI版)。
- f GetFileVersionInfoExW — フラグ指定でファイルのバージョン情報を取得する。
- f GetFileVersionInfoSizeW — ファイルのバージョン情報の必要バッファサイズを取得する。
- f VerQueryValueW — バージョン情報ブロックから指定値を取得する。