ホーム › Storage.FileSystem › CopyFileA
CopyFileA
関数既存ファイルを新しいファイルへコピーする(ANSI版)。
シグネチャ
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL CopyFileA(
LPCSTR lpExistingFileName,
LPCSTR lpNewFileName,
BOOL bFailIfExists
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpExistingFileName | LPCSTR | in |
| lpNewFileName | LPCSTR | in |
| bFailIfExists | BOOL | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll (ANSI / -A)
#include <windows.h>
BOOL CopyFileA(
LPCSTR lpExistingFileName,
LPCSTR lpNewFileName,
BOOL bFailIfExists
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool CopyFileA(
[MarshalAs(UnmanagedType.LPStr)] string lpExistingFileName, // LPCSTR
[MarshalAs(UnmanagedType.LPStr)] string lpNewFileName, // LPCSTR
bool bFailIfExists // BOOL
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CopyFileA(
<MarshalAs(UnmanagedType.LPStr)> lpExistingFileName As String, ' LPCSTR
<MarshalAs(UnmanagedType.LPStr)> lpNewFileName As String, ' LPCSTR
bFailIfExists As Boolean ' BOOL
) As Boolean
End Function' lpExistingFileName : LPCSTR
' lpNewFileName : LPCSTR
' bFailIfExists : BOOL
Declare PtrSafe Function CopyFileA Lib "kernel32" ( _
ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CopyFileA = ctypes.windll.kernel32.CopyFileA
CopyFileA.restype = wintypes.BOOL
CopyFileA.argtypes = [
wintypes.LPCSTR, # lpExistingFileName : LPCSTR
wintypes.LPCSTR, # lpNewFileName : LPCSTR
wintypes.BOOL, # bFailIfExists : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
CopyFileA = Fiddle::Function.new(
lib['CopyFileA'],
[
Fiddle::TYPE_VOIDP, # lpExistingFileName : LPCSTR
Fiddle::TYPE_VOIDP, # lpNewFileName : LPCSTR
Fiddle::TYPE_INT, # bFailIfExists : BOOL
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn CopyFileA(
lpExistingFileName: *const u8, // LPCSTR
lpNewFileName: *const u8, // LPCSTR
bFailIfExists: i32 // BOOL
) -> 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 CopyFileA([MarshalAs(UnmanagedType.LPStr)] string lpExistingFileName, [MarshalAs(UnmanagedType.LPStr)] string lpNewFileName, bool bFailIfExists);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CopyFileA' -Namespace Win32 -PassThru
# $api::CopyFileA(lpExistingFileName, lpNewFileName, bFailIfExists)#uselib "KERNEL32.dll"
#func global CopyFileA "CopyFileA" sptr, sptr, sptr
; CopyFileA lpExistingFileName, lpNewFileName, bFailIfExists ; 戻り値は stat
; lpExistingFileName : LPCSTR -> "sptr"
; lpNewFileName : LPCSTR -> "sptr"
; bFailIfExists : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global CopyFileA "CopyFileA" str, str, int
; res = CopyFileA(lpExistingFileName, lpNewFileName, bFailIfExists)
; lpExistingFileName : LPCSTR -> "str"
; lpNewFileName : LPCSTR -> "str"
; bFailIfExists : BOOL -> "int"; BOOL CopyFileA(LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExists)
#uselib "KERNEL32.dll"
#cfunc global CopyFileA "CopyFileA" str, str, int
; res = CopyFileA(lpExistingFileName, lpNewFileName, bFailIfExists)
; lpExistingFileName : LPCSTR -> "str"
; lpNewFileName : LPCSTR -> "str"
; bFailIfExists : BOOL -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procCopyFileA = kernel32.NewProc("CopyFileA")
)
// lpExistingFileName (LPCSTR), lpNewFileName (LPCSTR), bFailIfExists (BOOL)
r1, _, err := procCopyFileA.Call(
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpExistingFileName))),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpNewFileName))),
uintptr(bFailIfExists),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction CopyFileA(
lpExistingFileName: PAnsiChar; // LPCSTR
lpNewFileName: PAnsiChar; // LPCSTR
bFailIfExists: BOOL // BOOL
): BOOL; stdcall;
external 'KERNEL32.dll' name 'CopyFileA';result := DllCall("KERNEL32\CopyFileA"
, "AStr", lpExistingFileName ; LPCSTR
, "AStr", lpNewFileName ; LPCSTR
, "Int", bFailIfExists ; BOOL
, "Int") ; return: BOOL●CopyFileA(lpExistingFileName, lpNewFileName, bFailIfExists) = DLL("KERNEL32.dll", "bool CopyFileA(char*, char*, bool)")
# 呼び出し: CopyFileA(lpExistingFileName, lpNewFileName, bFailIfExists)
# lpExistingFileName : LPCSTR -> "char*"
# lpNewFileName : LPCSTR -> "char*"
# bFailIfExists : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。