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

GetFileInformationByName

関数
ファイル名から指定クラスのファイル情報を取得する。
DLLKERNEL32.dll呼出規約winapi

シグネチャ

// KERNEL32.dll
#include <windows.h>

BOOL GetFileInformationByName(
    LPCWSTR FileName,
    FILE_INFO_BY_NAME_CLASS FileInformationClass,
    void* FileInfoBuffer,
    DWORD FileInfoBufferSize
);

パラメーター

名前方向
FileNameLPCWSTRin
FileInformationClassFILE_INFO_BY_NAME_CLASSin
FileInfoBuffervoid*out
FileInfoBufferSizeDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

BOOL GetFileInformationByName(
    LPCWSTR FileName,
    FILE_INFO_BY_NAME_CLASS FileInformationClass,
    void* FileInfoBuffer,
    DWORD FileInfoBufferSize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool GetFileInformationByName(
    [MarshalAs(UnmanagedType.LPWStr)] string FileName,   // LPCWSTR
    int FileInformationClass,   // FILE_INFO_BY_NAME_CLASS
    IntPtr FileInfoBuffer,   // void* out
    uint FileInfoBufferSize   // DWORD
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function GetFileInformationByName(
    <MarshalAs(UnmanagedType.LPWStr)> FileName As String,   ' LPCWSTR
    FileInformationClass As Integer,   ' FILE_INFO_BY_NAME_CLASS
    FileInfoBuffer As IntPtr,   ' void* out
    FileInfoBufferSize As UInteger   ' DWORD
) As Boolean
End Function
' FileName : LPCWSTR
' FileInformationClass : FILE_INFO_BY_NAME_CLASS
' FileInfoBuffer : void* out
' FileInfoBufferSize : DWORD
Declare PtrSafe Function GetFileInformationByName Lib "kernel32" ( _
    ByVal FileName As LongPtr, _
    ByVal FileInformationClass As Long, _
    ByVal FileInfoBuffer As LongPtr, _
    ByVal FileInfoBufferSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetFileInformationByName = ctypes.windll.kernel32.GetFileInformationByName
GetFileInformationByName.restype = wintypes.BOOL
GetFileInformationByName.argtypes = [
    wintypes.LPCWSTR,  # FileName : LPCWSTR
    ctypes.c_int,  # FileInformationClass : FILE_INFO_BY_NAME_CLASS
    ctypes.POINTER(None),  # FileInfoBuffer : void* out
    wintypes.DWORD,  # FileInfoBufferSize : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetFileInformationByName = Fiddle::Function.new(
  lib['GetFileInformationByName'],
  [
    Fiddle::TYPE_VOIDP,  # FileName : LPCWSTR
    Fiddle::TYPE_INT,  # FileInformationClass : FILE_INFO_BY_NAME_CLASS
    Fiddle::TYPE_VOIDP,  # FileInfoBuffer : void* out
    -Fiddle::TYPE_INT,  # FileInfoBufferSize : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetFileInformationByName(
        FileName: *const u16,  // LPCWSTR
        FileInformationClass: i32,  // FILE_INFO_BY_NAME_CLASS
        FileInfoBuffer: *mut (),  // void* out
        FileInfoBufferSize: u32  // DWORD
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll")]
public static extern bool GetFileInformationByName([MarshalAs(UnmanagedType.LPWStr)] string FileName, int FileInformationClass, IntPtr FileInfoBuffer, uint FileInfoBufferSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetFileInformationByName' -Namespace Win32 -PassThru
# $api::GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize)
#uselib "KERNEL32.dll"
#func global GetFileInformationByName "GetFileInformationByName" sptr, sptr, sptr, sptr
; GetFileInformationByName FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize   ; 戻り値は stat
; FileName : LPCWSTR -> "sptr"
; FileInformationClass : FILE_INFO_BY_NAME_CLASS -> "sptr"
; FileInfoBuffer : void* out -> "sptr"
; FileInfoBufferSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global GetFileInformationByName "GetFileInformationByName" wstr, int, sptr, int
; res = GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize)
; FileName : LPCWSTR -> "wstr"
; FileInformationClass : FILE_INFO_BY_NAME_CLASS -> "int"
; FileInfoBuffer : void* out -> "sptr"
; FileInfoBufferSize : DWORD -> "int"
; BOOL GetFileInformationByName(LPCWSTR FileName, FILE_INFO_BY_NAME_CLASS FileInformationClass, void* FileInfoBuffer, DWORD FileInfoBufferSize)
#uselib "KERNEL32.dll"
#cfunc global GetFileInformationByName "GetFileInformationByName" wstr, int, intptr, int
; res = GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize)
; FileName : LPCWSTR -> "wstr"
; FileInformationClass : FILE_INFO_BY_NAME_CLASS -> "int"
; FileInfoBuffer : void* out -> "intptr"
; FileInfoBufferSize : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetFileInformationByName = kernel32.NewProc("GetFileInformationByName")
)

// FileName (LPCWSTR), FileInformationClass (FILE_INFO_BY_NAME_CLASS), FileInfoBuffer (void* out), FileInfoBufferSize (DWORD)
r1, _, err := procGetFileInformationByName.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(FileName))),
	uintptr(FileInformationClass),
	uintptr(FileInfoBuffer),
	uintptr(FileInfoBufferSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetFileInformationByName(
  FileName: PWideChar;   // LPCWSTR
  FileInformationClass: Integer;   // FILE_INFO_BY_NAME_CLASS
  FileInfoBuffer: Pointer;   // void* out
  FileInfoBufferSize: DWORD   // DWORD
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'GetFileInformationByName';
result := DllCall("KERNEL32\GetFileInformationByName"
    , "WStr", FileName   ; LPCWSTR
    , "Int", FileInformationClass   ; FILE_INFO_BY_NAME_CLASS
    , "Ptr", FileInfoBuffer   ; void* out
    , "UInt", FileInfoBufferSize   ; DWORD
    , "Int")   ; return: BOOL
●GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize) = DLL("KERNEL32.dll", "bool GetFileInformationByName(char*, int, void*, dword)")
# 呼び出し: GetFileInformationByName(FileName, FileInformationClass, FileInfoBuffer, FileInfoBufferSize)
# FileName : LPCWSTR -> "char*"
# FileInformationClass : FILE_INFO_BY_NAME_CLASS -> "int"
# FileInfoBuffer : void* out -> "void*"
# FileInfoBufferSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。