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

GetFileAttributesExFromAppW

関数
アプリコンテナからファイルの拡張属性情報を取得する。
DLLapi-ms-win-core-file-fromapp-l1-1-0.dll呼出規約winapi

シグネチャ

// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>

BOOL GetFileAttributesExFromAppW(
    LPCWSTR lpFileName,
    GET_FILEEX_INFO_LEVELS fInfoLevelId,
    void* lpFileInformation
);

パラメーター

名前方向説明
lpFileNameLPCWSTRin

ファイルまたはディレクトリの名前です。

"\\?\" を先頭に付加せずに MAX_PATH の制限を回避する方法については、ファイル、パス、および名前空間の名前付けの「最大パス長の制限」セクションを参照してください。

fInfoLevelIdGET_FILEEX_INFO_LEVELSin

取得する属性情報のクラスです。

このパラメーターには、GET_FILEEX_INFO_LEVELS 列挙体の次の値を指定できます。

意味
GetFileExInfoStandard lpFileInformation パラメーターは WIN32_FILE_ATTRIBUTE_DATA 構造体です。
lpFileInformationvoid*out

属性情報を受け取るバッファーへのポインターです。

このバッファーに格納される属性情報の種類は、fInfoLevelId の値によって決まります。

戻り値の型: BOOL

公式ドキュメント

指定したファイルまたはディレクトリの属性を取得します。この関数の動作は GetFileAttributesEx と同一ですが、ユニバーサル Windows プラットフォーム アプリのセキュリティ モデルに従う点が異なります。

戻り値

関数が成功した場合、戻り値は 0 以外の値になります。

関数が失敗した場合、戻り値は 0 (0) になります。拡張エラー情報を取得するには、GetLastError を呼び出してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>

