ホーム › Storage.FileSystem › CreateHardLinkTransactedW
CreateHardLinkTransactedW
関数トランザクション内でハードリンクを作成する(Unicode版)。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
BOOL CreateHardLinkTransactedW(
LPCWSTR lpFileName,
LPCWSTR lpExistingFileName,
SECURITY_ATTRIBUTES* lpSecurityAttributes, // optional
HANDLE hTransaction
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpFileName | LPCWSTR | in |
| lpExistingFileName | LPCWSTR | in |
| lpSecurityAttributes | SECURITY_ATTRIBUTES* | optional |
| hTransaction | HANDLE | in |
戻り値の型: BOOL
各言語での呼び出し定義
// 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 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 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global CreateHardLinkTransactedW "CreateHardLinkTransactedW" wstr, wstr, sptr, sptr ; res = CreateHardLinkTransactedW(lpFileName, lpExistingFileName, varptr(lpSecurityAttributes), hTransaction) ; lpFileName : LPCWSTR -> "wstr" ; lpExistingFileName : LPCWSTR -> "wstr" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "sptr" ; hTransaction : HANDLE -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; BOOL CreateHardLinkTransactedW(LPCWSTR lpFileName, LPCWSTR lpExistingFileName, SECURITY_ATTRIBUTES* lpSecurityAttributes, HANDLE hTransaction) #uselib "KERNEL32.dll" #cfunc global CreateHardLinkTransactedW "CreateHardLinkTransactedW" wstr, wstr, intptr, intptr ; res = CreateHardLinkTransactedW(lpFileName, lpExistingFileName, varptr(lpSecurityAttributes), hTransaction) ; lpFileName : LPCWSTR -> "wstr" ; lpExistingFileName : LPCWSTR -> "wstr" ; lpSecurityAttributes : SECURITY_ATTRIBUTES* optional -> "intptr" ; hTransaction : HANDLE -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // BOOLfunction 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 版の利用を推奨。