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

CreateDirectoryTransactedW

関数
トランザクション内でディレクトリを作成する(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL CreateDirectoryTransactedW(
    LPCWSTR lpTemplateDirectory,   // optional
    LPCWSTR lpNewDirectory,
    SECURITY_ATTRIBUTES* lpSecurityAttributes,   // optional
    HANDLE hTransaction
);

パラメーター

名前方向
lpTemplateDirectoryLPCWSTRinoptional
lpNewDirectoryLPCWSTRin
lpSecurityAttributesSECURITY_ATTRIBUTES*inoptional
hTransactionHANDLEin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

CreateDirectoryTransactedW = ctypes.windll.kernel32.CreateDirectoryTransactedW
CreateDirectoryTransactedW.restype = wintypes.BOOL
CreateDirectoryTransactedW.argtypes = [
    wintypes.LPCWSTR,  # lpTemplateDirectory : LPCWSTR optional
    wintypes.LPCWSTR,  # lpNewDirectory : LPCWSTR
    ctypes.c_void_p,  # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
    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')
CreateDirectoryTransactedW = Fiddle::Function.new(
  lib['CreateDirectoryTransactedW'],
  [
    Fiddle::TYPE_VOIDP,  # lpTemplateDirectory : LPCWSTR optional
    Fiddle::TYPE_VOIDP,  # lpNewDirectory : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
    Fiddle::TYPE_VOIDP,  # hTransaction : HANDLE
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn CreateDirectoryTransactedW(
        lpTemplateDirectory: *const u16,  // LPCWSTR optional
        lpNewDirectory: *const u16,  // LPCWSTR
        lpSecurityAttributes: *mut SECURITY_ATTRIBUTES,  // SECURITY_ATTRIBUTES* optional
        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 CreateDirectoryTransactedW([MarshalAs(UnmanagedType.LPWStr)] string lpTemplateDirectory, [MarshalAs(UnmanagedType.LPWStr)] string lpNewDirectory, IntPtr lpSecurityAttributes, IntPtr hTransaction);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CreateDirectoryTransactedW' -Namespace Win32 -PassThru
# $api::CreateDirectoryTransactedW(lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes, hTransaction)
#uselib "KERNEL32.dll"
#func global CreateDirectoryTransactedW "CreateDirectoryTransactedW" wptr, wptr, wptr, wptr
; CreateDirectoryTransactedW lpTemplateDirectory, lpNewDirectory, varptr(lpSecurityAttributes), hTransaction   ; 戻り値は stat
; lpTemplateDirectory : LPCWSTR optional -> "wptr"
; lpNewDirectory : LPCWSTR -> "wptr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "wptr"
; hTransaction : HANDLE -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global CreateDirectoryTransactedW "CreateDirectoryTransactedW" wstr, wstr, var, sptr
; res = CreateDirectoryTransactedW(lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes, hTransaction)
; lpTemplateDirectory : LPCWSTR optional -> "wstr"
; lpNewDirectory : LPCWSTR -> "wstr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; hTransaction : HANDLE -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CreateDirectoryTransactedW(LPCWSTR lpTemplateDirectory, LPCWSTR lpNewDirectory, SECURITY_ATTRIBUTES* lpSecurityAttributes, HANDLE hTransaction)
#uselib "KERNEL32.dll"
#cfunc global CreateDirectoryTransactedW "CreateDirectoryTransactedW" wstr, wstr, var, intptr
; res = CreateDirectoryTransactedW(lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes, hTransaction)
; lpTemplateDirectory : LPCWSTR optional -> "wstr"
; lpNewDirectory : LPCWSTR -> "wstr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; hTransaction : HANDLE -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procCreateDirectoryTransactedW = kernel32.NewProc("CreateDirectoryTransactedW")
)

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