BOOL GetFileAttributesExFromAppW(
    LPCWSTR lpFileName,
    GET_FILEEX_INFO_LEVELS fInfoLevelId,
    void* lpFileInformation
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling = true)]
static extern bool GetFileAttributesExFromAppW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpFileName,   // LPCWSTR
    int fInfoLevelId,   // GET_FILEEX_INFO_LEVELS
    IntPtr lpFileInformation   // void* out
);
<DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function GetFileAttributesExFromAppW(
    <MarshalAs(UnmanagedType.LPWStr)> lpFileName As String,   ' LPCWSTR
    fInfoLevelId As Integer,   ' GET_FILEEX_INFO_LEVELS
    lpFileInformation As IntPtr   ' void* out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' lpFileName : LPCWSTR
' fInfoLevelId : GET_FILEEX_INFO_LEVELS
' lpFileInformation : void* out
Declare PtrSafe Function GetFileAttributesExFromAppW Lib "api-ms-win-core-file-fromapp-l1-1-0" ( _
    ByVal lpFileName As LongPtr, _
    ByVal fInfoLevelId As Long, _
    ByVal lpFileInformation As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetFileAttributesExFromAppW = ctypes.windll.LoadLibrary("api-ms-win-core-file-fromapp-l1-1-0.dll").GetFileAttributesExFromAppW
GetFileAttributesExFromAppW.restype = wintypes.BOOL
GetFileAttributesExFromAppW.argtypes = [
    wintypes.LPCWSTR,  # lpFileName : LPCWSTR
    ctypes.c_int,  # fInfoLevelId : GET_FILEEX_INFO_LEVELS
    ctypes.POINTER(None),  # lpFileInformation : void* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	api_ms_win_core_file_fromapp_l1_1_0 = windows.NewLazySystemDLL("api-ms-win-core-file-fromapp-l1-1-0.dll")
	procGetFileAttributesExFromAppW = api_ms_win_core_file_fromapp_l1_1_0.NewProc("GetFileAttributesExFromAppW")
)

// lpFileName (LPCWSTR), fInfoLevelId (GET_FILEEX_INFO_LEVELS), lpFileInformation (void* out)
r1, _, err := procGetFileAttributesExFromAppW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
	uintptr(fInfoLevelId),
	uintptr(lpFileInformation),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetFileAttributesExFromAppW(
  lpFileName: PWideChar;   // LPCWSTR
  fInfoLevelId: Integer;   // GET_FILEEX_INFO_LEVELS
  lpFileInformation: Pointer   // void* out
): BOOL; stdcall;
  external 'api-ms-win-core-file-fromapp-l1-1-0.dll' name 'GetFileAttributesExFromAppW';
result := DllCall("api-ms-win-core-file-fromapp-l1-1-0\GetFileAttributesExFromAppW"
    , "WStr", lpFileName   ; LPCWSTR
    , "Int", fInfoLevelId   ; GET_FILEEX_INFO_LEVELS
    , "Ptr", lpFileInformation   ; void* out
    , "Int")   ; return: BOOL
●GetFileAttributesExFromAppW(lpFileName, fInfoLevelId, lpFileInformation) = DLL("api-ms-win-core-file-fromapp-l1-1-0.dll", "bool GetFileAttributesExFromAppW(char*, int, void*)")
# 呼び出し: GetFileAttributesExFromAppW(lpFileName, fInfoLevelId, lpFileInformation)
# lpFileName : LPCWSTR -> "char*"
# fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "int"
# lpFileInformation : void* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "api-ms-win-core-file-fromapp-l1-1-0" fn GetFileAttributesExFromAppW(
    lpFileName: [*c]const u16, // LPCWSTR
    fInfoLevelId: i32, // GET_FILEEX_INFO_LEVELS
    lpFileInformation: ?*anyopaque // void* out
) callconv(std.os.windows.WINAPI) i32;
proc GetFileAttributesExFromAppW(
    lpFileName: WideCString,  # LPCWSTR
    fInfoLevelId: int32,  # GET_FILEEX_INFO_LEVELS
    lpFileInformation: pointer  # void* out
): int32 {.importc: "GetFileAttributesExFromAppW", stdcall, dynlib: "api-ms-win-core-file-fromapp-l1-1-0.dll".}
pragma(lib, "api-ms-win-core-file-fromapp-l1-1-0");
extern(Windows)
int GetFileAttributesExFromAppW(
    const(wchar)* lpFileName,   // LPCWSTR
    int fInfoLevelId,   // GET_FILEEX_INFO_LEVELS
    void* lpFileInformation   // void* out
);
ccall((:GetFileAttributesExFromAppW, "api-ms-win-core-file-fromapp-l1-1-0.dll"), stdcall, Int32,
      (Cwstring, Int32, Ptr{Cvoid}),
      lpFileName, fInfoLevelId, lpFileInformation)
# lpFileName : LPCWSTR -> Cwstring
# fInfoLevelId : GET_FILEEX_INFO_LEVELS -> Int32
# lpFileInformation : void* out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t GetFileAttributesExFromAppW(
    const uint16_t* lpFileName,
    int32_t fInfoLevelId,
    void* lpFileInformation);
]]
local api-ms-win-core-file-fromapp-l1-1-0 = ffi.load("api-ms-win-core-file-fromapp-l1-1-0")
-- api-ms-win-core-file-fromapp-l1-1-0.GetFileAttributesExFromAppW(lpFileName, fInfoLevelId, lpFileInformation)
-- lpFileName : LPCWSTR
-- fInfoLevelId : GET_FILEEX_INFO_LEVELS
-- lpFileInformation : void* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('api-ms-win-core-file-fromapp-l1-1-0.dll');
const GetFileAttributesExFromAppW = lib.func('__stdcall', 'GetFileAttributesExFromAppW', 'int32_t', ['str16', 'int32_t', 'void *']);
// GetFileAttributesExFromAppW(lpFileName, fInfoLevelId, lpFileInformation)
// lpFileName : LPCWSTR -> 'str16'
// fInfoLevelId : GET_FILEEX_INFO_LEVELS -> 'int32_t'
// lpFileInformation : void* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("api-ms-win-core-file-fromapp-l1-1-0.dll", {
  GetFileAttributesExFromAppW: { parameters: ["buffer", "i32", "pointer"], result: "i32" },
});
// lib.symbols.GetFileAttributesExFromAppW(lpFileName, fInfoLevelId, lpFileInformation)
// lpFileName : LPCWSTR -> "buffer"
// fInfoLevelId : GET_FILEEX_INFO_LEVELS -> "i32"
// lpFileInformation : void* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t GetFileAttributesExFromAppW(
    const uint16_t* lpFileName,
    int32_t fInfoLevelId,
    void* lpFileInformation);
