ホーム › Storage.FileSystem › SetFileAttributesA
SetFileAttributesA
関数指定ファイルの属性を設定する(ANSI版)。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL SetFileAttributesA(
LPCSTR lpFileName,
FILE_FLAGS_AND_ATTRIBUTES dwFileAttributes
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpFileName | LPCSTR | in |
| dwFileAttributes | FILE_FLAGS_AND_ATTRIBUTES | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL SetFileAttributesA(
LPCSTR lpFileName,
FILE_FLAGS_AND_ATTRIBUTES dwFileAttributes
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool SetFileAttributesA(
[MarshalAs(UnmanagedType.LPStr)] string lpFileName, // LPCSTR
uint dwFileAttributes // FILE_FLAGS_AND_ATTRIBUTES
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetFileAttributesA(
<MarshalAs(UnmanagedType.LPStr)> lpFileName As String, ' LPCSTR
dwFileAttributes As UInteger ' FILE_FLAGS_AND_ATTRIBUTES
) As Boolean
End Function' lpFileName : LPCSTR
' dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES
Declare PtrSafe Function SetFileAttributesA Lib "kernel32" ( _
ByVal lpFileName As String, _
ByVal dwFileAttributes As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetFileAttributesA = ctypes.windll.kernel32.SetFileAttributesA
SetFileAttributesA.restype = wintypes.BOOL
SetFileAttributesA.argtypes = [
wintypes.LPCSTR, # lpFileName : LPCSTR
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')
SetFileAttributesA = Fiddle::Function.new(
lib['SetFileAttributesA'],
[
Fiddle::TYPE_VOIDP, # lpFileName : LPCSTR
-Fiddle::TYPE_INT, # dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn SetFileAttributesA(
lpFileName: *const u8, // LPCSTR
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.Ansi, SetLastError = true)]
public static extern bool SetFileAttributesA([MarshalAs(UnmanagedType.LPStr)] string lpFileName, uint dwFileAttributes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetFileAttributesA' -Namespace Win32 -PassThru
# $api::SetFileAttributesA(lpFileName, dwFileAttributes)#uselib "KERNEL32.dll"
#func global SetFileAttributesA "SetFileAttributesA" sptr, sptr
; SetFileAttributesA lpFileName, dwFileAttributes ; 戻り値は stat
; lpFileName : LPCSTR -> "sptr"
; dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global SetFileAttributesA "SetFileAttributesA" str, int
; res = SetFileAttributesA(lpFileName, dwFileAttributes)
; lpFileName : LPCSTR -> "str"
; dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "int"; BOOL SetFileAttributesA(LPCSTR lpFileName, FILE_FLAGS_AND_ATTRIBUTES dwFileAttributes)
#uselib "KERNEL32.dll"
#cfunc global SetFileAttributesA "SetFileAttributesA" str, int
; res = SetFileAttributesA(lpFileName, dwFileAttributes)
; lpFileName : LPCSTR -> "str"
; dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetFileAttributesA = kernel32.NewProc("SetFileAttributesA")
)
// lpFileName (LPCSTR), dwFileAttributes (FILE_FLAGS_AND_ATTRIBUTES)
r1, _, err := procSetFileAttributesA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpFileName))),
uintptr(dwFileAttributes),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetFileAttributesA(
lpFileName: PAnsiChar; // LPCSTR
dwFileAttributes: DWORD // FILE_FLAGS_AND_ATTRIBUTES
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetFileAttributesA';result := DllCall("KERNEL32\SetFileAttributesA"
, "AStr", lpFileName ; LPCSTR
, "UInt", dwFileAttributes ; FILE_FLAGS_AND_ATTRIBUTES
, "Int") ; return: BOOL●SetFileAttributesA(lpFileName, dwFileAttributes) = DLL("KERNEL32.dll", "bool SetFileAttributesA(char*, dword)")
# 呼び出し: SetFileAttributesA(lpFileName, dwFileAttributes)
# lpFileName : LPCSTR -> "char*"
# dwFileAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。