ホーム › Storage.FileSystem › SetFileAttributesW
SetFileAttributesW
関数指定ファイルの属性を設定する。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetFileAttributesW(
LPCWSTR lpFileName,
FILE_FLAGS_AND_ATTRIBUTES dwFileAttributes
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpFileName | LPCWSTR | in |
| dwFileAttributes | FILE_FLAGS_AND_ATTRIBUTES | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL SetFileAttributesW(
LPCWSTR lpFileName,
FILE_FLAGS_AND_ATTRIBUTES dwFileAttributes
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetFileAttributesW(
[MarshalAs(UnmanagedType.LPWStr)] string lpFileName, // LPCWSTR
uint dwFileAttributes // FILE_FLAGS_AND_ATTRIBUTES
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetFileAttributesW(
<MarshalAs(UnmanagedType.LPWStr)> lpFileName As String, ' LPCWSTR
dwFileAttributes As UInteger ' FILE_FLAGS_AND_ATTRIBUTES
) As Boolean
End Function' lpFileName : LPCWSTR
' dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES
Declare PtrSafe Function SetFileAttributesW Lib "kernel32" ( _
ByVal lpFileName As LongPtr, _
ByVal dwFileAttributes As Long) 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
SetFileAttributesW = ctypes.windll.kernel32.SetFileAttributesW
SetFileAttributesW.restype = wintypes.BOOL
SetFileAttributesW.argtypes = [
wintypes.LPCWSTR, # lpFileName : LPCWSTR
wintypes.DWORD, # dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetFileAttributesW = Fiddle::Function.new(
lib['SetFileAttributesW'],
[
Fiddle::TYPE_VOIDP, # lpFileName : LPCWSTR
-Fiddle::TYPE_INT, # dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn SetFileAttributesW(
lpFileName: *const u16, // LPCWSTR
dwFileAttributes: u32 // FILE_FLAGS_AND_ATTRIBUTES
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetFileAttributesW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, uint dwFileAttributes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetFileAttributesW' -Namespace Win32 -PassThru
# $api::SetFileAttributesW(lpFileName, dwFileAttributes)#uselib "KERNEL32.dll"
#func global SetFileAttributesW "SetFileAttributesW" wptr, wptr
; SetFileAttributesW lpFileName, dwFileAttributes ; 戻り値は stat
; lpFileName : LPCWSTR -> "wptr"
; dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global SetFileAttributesW "SetFileAttributesW" wstr, int
; res = SetFileAttributesW(lpFileName, dwFileAttributes)
; lpFileName : LPCWSTR -> "wstr"
; dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "int"; BOOL SetFileAttributesW(LPCWSTR lpFileName, FILE_FLAGS_AND_ATTRIBUTES dwFileAttributes)
#uselib "KERNEL32.dll"
#cfunc global SetFileAttributesW "SetFileAttributesW" wstr, int
; res = SetFileAttributesW(lpFileName, dwFileAttributes)
; lpFileName : LPCWSTR -> "wstr"
; dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetFileAttributesW = kernel32.NewProc("SetFileAttributesW")
)
// lpFileName (LPCWSTR), dwFileAttributes (FILE_FLAGS_AND_ATTRIBUTES)
r1, _, err := procSetFileAttributesW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
uintptr(dwFileAttributes),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetFileAttributesW(
lpFileName: PWideChar; // LPCWSTR
dwFileAttributes: DWORD // FILE_FLAGS_AND_ATTRIBUTES
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetFileAttributesW';result := DllCall("KERNEL32\SetFileAttributesW"
, "WStr", lpFileName ; LPCWSTR
, "UInt", dwFileAttributes ; FILE_FLAGS_AND_ATTRIBUTES
, "Int") ; return: BOOL●SetFileAttributesW(lpFileName, dwFileAttributes) = DLL("KERNEL32.dll", "bool SetFileAttributesW(char*, dword)")
# 呼び出し: SetFileAttributesW(lpFileName, dwFileAttributes)
# lpFileName : LPCWSTR -> "char*"
# dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。