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

CreateHardLinkTransactedW

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

シグネチャ

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

BOOL CreateHardLinkTransactedW(
    LPCWSTR lpFileName,
    LPCWSTR lpExistingFileName,
    SECURITY_ATTRIBUTES* lpSecurityAttributes,   // optional
    HANDLE hTransaction
);

パラメーター

名前方向説明
lpFileNameLPCWSTRin

新しいファイルの名前。

このパラメーターでディレクトリの名前を指定することはできません。

lpExistingFileNameLPCWSTRin

既存のファイルの名前。

このパラメーターでディレクトリの名前を指定することはできません。

lpSecurityAttributesSECURITY_ATTRIBUTES*optional予約済み。NULL を指定する必要があります。
hTransactionHANDLEinトランザクションへのハンドル。このハンドルは CreateTransaction 関数によって返されます。

戻り値の型: BOOL

公式ドキュメント

既存のファイルと新しいファイルとの間にハードリンクを、トランザクション操作として確立します。(Unicode)

戻り値

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

関数が失敗した場合、戻り値は 0 です。詳細なエラー情報を取得するには、 GetLastError を呼び出します。

この関数で作成できるハードリンクの最大数は、ファイルごとに 1023 個です。1 つのファイルに対して 1023 個を超える リンクを作成しようとすると、エラーが発生します。

ファイルはローカルコンピューター上に存在する必要があります。そうでない場合、 関数は失敗し、最終エラーコードは ERROR_TRANSACTIONS_UNSUPPORTED_REMOTE に設定されます。

解説(Remarks)

CreateFileTransacted または CreateHardLinkTransacted で作成されたファイルのディレクトリエントリは、 関連付けられたファイルへのハードリンクです。CreateHardLinkTransacted 関数で作成される追加のハードリンクを利用すると、 1 つのファイルに対して複数のディレクトリエントリ、つまり同一ファイルへの複数のハードリンクを持つことができます。これらは同じディレクトリ内で異なる 名前にすることも、異なるディレクトリ内で同じまたは異なる名前にすることもできます。ただし、あるファイルへのすべてのハードリンクは 同じボリューム上に存在する必要があります。

ハードリンクはファイルのディレクトリエントリにすぎないため、アプリケーションがいずれかのハードリンクを通じてファイルを変更すると、 そのファイルへの他のハードリンクを使用するすべてのアプリケーションにその変更が反映されます。また、ファイルが変更されると、すべてのディレクトリ エントリが更新されます。たとえば、ファイルサイズが変化すると、そのファイルへのすべてのハードリンクに 新しいファイルサイズが表示されます。

セキュリティ記述子は、ハードリンクが指すファイルに属します。リンク自体はディレクトリ エントリにすぎず、セキュリティ記述子を持ちません。したがって、ハードリンクのセキュリティ記述子を変更すると、 基になるファイルのセキュリティ記述子を変更することになり、そのファイルを指すすべてのハードリンクが 新しく指定されたアクセスを許可するようになります。ハードリンクごとに異なるセキュリティ記述子をファイルに付与することはできません。

この関数は、lpSecurityAttributes パラメーターでセキュリティ記述子の 情報が渡された場合でも、リンク先のファイルのセキュリティ記述子を変更しません。

ハードリンクを削除するには DeleteFileTransacted を使用します。 作成された順序にかかわらず、任意の順序で削除できます。

CreateFileTransacted で指定されたフラグ、属性、アクセス、共有は、 ファイル単位で動作します。 つまり、共有を許可しないファイルを開いた場合、別のアプリケーションがそのファイルへの 新しいハードリンクを作成して共有することはできません。

NTFS ファイルシステム上でハードリンクを作成する場合、ディレクトリエントリ内のファイル属性情報は、 ファイルが開かれたとき、または特定のファイルのハンドルを指定して GetFileInformationByHandle が呼び出されたときにのみ 更新されます。

シンボリックリンク: パスがシンボリックリンクを指している場合、この関数はそのターゲットへのハードリンクを作成します。

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

テクノロジ サポート
Server Message Block (SMB) 3.0 プロトコル いいえ
SMB 3.0 トランスペアレントフェールオーバー (TFO) いいえ
SMB 3.0 とスケールアウトファイル共有 (SO) いいえ
クラスター共有ボリュームファイルシステム (CsvFS) いいえ
回復性ファイルシステム (ReFS) いいえ

SMB 3.0 は TxF をサポートしていないことに注意してください。

メモ

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

