SetFileAttributesFromAppW
関数シグネチャ
// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>
BOOL SetFileAttributesFromAppW(
LPCWSTR lpFileName,
DWORD dwFileAttributes
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| lpFileName | LPCWSTR | in | 属性を設定するファイルの名前。 "\\?\" を先頭に付加せずに MAX_PATH の制限を回避する方法については、ファイル、パス、名前空間の名前付け の「最大パス長の制限」セクションを参照してください。 | ||||||||||||||||||
| dwFileAttributes | DWORD | in | ファイルに設定するファイル属性。 このパラメーターには、ビットごとの OR 演算子で組み合わせた 1 つ以上の値を指定できます。ただし、FILE_ATTRIBUTE_NORMAL は他のすべての値によって上書きされます。 すべての属性がこの関数でサポートされているわけではありません。 以下は、サポートされている属性値の一覧です。
|
戻り値の型: BOOL
公式ドキュメント
ファイルまたはディレクトリの属性を設定します。この関数の動作は SetFileAttributes と同一ですが、ユニバーサル Windows プラットフォーム アプリのセキュリティ モデルに準拠している点が異なります。
戻り値
関数が成功すると、戻り値は 0 以外になります。
関数が失敗すると、戻り値は 0 になります。拡張エラー情報を取得するには、GetLastError を呼び出してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// api-ms-win-core-file-fromapp-l1-1-0.dll
#include <windows.h>
BOOL SetFileAttributesFromAppW(
LPCWSTR lpFileName,
DWORD dwFileAttributes
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling = true)]
static extern bool SetFileAttributesFromAppW(
[MarshalAs(UnmanagedType.LPWStr)] string lpFileName, // LPCWSTR
uint dwFileAttributes // DWORD
);<DllImport("api-ms-win-core-file-fromapp-l1-1-0.dll", ExactSpelling:=True)>
Public Shared Function SetFileAttributesFromAppW(
<MarshalAs(UnmanagedType.LPWStr)> lpFileName As String, ' LPCWSTR
dwFileAttributes As UInteger ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' lpFileName : LPCWSTR
' dwFileAttributes : DWORD
Declare PtrSafe Function SetFileAttributesFromAppW Lib "api-ms-win-core-file-fromapp-l1-1-0" ( _
ByVal lpFileName As LongPtr, _
ByVal dwFileAttributes As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetFileAttributesFromAppW = ctypes.windll.LoadLibrary("api-ms-win-core-file-fromapp-l1-1-0.dll").SetFileAttributesFromAppW
SetFileAttributesFromAppW.restype = wintypes.BOOL
SetFileAttributesFromAppW.argtypes = [
wintypes.LPCWSTR, # lpFileName : LPCWSTR
wintypes.DWORD, # dwFileAttributes : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('api-ms-win-core-file-fromapp-l1-1-0.dll')
SetFileAttributesFromAppW = Fiddle::Function.new(
lib['SetFileAttributesFromAppW'],
[
Fiddle::TYPE_VOIDP, # lpFileName : LPCWSTR
-Fiddle::TYPE_INT, # dwFileAttributes : DWORD
],
Fiddle::TYPE_INT)#[link(name = "api-ms-win-core-file-fromapp-l1-1-0")]
extern "system" {
fn SetFileAttributesFromAppW(
lpFileName: *const u16, // LPCWSTR
dwFileAttributes: u32 // DWORD
) -> 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 SetFileAttributesFromAppW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, uint dwFileAttributes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-file-fromapp-l1-1-0_SetFileAttributesFromAppW' -Namespace Win32 -PassThru
# $api::SetFileAttributesFromAppW(lpFileName, dwFileAttributes)#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#func global SetFileAttributesFromAppW "SetFileAttributesFromAppW" sptr, sptr
; SetFileAttributesFromAppW lpFileName, dwFileAttributes ; 戻り値は stat
; lpFileName : LPCWSTR -> "sptr"
; dwFileAttributes : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#cfunc global SetFileAttributesFromAppW "SetFileAttributesFromAppW" wstr, int
; res = SetFileAttributesFromAppW(lpFileName, dwFileAttributes)
; lpFileName : LPCWSTR -> "wstr"
; dwFileAttributes : DWORD -> "int"; BOOL SetFileAttributesFromAppW(LPCWSTR lpFileName, DWORD dwFileAttributes)
#uselib "api-ms-win-core-file-fromapp-l1-1-0.dll"
#cfunc global SetFileAttributesFromAppW "SetFileAttributesFromAppW" wstr, int
; res = SetFileAttributesFromAppW(lpFileName, dwFileAttributes)
; lpFileName : LPCWSTR -> "wstr"
; dwFileAttributes : DWORD -> "int"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")
procSetFileAttributesFromAppW = api_ms_win_core_file_fromapp_l1_1_0.NewProc("SetFileAttributesFromAppW")
)
// lpFileName (LPCWSTR), dwFileAttributes (DWORD)
r1, _, err := procSetFileAttributesFromAppW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
uintptr(dwFileAttributes),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetFileAttributesFromAppW(
lpFileName: PWideChar; // LPCWSTR
dwFileAttributes: DWORD // DWORD
): BOOL; stdcall;
external 'api-ms-win-core-file-fromapp-l1-1-0.dll' name 'SetFileAttributesFromAppW';result := DllCall("api-ms-win-core-file-fromapp-l1-1-0\SetFileAttributesFromAppW"
, "WStr", lpFileName ; LPCWSTR
, "UInt", dwFileAttributes ; DWORD
, "Int") ; return: BOOL●SetFileAttributesFromAppW(lpFileName, dwFileAttributes) = DLL("api-ms-win-core-file-fromapp-l1-1-0.dll", "bool SetFileAttributesFromAppW(char*, dword)")
# 呼び出し: SetFileAttributesFromAppW(lpFileName, dwFileAttributes)
# lpFileName : LPCWSTR -> "char*"
# dwFileAttributes : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "api-ms-win-core-file-fromapp-l1-1-0" fn SetFileAttributesFromAppW(
lpFileName: [*c]const u16, // LPCWSTR
dwFileAttributes: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc SetFileAttributesFromAppW(
lpFileName: WideCString, # LPCWSTR
dwFileAttributes: uint32 # DWORD
): int32 {.importc: "SetFileAttributesFromAppW", 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 SetFileAttributesFromAppW(
const(wchar)* lpFileName, // LPCWSTR
uint dwFileAttributes // DWORD
);ccall((:SetFileAttributesFromAppW, "api-ms-win-core-file-fromapp-l1-1-0.dll"), stdcall, Int32,
(Cwstring, UInt32),
lpFileName, dwFileAttributes)
# lpFileName : LPCWSTR -> Cwstring
# dwFileAttributes : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetFileAttributesFromAppW(
const uint16_t* lpFileName,
uint32_t dwFileAttributes);
]]
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.SetFileAttributesFromAppW(lpFileName, dwFileAttributes)
-- lpFileName : LPCWSTR
-- dwFileAttributes : DWORD
-- 構造体/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 SetFileAttributesFromAppW = lib.func('__stdcall', 'SetFileAttributesFromAppW', 'int32_t', ['str16', 'uint32_t']);
// SetFileAttributesFromAppW(lpFileName, dwFileAttributes)
// lpFileName : LPCWSTR -> 'str16'
// dwFileAttributes : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("api-ms-win-core-file-fromapp-l1-1-0.dll", {
SetFileAttributesFromAppW: { parameters: ["buffer", "u32"], result: "i32" },
});
// lib.symbols.SetFileAttributesFromAppW(lpFileName, dwFileAttributes)
// lpFileName : LPCWSTR -> "buffer"
// dwFileAttributes : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetFileAttributesFromAppW(
const uint16_t* lpFileName,
uint32_t dwFileAttributes);
C, "api-ms-win-core-file-fromapp-l1-1-0.dll");
// $ffi->SetFileAttributesFromAppW(lpFileName, dwFileAttributes);
// lpFileName : LPCWSTR
// dwFileAttributes : DWORD
// 構造体/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 SetFileAttributesFromAppW(
WString lpFileName, // LPCWSTR
int dwFileAttributes // DWORD
);
}@[Link("api-ms-win-core-file-fromapp-l1-1-0")]
lib Libapi-ms-win-core-file-fromapp-l1-1-0
fun SetFileAttributesFromAppW = SetFileAttributesFromAppW(
lpFileName : UInt16*, # LPCWSTR
dwFileAttributes : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetFileAttributesFromAppWNative = Int32 Function(Pointer<Utf16>, Uint32);
typedef SetFileAttributesFromAppWDart = int Function(Pointer<Utf16>, int);
final SetFileAttributesFromAppW = DynamicLibrary.open('api-ms-win-core-file-fromapp-l1-1-0.dll')
.lookupFunction<SetFileAttributesFromAppWNative, SetFileAttributesFromAppWDart>('SetFileAttributesFromAppW');
// lpFileName : LPCWSTR -> Pointer<Utf16>
// dwFileAttributes : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetFileAttributesFromAppW(
lpFileName: PWideChar; // LPCWSTR
dwFileAttributes: DWORD // DWORD
): BOOL; stdcall;
external 'api-ms-win-core-file-fromapp-l1-1-0.dll' name 'SetFileAttributesFromAppW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetFileAttributesFromAppW"
c_SetFileAttributesFromAppW :: CWString -> Word32 -> IO CInt
-- lpFileName : LPCWSTR -> CWString
-- dwFileAttributes : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setfileattributesfromappw =
foreign "SetFileAttributesFromAppW"
((ptr uint16_t) @-> uint32_t @-> returning int32_t)
(* lpFileName : LPCWSTR -> (ptr uint16_t) *)
(* dwFileAttributes : DWORD -> uint32_t *)
(* 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 ("SetFileAttributesFromAppW" set-file-attributes-from-app-w :convention :stdcall) :int32
(lp-file-name (:string :encoding :utf-16le)) ; LPCWSTR
(dw-file-attributes :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetFileAttributesFromAppW = Win32::API::More->new('api-ms-win-core-file-fromapp-l1-1-0',
'BOOL SetFileAttributesFromAppW(LPCWSTR lpFileName, DWORD dwFileAttributes)');
# my $ret = $SetFileAttributesFromAppW->Call($lpFileName, $dwFileAttributes);
# lpFileName : LPCWSTR -> LPCWSTR
# dwFileAttributes : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。