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

GetFileVersionInfoSizeW

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

シグネチャ

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

DWORD GetFileVersionInfoSizeW(
    LPCWSTR lptstrFilename,
    DWORD* lpdwHandle   // optional
);

パラメーター

名前方向
lptstrFilenameLPCWSTRin
lpdwHandleDWORD*outoptional

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetFileVersionInfoSizeW(
    LPCWSTR lptstrFilename,
    DWORD* lpdwHandle   // optional
);
[DllImport("VERSION.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern uint GetFileVersionInfoSizeW(
    [MarshalAs(UnmanagedType.LPWStr)] string lptstrFilename,   // LPCWSTR
    IntPtr lpdwHandle   // DWORD* optional, out
);
<DllImport("VERSION.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetFileVersionInfoSizeW(
    <MarshalAs(UnmanagedType.LPWStr)> lptstrFilename As String,   ' LPCWSTR
    lpdwHandle As IntPtr   ' DWORD* optional, out
) As UInteger
End Function
' lptstrFilename : LPCWSTR
' lpdwHandle : DWORD* optional, out
Declare PtrSafe Function GetFileVersionInfoSizeW Lib "version" ( _
    ByVal lptstrFilename As LongPtr, _
    ByVal lpdwHandle 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

GetFileVersionInfoSizeW = ctypes.windll.version.GetFileVersionInfoSizeW
GetFileVersionInfoSizeW.restype = wintypes.DWORD
GetFileVersionInfoSizeW.argtypes = [
    wintypes.LPCWSTR,  # lptstrFilename : LPCWSTR
    ctypes.POINTER(wintypes.DWORD),  # lpdwHandle : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	version = windows.NewLazySystemDLL("VERSION.dll")
	procGetFileVersionInfoSizeW = version.NewProc("GetFileVersionInfoSizeW")
)

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