出典・ライセンス: 上記「公式ドキュメント」の内容は 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 CreateHardLinkTransactedW(
    LPCWSTR lpFileName,
    LPCWSTR lpExistingFileName,
    SECURITY_ATTRIBUTES* lpSecurityAttributes,   // optional
    HANDLE hTransaction
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool CreateHardLinkTransactedW(
    [MarshalAs(UnmanagedType.LPWStr)] string lpFileName,   // LPCWSTR
    [MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName,   // LPCWSTR
    IntPtr lpSecurityAttributes,   // SECURITY_ATTRIBUTES* optional
    IntPtr hTransaction   // HANDLE
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateHardLinkTransactedW(
    <MarshalAs(UnmanagedType.LPWStr)> lpFileName As String,   ' LPCWSTR
    <MarshalAs(UnmanagedType.LPWStr)> lpExistingFileName As String,   ' LPCWSTR
    lpSecurityAttributes As IntPtr,   ' SECURITY_ATTRIBUTES* optional
    hTransaction As IntPtr   ' HANDLE
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' lpFileName : LPCWSTR
' lpExistingFileName : LPCWSTR
' lpSecurityAttributes : SECURITY_ATTRIBUTES* optional
' hTransaction : HANDLE
Declare PtrSafe Function CreateHardLinkTransactedW Lib "kernel32" ( _
    ByVal lpFileName As LongPtr, _
    ByVal lpExistingFileName 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

CreateHardLinkTransactedW = ctypes.windll.kernel32.CreateHardLinkTransactedW
CreateHardLinkTransactedW.restype = wintypes.BOOL
CreateHardLinkTransactedW.argtypes = [
    wintypes.LPCWSTR,  # lpFileName : LPCWSTR
    wintypes.LPCWSTR,  # lpExistingFileName : 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')
CreateHardLinkTransactedW = Fiddle::Function.new(
  lib['CreateHardLinkTransactedW'],
  [
    Fiddle::TYPE_VOIDP,  # lpFileName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # lpExistingFileName : 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 CreateHardLinkTransactedW(
        lpFileName: *const u16,  // LPCWSTR
        lpExistingFileName: *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 CreateHardLinkTransactedW([MarshalAs(UnmanagedType.LPWStr)] string lpFileName, [MarshalAs(UnmanagedType.LPWStr)] string lpExistingFileName, IntPtr lpSecurityAttributes, IntPtr hTransaction);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CreateHardLinkTransactedW' -Namespace Win32 -PassThru
# $api::CreateHardLinkTransactedW(lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction)
#uselib "KERNEL32.dll"
#func global CreateHardLinkTransactedW "CreateHardLinkTransactedW" wptr, wptr, wptr, wptr
; CreateHardLinkTransactedW lpFileName, lpExistingFileName, varptr(lpSecurityAttributes), hTransaction   ; 戻り値は stat
; lpFileName : LPCWSTR -> "wptr"
; lpExistingFileName : LPCWSTR -> "wptr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "wptr"
; hTransaction : HANDLE -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global CreateHardLinkTransactedW "CreateHardLinkTransactedW" wstr, wstr, var, sptr
; res = CreateHardLinkTransactedW(lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction)
; lpFileName : LPCWSTR -> "wstr"
; lpExistingFileName : LPCWSTR -> "wstr"
; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; hTransaction : HANDLE -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL CreateHardLinkTransactedW(LPCWSTR lpFileName, LPCWSTR lpExistingFileName, SECURITY_ATTRIBUTES* lpSecurityAttributes, HANDLE hTransaction)
#uselib "KERNEL32.dll"
#cfunc global CreateHardLinkTransactedW "CreateHardLinkTransactedW" wstr, wstr, var, intptr
; res = CreateHardLinkTransactedW(lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction)
; lpFileName : LPCWSTR -> "wstr"
; lpExistingFileName : 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")
	procCreateHardLinkTransactedW = kernel32.NewProc("CreateHardLinkTransactedW")
)

// lpFileName (LPCWSTR), lpExistingFileName (LPCWSTR), lpSecurityAttributes (SECURITY_ATTRIBUTES* optional), hTransaction (HANDLE)
r1, _, err := procCreateHardLinkTransactedW.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpFileName))),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpExistingFileName))),
	uintptr(lpSecurityAttributes),
	uintptr(hTransaction),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function CreateHardLinkTransactedW(
  lpFileName: PWideChar;   // LPCWSTR
  lpExistingFileName: PWideChar;   // LPCWSTR
  lpSecurityAttributes: Pointer;   // SECURITY_ATTRIBUTES* optional
  hTransaction: THandle   // HANDLE
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'CreateHardLinkTransactedW';
result := DllCall("KERNEL32\CreateHardLinkTransactedW"
    , "WStr", lpFileName   ; LPCWSTR
    , "WStr", lpExistingFileName   ; LPCWSTR
    , "Ptr", lpSecurityAttributes   ; SECURITY_ATTRIBUTES* optional
    , "Ptr", hTransaction   ; HANDLE
    , "Int")   ; return: BOOL
●CreateHardLinkTransactedW(lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction) = DLL("KERNEL32.dll", "bool CreateHardLinkTransactedW(char*, char*, void*, void*)")
# 呼び出し: CreateHardLinkTransactedW(lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction)
# lpFileName : LPCWSTR -> "char*"
# lpExistingFileName : 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 CreateHardLinkTransactedW(
    lpFileName: [*c]const u16, // LPCWSTR
    lpExistingFileName: [*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 CreateHardLinkTransactedW(
    lpFileName: WideCString,  # LPCWSTR
    lpExistingFileName: WideCString,  # LPCWSTR
    lpSecurityAttributes: ptr SECURITY_ATTRIBUTES,  # SECURITY_ATTRIBUTES* optional
    hTransaction: pointer  # HANDLE
): int32 {.importc: "CreateHardLinkTransactedW", stdcall, dynlib: "KERNEL32.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。
pragma(lib, "kernel32");
extern(Windows)
int CreateHardLinkTransactedW(
    const(wchar)* lpFileName,   // LPCWSTR
    const(wchar)* lpExistingFileName,   // LPCWSTR
    SECURITY_ATTRIBUTES* lpSecurityAttributes,   // SECURITY_ATTRIBUTES* optional
    void* hTransaction   // HANDLE
);
ccall((:CreateHardLinkTransactedW, "KERNEL32.dll"), stdcall, Int32,
      (Cwstring, Cwstring, Ptr{SECURITY_ATTRIBUTES}, Ptr{Cvoid}),
      lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction)
# lpFileName : LPCWSTR -> Cwstring
# lpExistingFileName : 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 CreateHardLinkTransactedW(
    const uint16_t* lpFileName,
    const uint16_t* lpExistingFileName,
    void* lpSecurityAttributes,
    void* hTransaction);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.CreateHardLinkTransactedW(lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction)
-- lpFileName : LPCWSTR
-- lpExistingFileName : 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 CreateHardLinkTransactedW = lib.func('__stdcall', 'CreateHardLinkTransactedW', 'int32_t', ['str16', 'str16', 'void *', 'void *']);
// CreateHardLinkTransactedW(lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction)
// lpFileName : LPCWSTR -> 'str16'
// lpExistingFileName : LPCWSTR -> 'str16'
// lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> 'void *'
// hTransaction : HANDLE -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  CreateHardLinkTransactedW: { parameters: ["buffer", "buffer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.CreateHardLinkTransactedW(lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction)
// lpFileName : LPCWSTR -> "buffer"
// lpExistingFileName : 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 CreateHardLinkTransactedW(
    const uint16_t* lpFileName,
    const uint16_t* lpExistingFileName,
    void* lpSecurityAttributes,
    void* hTransaction);
C, "KERNEL32.dll");
// $ffi->CreateHardLinkTransactedW(lpFileName, lpExistingFileName, lpSecurityAttributes, hTransaction);
// lpFileName : LPCWSTR
// lpExistingFileName : 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 CreateHardLinkTransactedW(
        WString lpFileName,   // LPCWSTR
        WString lpExistingFileName,   // LPCWSTR
        Pointer lpSecurityAttributes,   // SECURITY_ATTRIBUTES* optional
        Pointer hTransaction   // HANDLE
    );
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。
@[Link("kernel32")]
lib LibKERNEL32
  fun CreateHardLinkTransactedW = CreateHardLinkTransactedW(
    lpFileName : UInt16*,   # LPCWSTR
    lpExistingFileName : 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 CreateHardLinkTransactedWNative = Int32 Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
typedef CreateHardLinkTransactedWDart = int Function(Pointer<Utf16>, Pointer<Utf16>, Pointer<Void>, Pointer<Void>);
final CreateHardLinkTransactedW = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<CreateHardLinkTransactedWNative, CreateHardLinkTransactedWDart>('CreateHardLinkTransactedW');
// lpFileName : LPCWSTR -> Pointer<Utf16>
// lpExistingFileName : LPCWSTR -> Pointer<Utf16>
// lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> Pointer<Void>
// hTransaction : HANDLE -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateHardLinkTransactedW(
  lpFileName: PWideChar;   // LPCWSTR
  lpExistingFileName: PWideChar;   // LPCWSTR
  lpSecurityAttributes: Pointer;   // SECURITY_ATTRIBUTES* optional
  hTransaction: THandle   // HANDLE
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'CreateHardLinkTransactedW';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let createhardlinktransactedw =
  foreign "CreateHardLinkTransactedW"
    ((ptr uint16_t) @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* lpFileName : LPCWSTR -> (ptr uint16_t) *)
(* lpExistingFileName : 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 ("CreateHardLinkTransactedW" create-hard-link-transacted-w :convention :stdcall) :int32
  (lp-file-name (:string :encoding :utf-16le))   ; LPCWSTR
  (lp-existing-file-name (: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 $CreateHardLinkTransactedW = Win32::API::More->new('KERNEL32',
    'BOOL CreateHardLinkTransactedW(LPCWSTR lpFileName, LPCWSTR lpExistingFileName, LPVOID lpSecurityAttributes, HANDLE hTransaction)');
# my $ret = $CreateHardLinkTransactedW->Call($lpFileName, $lpExistingFileName, $lpSecurityAttributes, $hTransaction);
# lpFileName : LPCWSTR -> LPCWSTR
# lpExistingFileName : LPCWSTR -> LPCWSTR
# lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> LPVOID
# hTransaction : HANDLE -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。

関連項目

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