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

新しいディレクトリを作成する際にテンプレートとして使用するディレクトリのパスです。このパラメーターには NULL を指定できます。

ディレクトリはローカルコンピューター上に存在する必要があります。そうでない場合、この関数は失敗し、最後のエラーコードが ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE に設定されます。

既定では、名前は MAX_PATH 文字に制限されます。この制限を 32,767 ワイド文字まで拡張するには、パスの先頭に "\\?\" を付加します。詳細については、ファイル、パス、名前空間の名前付け を参照してください。

ヒント

Windows 10 Version 1607 以降では、"\\?\" を付加せずに MAX_PATH 制限を解除するようにオプトインできます。詳細については、ファイル、パス、名前空間の名前付け の「Maximum Path Length Limitation」セクションを参照してください。

lpNewDirectoryLPCWSTRin

作成するディレクトリのパスです。

既定では、名前は MAX_PATH 文字に制限されます。この制限を 32,767 ワイド文字まで拡張するには、パスの先頭に "\\?\" を付加します。詳細については、ファイル、パス、名前空間の名前付け を参照してください。

ヒント

Windows 10 Version 1607 以降では、"\\?\" を付加せずに MAX_PATH 制限を解除するようにオプトインできます。詳細については、ファイル、パス、名前空間の名前付け の「Maximum Path Length Limitation」セクションを参照してください。

lpSecurityAttributesSECURITY_ATTRIBUTES*inoptional

SECURITY_ATTRIBUTES 構造体へのポインターです。この構造体の lpSecurityDescriptor メンバーは、新しいディレクトリのセキュリティ記述子を指定します。

lpSecurityAttributesNULL の場合、ディレクトリには既定のセキュリティ記述子が適用されます。ディレクトリの既定のセキュリティ記述子内のアクセス制御リスト (ACL) は、親ディレクトリから継承されます。

このパラメーターを有効にするには、対象のファイルシステムがファイルおよびディレクトリのセキュリティをサポートしている必要があります。これは、GetVolumeInformationFS_PERSISTENT_ACLS を返すことで示されます。

hTransactionHANDLEinトランザクションへのハンドルです。このハンドルは CreateTransaction 関数によって返されます。

戻り値の型: BOOL

公式ドキュメント

指定したテンプレートディレクトリの属性を使用して、新しいディレクトリをトランザクション操作として作成します。(Unicode)

戻り値

関数が成功した場合、戻り値は 0 以外の値になります。

関数が失敗した場合、戻り値は 0 になります。拡張エラー情報を取得するには、 GetLastError を呼び出します。発生し得るエラーには次のものがあります。

戻り値コード 説明
ERROR_ALREADY_EXISTS
指定したディレクトリは既に存在します。
ERROR_EFS_NOT_ALLOWED_IN_TRANSACTION
暗号化が無効になっている親ディレクトリの下に子ディレクトリを作成することはできません。
ERROR_PATH_NOT_FOUND
1 つ以上の中間ディレクトリが存在しません。この関数はパス内の最終ディレクトリのみを作成します。

解説(Remarks)

CreateDirectoryTransacted 関数を使用すると、他のディレクトリからストリーム情報を継承するディレクトリを作成できます。この関数は、たとえば Macintosh ディレクトリを使用する場合に便利です。Macintosh ディレクトリには、ディレクトリの内容を属性として正しく識別するために必要なリソースストリームがあります。

NTFS ファイルシステムなど、一部のファイルシステムは、個々のファイルおよびディレクトリの圧縮または暗号化をサポートしています。そのようなファイルシステム用にフォーマットされたボリュームでは、新しいディレクトリは親ディレクトリの圧縮属性と暗号化属性を継承します。

暗号化が無効になっている親ディレクトリの下に子ディレクトリを作成しようとすると、この関数は ERROR_EFS_NOT_ALLOWED_IN_TRANSACTION で失敗します。

FILE_FLAG_BACKUP_SEMANTICS フラグを設定して CreateFileTransacted 関数を呼び出すことで、ディレクトリへのハンドルを取得できます。