C, "api-ms-win-core-file-fromapp-l1-1-0.dll");
// $ffi->GetFileAttributesExFromAppW(lpFileName, fInfoLevelId, lpFileInformation);
// lpFileName : LPCWSTR
// fInfoLevelId : GET_FILEEX_INFO_LEVELS
// lpFileInformation : 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 Api-ms-win-core-file-fromapp-l1-1-0 extends StdCallLibrary {
    Api-ms-win-core-file-fromapp-l1-1-0 INSTANCE = Native.load("api-ms-win-core-file-fromapp-l1-1-0", Api-ms-win-core-file-fromapp-l1-1-0.class);
    boolean GetFileAttributesExFromAppW(
        WString lpFileName,   // LPCWSTR
        int fInfoLevelId,   // GET_FILEEX_INFO_LEVELS
        Pointer lpFileInformation   // void* out
    );
}
@[Link("api-ms-win-core-file-fromapp-l1-1-0")]
lib Libapi-ms-win-core-file-fromapp-l1-1-0
  fun GetFileAttributesExFromAppW = GetFileAttributesExFromAppW(
    lpFileName : UInt16*,   # LPCWSTR
    fInfoLevelId : Int32,   # GET_FILEEX_INFO_LEVELS
    lpFileInformation : 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 GetFileAttributesExFromAppWNative = Int32 Function(Pointer<Utf16>, Int32, Pointer<Void>);
typedef GetFileAttributesExFromAppWDart = int Function(Pointer<Utf16>, int, Pointer<Void>);
final GetFileAttributesExFromAppW = DynamicLibrary.open('api-ms-win-core-file-fromapp-l1-1-0.dll')
    .lookupFunction<GetFileAttributesExFromAppWNative, GetFileAttributesExFromAppWDart>('GetFileAttributesExFromAppW');
// lpFileName : LPCWSTR -> Pointer<Utf16>
// fInfoLevelId : GET_FILEEX_INFO_LEVELS -> Int32
// lpFileInformation : void* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function GetFileAttributesExFromAppW(
  lpFileName: PWideChar;   // LPCWSTR
  fInfoLevelId: Integer;   // GET_FILEEX_INFO_LEVELS
  lpFileInformation: Pointer   // void* out
): BOOL; stdcall;
  external 'api-ms-win-core-file-fromapp-l1-1-0.dll' name 'GetFileAttributesExFromAppW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "GetFileAttributesExFromAppW"
  c_GetFileAttributesExFromAppW :: CWString -> Int32 -> Ptr () -> IO CInt
-- lpFileName : LPCWSTR -> CWString
-- fInfoLevelId : GET_FILEEX_INFO_LEVELS -> Int32
-- lpFileInformation : void* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let getfileattributesexfromappw =
  foreign "GetFileAttributesExFromAppW"
    ((ptr uint16_t) @-> int32_t @-> (ptr void) @-> returning int32_t)
(* lpFileName : LPCWSTR -> (ptr uint16_t) *)
(* fInfoLevelId : GET_FILEEX_INFO_LEVELS -> int32_t *)
(* lpFileInformation : void* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library api-ms-win-core-file-fromapp-l1-1-0 (t "api-ms-win-core-file-fromapp-l1-1-0.dll"))
(cffi:use-foreign-library api-ms-win-core-file-fromapp-l1-1-0)

(cffi:defcfun ("GetFileAttributesExFromAppW" get-file-attributes-ex-from-app-w :convention :stdcall) :int32
  (lp-file-name (:string :encoding :utf-16le))   ; LPCWSTR
  (f-info-level-id :int32)   ; GET_FILEEX_INFO_LEVELS
  (lp-file-information :pointer))   ; void* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $GetFileAttributesExFromAppW = Win32::API::More->new('api-ms-win-core-file-fromapp-l1-1-0',
    'BOOL GetFileAttributesExFromAppW(LPCWSTR lpFileName, int fInfoLevelId, LPVOID lpFileInformation)');
# my $ret = $GetFileAttributesExFromAppW->Call($lpFileName, $fInfoLevelId, $lpFileInformation);
# lpFileName : LPCWSTR -> LPCWSTR
# fInfoLevelId : GET_FILEEX_INFO_LEVELS -> int
# lpFileInformation : void* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型