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

CreateFileTransactedW

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

シグネチャ

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

HANDLE CreateFileTransactedW(
    LPCWSTR lpFileName,
    DWORD dwDesiredAccess,
    FILE_SHARE_MODE dwShareMode,
    SECURITY_ATTRIBUTES* lpSecurityAttributes,   // optional
    FILE_CREATION_DISPOSITION dwCreationDisposition,
    FILE_FLAGS_AND_ATTRIBUTES dwFlagsAndAttributes,
    HANDLE hTemplateFile,   // optional
    HANDLE hTransaction,
    TXFS_MINIVERSION* pusMiniVersion,   // optional
    void* lpExtendedParameter   // optional
);

パラメーター

名前方向
lpFileNameLPCWSTRin
dwDesiredAccessDWORDin
dwShareModeFILE_SHARE_MODEin
lpSecurityAttributesSECURITY_ATTRIBUTES*inoptional
dwCreationDispositionFILE_CREATION_DISPOSITIONin
dwFlagsAndAttributesFILE_FLAGS_AND_ATTRIBUTESin
hTemplateFileHANDLEinoptional
hTransactionHANDLEin
pusMiniVersionTXFS_MINIVERSION*inoptional
lpExtendedParametervoid*optional

戻り値の型: HANDLE

各言語での呼び出し定義

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