Windows 8 および Windows Server 2012 では、この関数は次のテクノロジによってサポートされています。

テクノロジ サポート
Server Message Block (SMB) 3.0 プロトコル いいえ
SMB 3.0 トランスペアレントフェイルオーバー (TFO) いいえ
SMB 3.0 とスケールアウトファイル共有 (SO) いいえ
Cluster Shared Volume File System (CsvFS) いいえ
Resilient File System (ReFS) いいえ

SMB 3.0 は TxF をサポートしていません。

メモ

winbase.h ヘッダーは、UNICODE プリプロセッサ定数の定義に基づいて、この関数の ANSI 版または Unicode 版を自動的に選択するエイリアスとして CreateDirectoryTransacted を定義します。エンコーディング中立のエイリアスの使用と、エンコーディング中立でないコードを混在させると、コンパイルエラーや実行時エラーの原因となる不一致が生じる可能性があります。詳細については、関数プロトタイプの規則 を参照してください。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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 <MarshalAs(UnmanagedType.Bool)> 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 版の利用を推奨。
const std = @import("std");

extern "kernel32" fn CreateDirectoryTransactedW(
    lpTemplateDirectory: [*c]const u16, // LPCWSTR optional
    lpNewDirectory: [*c]const u16, // LPCWSTR
    lpSecurityAttributes: [*c]SECURITY_ATTRIBUTES, // SECURITY_ATTRIBUTES* optional
    hTransaction: ?*anyopaque // HANDLE
) callconv(std.os.windows.WINAPI) i32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。
proc CreateDirectoryTransactedW(
    lpTemplateDirectory: WideCString,  # LPCWSTR optional
    lpNewDirectory: WideCString,  # LPCWSTR
    lpSecurityAttributes: ptr SECURITY_ATTRIBUTES,  # SECURITY_ATTRIBUTES* optional
    hTransaction: pointer  # HANDLE
): int32 {.importc: "CreateDirectoryTransactedW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "kernel32");
extern(Windows)
int CreateDirectoryTransactedW(
    const(wchar)* lpTemplateDirectory,   // LPCWSTR optional
    const(wchar)* lpNewDirectory,   // LPCWSTR
    SECURITY_ATTRIBUTES* lpSecurityAttributes,   // SECURITY_ATTRIBUTES* optional
    void* hTransaction   // HANDLE
);
ccall((:CreateDirectoryTransactedW, "KERNEL32.dll"), stdcall, Int32,
      (Cwstring, Cwstring, Ptr{SECURITY_ATTRIBUTES}, Ptr{Cvoid}),
      lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes, hTransaction)
# lpTemplateDirectory : LPCWSTR optional -> Cwstring
# lpNewDirectory : LPCWSTR -> Cwstring
# lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> Ptr{SECURITY_ATTRIBUTES}
# hTransaction : HANDLE -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。
local ffi = require("ffi")
ffi.cdef[[
int32_t CreateDirectoryTransactedW(
    const uint16_t* lpTemplateDirectory,
    const uint16_t* lpNewDirectory,
    void* lpSecurityAttributes,
    void* hTransaction);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.CreateDirectoryTransactedW(lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes, hTransaction)
-- lpTemplateDirectory : LPCWSTR optional
-- lpNewDirectory : LPCWSTR
-- lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
-- hTransaction : HANDLE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const CreateDirectoryTransactedW = lib.func('__stdcall', 'CreateDirectoryTransactedW', 'int32_t', ['str16', 'str16', 'void *', 'void *']);
// CreateDirectoryTransactedW(lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes, hTransaction)
// lpTemplateDirectory : LPCWSTR optional -> 'str16'
// lpNewDirectory : LPCWSTR -> 'str16'
// lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> 'void *'
// hTransaction : HANDLE -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  CreateDirectoryTransactedW: { parameters: ["buffer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CreateDirectoryTransactedW(lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes, hTransaction)
// lpTemplateDirectory : LPCWSTR optional -> "buffer"
// lpNewDirectory : LPCWSTR -> "buffer"
// lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "pointer"
// hTransaction : HANDLE -> "pointer"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t CreateDirectoryTransactedW(
    const uint16_t* lpTemplateDirectory,
    const uint16_t* lpNewDirectory,
    void* lpSecurityAttributes,
    void* hTransaction);
C, "KERNEL32.dll");
// $ffi->CreateDirectoryTransactedW(lpTemplateDirectory, lpNewDirectory, lpSecurityAttributes, hTransaction);
// lpTemplateDirectory : LPCWSTR optional
// lpNewDirectory : LPCWSTR
// lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
// hTransaction : HANDLE
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class, W32APIOptions.UNICODE_OPTIONS);
    boolean CreateDirectoryTransactedW(
        WString lpTemplateDirectory,   // LPCWSTR optional
        WString lpNewDirectory,   // LPCWSTR
        Pointer lpSecurityAttributes,   // SECURITY_ATTRIBUTES* optional
        Pointer hTransaction   // HANDLE
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("kernel32")]
lib LibKERNEL32
  fun CreateDirectoryTransactedW = CreateDirectoryTransactedW(
    lpTemplateDirectory : UInt16*,   # LPCWSTR optional
    lpNewDirectory : UInt16*,   # LPCWSTR
    lpSecurityAttributes : SECURITY_ATTRIBUTES*,   # SECURITY_ATTRIBUTES* optional
    hTransaction : Void*   # HANDLE
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef CreateDirectoryTransactedWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef CreateDirectoryTransactedWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final CreateDirectoryTransactedW = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<CreateDirectoryTransactedWNative, CreateDirectoryTransactedWDart>('CreateDirectoryTransactedW');
// lpTemplateDirectory : LPCWSTR optional -> Pointer<Utf16>
// lpNewDirectory : LPCWSTR -> Pointer<Utf16>
// lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> Pointer<Void>
// hTransaction : HANDLE -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateDirectoryTransactedW(
  lpTemplateDirectory: PWideChar;   // LPCWSTR optional
  lpNewDirectory: PWideChar;   // LPCWSTR
  lpSecurityAttributes: Pointer;   // SECURITY_ATTRIBUTES* optional
  hTransaction: THandle   // HANDLE
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'CreateDirectoryTransactedW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateDirectoryTransactedW"
  c_CreateDirectoryTransactedW :: CWString -> CWString -> Ptr () -> Ptr () -> IO CInt
-- lpTemplateDirectory : LPCWSTR optional -> CWString
-- lpNewDirectory : LPCWSTR -> CWString
-- lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> Ptr ()
-- hTransaction : HANDLE -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createdirectorytransactedw =
  foreign "CreateDirectoryTransactedW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* lpTemplateDirectory : LPCWSTR optional -> (ptr uint16_t) *)
(* lpNewDirectory : LPCWSTR -> (ptr uint16_t) *)
(* lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> (ptr void) *)
(* hTransaction : HANDLE -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("CreateDirectoryTransactedW" create-directory-transacted-w :convention :stdcall) :int32
  (lp-template-directory (:string :encoding :utf-16le))   ; LPCWSTR optional
  (lp-new-directory (:string :encoding :utf-16le))   ; LPCWSTR
  (lp-security-attributes :pointer)   ; SECURITY_ATTRIBUTES* optional
  (h-transaction :pointer))   ; HANDLE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateDirectoryTransactedW = Win32::API::More->new('KERNEL32',
    'BOOL CreateDirectoryTransactedW(LPCWSTR lpTemplateDirectory, LPCWSTR lpNewDirectory, LPVOID lpSecurityAttributes, HANDLE hTransaction)');
# my $ret = $CreateDirectoryTransactedW->Call($lpTemplateDirectory, $lpNewDirectory, $lpSecurityAttributes, $hTransaction);
# lpTemplateDirectory : LPCWSTR optional -> LPCWSTR
# lpNewDirectory : LPCWSTR -> LPCWSTR
# lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> LPVOID
# hTransaction : HANDLE -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

文字セット違い
公式の関連項目
使用する型