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

SetFileAttributesTransactedW

関数
トランザクション内でファイル属性を設定する(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetFileAttributesTransactedW(
    LPCWSTR lpFileName,
    DWORD dwFileAttributes,
    HANDLE hTransaction
);

パラメーター

名前方向
lpFileNameLPCWSTRin
dwFileAttributesDWORDin
hTransactionHANDLEin

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

BOOL SetFileAttributesTransactedW(
    LPCWSTR lpFileName,
    DWORD dwFileAttributes,
    HANDLE hTransaction
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool SetFileAttributesTransactedW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpFileName,   // LPCWSTR
    uint dwFileAttributes,   // DWORD
    IntPtr hTransaction   // HANDLE
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetFileAttributesTransactedW(
    <MarshalAs(UnmanagedType.LPWStr)> lpFileName As String,   ' LPCWSTR
    dwFileAttributes As UInteger,   ' DWORD
    hTransaction As IntPtr   ' HANDLE
) As Boolean
End Function
' lpFileName : LPCWSTR
' dwFileAttributes : DWORD
' hTransaction : HANDLE
Declare PtrSafe Function SetFileAttributesTransactedW Lib "kernel32" ( _
    ByVal lpFileName As LongPtr, _
    ByVal dwFileAttributes As Long, _
    ByVal hTransaction As LongPtr) 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

SetFileAttributesTransactedW = ctypes.windll.kernel32.SetFileAttributesTransactedW
SetFileAttributesTransactedW.restype = wintypes.BOOL
SetFileAttributesTransactedW.argtypes = [
    wintypes.LPCWSTR,  # lpFileName : LPCWSTR
    wintypes.DWORD,  # dwFileAttributes : DWORD
    wintypes.HANDLE,  # hTransaction : HANDLE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetFileAttributesTransactedW = Fiddle::Function.new(
  lib['SetFileAttributesTransactedW'],
  [
    Fiddle::TYPE_VOIDP,  # lpFileName : LPCWSTR
    -Fiddle::TYPE_INT,  # dwFileAttributes : DWORD
    Fiddle::TYPE_VOIDP,  # hTransaction : HANDLE
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn SetFileAttributesTransactedW(
        lpFileName: *const u16,  // LPCWSTR
        dwFileAttributes: u32,  // DWORD
        hTransaction: *mut core::ffi::c_void  // HANDLE
    ) -> 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 SetFileAttributesTransactedW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, uint dwFileAttributes, IntPtr hTransaction);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetFileAttributesTransactedW' -Namespace Win32 -PassThru
# $api::SetFileAttributesTransactedW(lpFileName, dwFileAttributes, hTransaction)
#uselib "KERNEL32.dll"
#func global SetFileAttributesTransactedW "SetFileAttributesTransactedW" wptr, wptr, wptr
; SetFileAttributesTransactedW lpFileName, dwFileAttributes, hTransaction   ; 戻り値は stat
; lpFileName : LPCWSTR -> "wptr"
; dwFileAttributes : DWORD -> "wptr"
; hTransaction : HANDLE -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetFileAttributesTransactedW "SetFileAttributesTransactedW" wstr, int, sptr
; res = SetFileAttributesTransactedW(lpFileName, dwFileAttributes, hTransaction)
; lpFileName : LPCWSTR -> "wstr"
; dwFileAttributes : DWORD -> "int"
; hTransaction : HANDLE -> "sptr"
; BOOL SetFileAttributesTransactedW(LPCWSTR lpFileName, DWORD dwFileAttributes, HANDLE hTransaction)
#uselib "KERNEL32.dll"
#cfunc global SetFileAttributesTransactedW "SetFileAttributesTransactedW" wstr, int, intptr
; res = SetFileAttributesTransactedW(lpFileName, dwFileAttributes, hTransaction)
; lpFileName : LPCWSTR -> "wstr"
; dwFileAttributes : DWORD -> "int"
; hTransaction : HANDLE -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetFileAttributesTransactedW = kernel32.NewProc("SetFileAttributesTransactedW")
)

// lpFileName (LPCWSTR), dwFileAttributes (DWORD), hTransaction (HANDLE)
r1, _, err := procSetFileAttributesTransactedW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
	uintptr(dwFileAttributes),
	uintptr(hTransaction),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetFileAttributesTransactedW(
  lpFileName: PWideChar;   // LPCWSTR
  dwFileAttributes: DWORD;   // DWORD
  hTransaction: THandle   // HANDLE
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'SetFileAttributesTransactedW';
result := DllCall("KERNEL32\SetFileAttributesTransactedW"
    , "WStr", lpFileName   ; LPCWSTR
    , "UInt", dwFileAttributes   ; DWORD
    , "Ptr", hTransaction   ; HANDLE
    , "Int")   ; return: BOOL
●SetFileAttributesTransactedW(lpFileName, dwFileAttributes, hTransaction) = DLL("KERNEL32.dll", "bool SetFileAttributesTransactedW(char*, dword, void*)")
# 呼び出し: SetFileAttributesTransactedW(lpFileName, dwFileAttributes, hTransaction)
# lpFileName : LPCWSTR -> "char*"
# dwFileAttributes : DWORD -> "dword"
# hTransaction : HANDLE -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。