ホーム › Storage.FileSystem › CopyFileTransactedA
CopyFileTransactedA
関数トランザクション内で進捗通知付きにファイルをコピーする(ANSI版)。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL CopyFileTransactedA(
LPCSTR lpExistingFileName,
LPCSTR lpNewFileName,
LPPROGRESS_ROUTINE lpProgressRoutine, // optional
void* lpData, // optional
BOOL* pbCancel, // optional
DWORD dwCopyFlags,
HANDLE hTransaction
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpExistingFileName | LPCSTR | in |
| lpNewFileName | LPCSTR | in |
| lpProgressRoutine | LPPROGRESS_ROUTINE | inoptional |
| lpData | void* | inoptional |
| pbCancel | BOOL* | inoptional |
| dwCopyFlags | DWORD | in |
| hTransaction | HANDLE | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL CopyFileTransactedA(
LPCSTR lpExistingFileName,
LPCSTR lpNewFileName,
LPPROGRESS_ROUTINE lpProgressRoutine, // optional
void* lpData, // optional
BOOL* pbCancel, // optional
DWORD dwCopyFlags,
HANDLE hTransaction
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool CopyFileTransactedA(
[MarshalAs(UnmanagedType.LPStr)] string lpExistingFileName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string lpNewFileName, // LPCSTR
IntPtr lpProgressRoutine, // LPPROGRESS_ROUTINE optional
IntPtr lpData, // void* optional
IntPtr pbCancel, // BOOL* optional
uint dwCopyFlags, // DWORD
IntPtr hTransaction // HANDLE
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CopyFileTransactedA(
<MarshalAs(UnmanagedType.LPStr)> lpExistingFileName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpNewFileName As String, ' LPCSTR
lpProgressRoutine As IntPtr, ' LPPROGRESS_ROUTINE optional
lpData As IntPtr, ' void* optional
pbCancel As IntPtr, ' BOOL* optional
dwCopyFlags As UInteger, ' DWORD
hTransaction As IntPtr ' HANDLE
) As Boolean
End Function' lpExistingFileName : LPCSTR
' lpNewFileName : LPCSTR
' lpProgressRoutine : LPPROGRESS_ROUTINE optional
' lpData : void* optional
' pbCancel : BOOL* optional
' dwCopyFlags : DWORD
' hTransaction : HANDLE
Declare PtrSafe Function CopyFileTransactedA Lib "kernel32" ( _
ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal lpProgressRoutine As LongPtr, _
ByVal lpData As LongPtr, _
ByVal pbCancel As LongPtr, _
ByVal dwCopyFlags As Long, _
ByVal hTransaction As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CopyFileTransactedA = ctypes.windll.kernel32.CopyFileTransactedA
CopyFileTransactedA.restype = wintypes.BOOL
CopyFileTransactedA.argtypes = [
wintypes.LPCSTR, # lpExistingFileName : LPCSTR
wintypes.LPCSTR, # lpNewFileName : LPCSTR
ctypes.c_void_p, # lpProgressRoutine : LPPROGRESS_ROUTINE optional
ctypes.POINTER(None), # lpData : void* optional
ctypes.c_void_p, # pbCancel : BOOL* optional
wintypes.DWORD, # dwCopyFlags : DWORD
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')
CopyFileTransactedA = Fiddle::Function.new(
lib['CopyFileTransactedA'],
[
Fiddle::TYPE_VOIDP, # lpExistingFileName : LPCSTR
Fiddle::TYPE_VOIDP, # lpNewFileName : LPCSTR
Fiddle::TYPE_VOIDP, # lpProgressRoutine : LPPROGRESS_ROUTINE optional
Fiddle::TYPE_VOIDP, # lpData : void* optional
Fiddle::TYPE_VOIDP, # pbCancel : BOOL* optional
-Fiddle::TYPE_INT, # dwCopyFlags : DWORD
Fiddle::TYPE_VOIDP, # hTransaction : HANDLE
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn CopyFileTransactedA(
lpExistingFileName: *const u8, // LPCSTR
lpNewFileName: *const u8, // LPCSTR
lpProgressRoutine: *const core::ffi::c_void, // LPPROGRESS_ROUTINE optional
lpData: *mut (), // void* optional
pbCancel: *mut i32, // BOOL* optional
dwCopyFlags: u32, // DWORD
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.Ansi, SetLastError = true)]
public static extern bool CopyFileTransactedA([MarshalAs(UnmanagedType.LPStr)] string lpExistingFileName, [MarshalAs(UnmanagedType.LPStr)] string lpNewFileName, IntPtr lpProgressRoutine, IntPtr lpData, IntPtr pbCancel, uint dwCopyFlags, IntPtr hTransaction);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CopyFileTransactedA' -Namespace Win32 -PassThru
# $api::CopyFileTransactedA(lpExistingFileName, lpNewFileName, lpProgressRoutine, lpData, pbCancel, dwCopyFlags, hTransaction)#uselib "KERNEL32.dll"
#func global CopyFileTransactedA "CopyFileTransactedA" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CopyFileTransactedA lpExistingFileName, lpNewFileName, lpProgressRoutine, lpData, pbCancel, dwCopyFlags, hTransaction ; 戻り値は stat
; lpExistingFileName : LPCSTR -> "sptr"
; lpNewFileName : LPCSTR -> "sptr"
; lpProgressRoutine : LPPROGRESS_ROUTINE optional -> "sptr"
; lpData : void* optional -> "sptr"
; pbCancel : BOOL* optional -> "sptr"
; dwCopyFlags : DWORD -> "sptr"
; hTransaction : HANDLE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global CopyFileTransactedA "CopyFileTransactedA" str, str, sptr, sptr, int, int, sptr
; res = CopyFileTransactedA(lpExistingFileName, lpNewFileName, lpProgressRoutine, lpData, pbCancel, dwCopyFlags, hTransaction)
; lpExistingFileName : LPCSTR -> "str"
; lpNewFileName : LPCSTR -> "str"
; lpProgressRoutine : LPPROGRESS_ROUTINE optional -> "sptr"
; lpData : void* optional -> "sptr"
; pbCancel : BOOL* optional -> "int"
; dwCopyFlags : DWORD -> "int"
; hTransaction : HANDLE -> "sptr"; BOOL CopyFileTransactedA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, LPPROGRESS_ROUTINE lpProgressRoutine, void* lpData, BOOL* pbCancel, DWORD dwCopyFlags, HANDLE hTransaction)
#uselib "KERNEL32.dll"
#cfunc global CopyFileTransactedA "CopyFileTransactedA" str, str, intptr, intptr, int, int, intptr
; res = CopyFileTransactedA(lpExistingFileName, lpNewFileName, lpProgressRoutine, lpData, pbCancel, dwCopyFlags, hTransaction)
; lpExistingFileName : LPCSTR -> "str"
; lpNewFileName : LPCSTR -> "str"
; lpProgressRoutine : LPPROGRESS_ROUTINE optional -> "intptr"
; lpData : void* optional -> "intptr"
; pbCancel : BOOL* optional -> "int"
; dwCopyFlags : DWORD -> "int"
; hTransaction : HANDLE -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procCopyFileTransactedA = kernel32.NewProc("CopyFileTransactedA")
)
// lpExistingFileName (LPCSTR), lpNewFileName (LPCSTR), lpProgressRoutine (LPPROGRESS_ROUTINE optional), lpData (void* optional), pbCancel (BOOL* optional), dwCopyFlags (DWORD), hTransaction (HANDLE)
r1, _, err := procCopyFileTransactedA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpExistingFileName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpNewFileName))),
uintptr(lpProgressRoutine),
uintptr(lpData),
uintptr(pbCancel),
uintptr(dwCopyFlags),
uintptr(hTransaction),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CopyFileTransactedA(
lpExistingFileName: PAnsiChar; // LPCSTR
lpNewFileName: PAnsiChar; // LPCSTR
lpProgressRoutine: Pointer; // LPPROGRESS_ROUTINE optional
lpData: Pointer; // void* optional
pbCancel: Pointer; // BOOL* optional
dwCopyFlags: DWORD; // DWORD
hTransaction: THandle // HANDLE
): BOOL; stdcall;
external 'KERNEL32.dll' name 'CopyFileTransactedA';result := DllCall("KERNEL32\CopyFileTransactedA"
, "AStr", lpExistingFileName ; LPCSTR
, "AStr", lpNewFileName ; LPCSTR
, "Ptr", lpProgressRoutine ; LPPROGRESS_ROUTINE optional
, "Ptr", lpData ; void* optional
, "Ptr", pbCancel ; BOOL* optional
, "UInt", dwCopyFlags ; DWORD
, "Ptr", hTransaction ; HANDLE
, "Int") ; return: BOOL●CopyFileTransactedA(lpExistingFileName, lpNewFileName, lpProgressRoutine, lpData, pbCancel, dwCopyFlags, hTransaction) = DLL("KERNEL32.dll", "bool CopyFileTransactedA(char*, char*, void*, void*, void*, dword, void*)")
# 呼び出し: CopyFileTransactedA(lpExistingFileName, lpNewFileName, lpProgressRoutine, lpData, pbCancel, dwCopyFlags, hTransaction)
# lpExistingFileName : LPCSTR -> "char*"
# lpNewFileName : LPCSTR -> "char*"
# lpProgressRoutine : LPPROGRESS_ROUTINE optional -> "void*"
# lpData : void* optional -> "void*"
# pbCancel : BOOL* optional -> "void*"
# dwCopyFlags : DWORD -> "dword"
# hTransaction : HANDLE -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。