HANDLE CreateFileTransactedW(
    LPCWSTR lpFileName,
    DWORD dwDesiredAccess,
    FILE_SHARE_MODE dwShareMode,
    SECURITY_ATTRIBUTES* lpSecurityAttributes,   // optional
    FILE_CREATION_DISPOSITION dwCreationDisposition,
    FILE_FLAGS_AND_ATTRIBUTES dwFlagsAndAttributes,
    HANDLE hTemplateFile,   // optional
    HANDLE hTransaction,
    TXFS_MINIVERSION* pusMiniVersion,   // optional
    void* lpExtendedParameter   // optional
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateFileTransactedW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpFileName,   // LPCWSTR
    uint dwDesiredAccess,   // DWORD
    uint dwShareMode,   // FILE_SHARE_MODE
    IntPtr lpSecurityAttributes,   // SECURITY_ATTRIBUTES* optional
    uint dwCreationDisposition,   // FILE_CREATION_DISPOSITION
    uint dwFlagsAndAttributes,   // FILE_FLAGS_AND_ATTRIBUTES
    IntPtr hTemplateFile,   // HANDLE optional
    IntPtr hTransaction,   // HANDLE
    IntPtr pusMiniVersion,   // TXFS_MINIVERSION* optional
    IntPtr lpExtendedParameter   // void* optional
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateFileTransactedW(
    <MarshalAs(UnmanagedType.LPWStr)> lpFileName As String,   ' LPCWSTR
    dwDesiredAccess As UInteger,   ' DWORD
    dwShareMode As UInteger,   ' FILE_SHARE_MODE
    lpSecurityAttributes As IntPtr,   ' SECURITY_ATTRIBUTES* optional
    dwCreationDisposition As UInteger,   ' FILE_CREATION_DISPOSITION
    dwFlagsAndAttributes As UInteger,   ' FILE_FLAGS_AND_ATTRIBUTES
    hTemplateFile As IntPtr,   ' HANDLE optional
    hTransaction As IntPtr,   ' HANDLE
    pusMiniVersion As IntPtr,   ' TXFS_MINIVERSION* optional
    lpExtendedParameter As IntPtr   ' void* optional
) As IntPtr
End Function
' lpFileName : LPCWSTR
' dwDesiredAccess : DWORD
' dwShareMode : FILE_SHARE_MODE
' lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
' dwCreationDisposition : FILE_CREATION_DISPOSITION
' dwFlagsAndAttributes : FILE_FLAGS_AND_ATTRIBUTES
' hTemplateFile : HANDLE optional
' hTransaction : HANDLE
' pusMiniVersion : TXFS_MINIVERSION* optional
' lpExtendedParameter : void* optional
Declare PtrSafe Function CreateFileTransactedW Lib "kernel32" ( _
    ByVal lpFileName As LongPtr, _
    ByVal dwDesiredAccess As Long, _
    ByVal dwShareMode As Long, _
    ByVal lpSecurityAttributes As LongPtr, _
    ByVal dwCreationDisposition As Long, _
    ByVal dwFlagsAndAttributes As Long, _
    ByVal hTemplateFile As LongPtr, _
    ByVal hTransaction As LongPtr, _
    ByVal pusMiniVersion As LongPtr, _
    ByVal lpExtendedParameter As LongPtr) As LongPtr
' 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

CreateFileTransactedW = ctypes.windll.kernel32.CreateFileTransactedW
CreateFileTransactedW.restype = ctypes.c_void_p
CreateFileTransactedW.argtypes = [
    wintypes.LPCWSTR,  # lpFileName : LPCWSTR
    wintypes.DWORD,  # dwDesiredAccess : DWORD
    wintypes.DWORD,  # dwShareMode : FILE_SHARE_MODE
    ctypes.c_void_p,  # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
    wintypes.DWORD,  # dwCreationDisposition : FILE_CREATION_DISPOSITION
    wintypes.DWORD,  # dwFlagsAndAttributes : FILE_FLAGS_AND_ATTRIBUTES
    wintypes.HANDLE,  # hTemplateFile : HANDLE optional
    wintypes.HANDLE,  # hTransaction : HANDLE
    ctypes.c_void_p,  # pusMiniVersion : TXFS_MINIVERSION* optional
    ctypes.POINTER(None),  # lpExtendedParameter : void* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
CreateFileTransactedW = Fiddle::Function.new(
  lib['CreateFileTransactedW'],
  [
    Fiddle::TYPE_VOIDP,  # lpFileName : LPCWSTR
    -Fiddle::TYPE_INT,  # dwDesiredAccess : DWORD
    -Fiddle::TYPE_INT,  # dwShareMode : FILE_SHARE_MODE
    Fiddle::TYPE_VOIDP,  # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
    -Fiddle::TYPE_INT,  # dwCreationDisposition : FILE_CREATION_DISPOSITION
    -Fiddle::TYPE_INT,  # dwFlagsAndAttributes : FILE_FLAGS_AND_ATTRIBUTES
    Fiddle::TYPE_VOIDP,  # hTemplateFile : HANDLE optional
    Fiddle::TYPE_VOIDP,  # hTransaction : HANDLE
    Fiddle::TYPE_VOIDP,  # pusMiniVersion : TXFS_MINIVERSION* optional
    Fiddle::TYPE_VOIDP,  # lpExtendedParameter : void* optional
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn CreateFileTransactedW(
        lpFileName: *const u16,  // LPCWSTR
        dwDesiredAccess: u32,  // DWORD
        dwShareMode: u32,  // FILE_SHARE_MODE
        lpSecurityAttributes: *mut SECURITY_ATTRIBUTES,  // SECURITY_ATTRIBUTES* optional
        dwCreationDisposition: u32,  // FILE_CREATION_DISPOSITION
        dwFlagsAndAttributes: u32,  // FILE_FLAGS_AND_ATTRIBUTES
        hTemplateFile: *mut core::ffi::c_void,  // HANDLE optional
        hTransaction: *mut core::ffi::c_void,  // HANDLE
        pusMiniVersion: *mut u32,  // TXFS_MINIVERSION* optional
        lpExtendedParameter: *mut ()  // void* optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CreateFileTransactedW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile, IntPtr hTransaction, IntPtr pusMiniVersion, IntPtr lpExtendedParameter);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CreateFileTransactedW' -Namespace Win32 -PassThru
# $api::CreateFileTransactedW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, lpExtendedParameter)
#uselib "KERNEL32.dll"
#func global CreateFileTransactedW "CreateFileTransactedW" wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr, wptr
; CreateFileTransactedW lpFileName, dwDesiredAccess, dwShareMode, varptr(lpSecurityAttributes), dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, lpExtendedParameter   ; 戻り値は stat
; lpFileName : LPCWSTR -> "wptr"
; dwDesiredAccess : DWORD -> "wptr"
; dwShareMode : FILE_SHARE_MODE -> "wptr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "wptr"
; dwCreationDisposition : FILE_CREATION_DISPOSITION -> "wptr"
; dwFlagsAndAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "wptr"
; hTemplateFile : HANDLE optional -> "wptr"
; hTransaction : HANDLE -> "wptr"
; pusMiniVersion : TXFS_MINIVERSION* optional -> "wptr"
; lpExtendedParameter : void* optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global CreateFileTransactedW "CreateFileTransactedW" wstr, int, int, var, int, int, sptr, sptr, int, sptr
; res = CreateFileTransactedW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, lpExtendedParameter)
; lpFileName : LPCWSTR -> "wstr"
; dwDesiredAccess : DWORD -> "int"
; dwShareMode : FILE_SHARE_MODE -> "int"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; dwCreationDisposition : FILE_CREATION_DISPOSITION -> "int"
; dwFlagsAndAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "int"
; hTemplateFile : HANDLE optional -> "sptr"
; hTransaction : HANDLE -> "sptr"
; pusMiniVersion : TXFS_MINIVERSION* optional -> "int"
; lpExtendedParameter : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE CreateFileTransactedW(LPCWSTR lpFileName, DWORD dwDesiredAccess, FILE_SHARE_MODE dwShareMode, SECURITY_ATTRIBUTES* lpSecurityAttributes, FILE_CREATION_DISPOSITION dwCreationDisposition, FILE_FLAGS_AND_ATTRIBUTES dwFlagsAndAttributes, HANDLE hTemplateFile, HANDLE hTransaction, TXFS_MINIVERSION* pusMiniVersion, void* lpExtendedParameter)
#uselib "KERNEL32.dll"
#cfunc global CreateFileTransactedW "CreateFileTransactedW" wstr, int, int, var, int, int, intptr, intptr, int, intptr
; res = CreateFileTransactedW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile, hTransaction, pusMiniVersion, lpExtendedParameter)
; lpFileName : LPCWSTR -> "wstr"
; dwDesiredAccess : DWORD -> "int"
; dwShareMode : FILE_SHARE_MODE -> "int"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; dwCreationDisposition : FILE_CREATION_DISPOSITION -> "int"
; dwFlagsAndAttributes : FILE_FLAGS_AND_ATTRIBUTES -> "int"
; hTemplateFile : HANDLE optional -> "intptr"
; hTransaction : HANDLE -> "intptr"
; pusMiniVersion : TXFS_MINIVERSION* optional -> "int"
; lpExtendedParameter : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procCreateFileTransactedW = kernel32.NewProc("CreateFileTransactedW")
)

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