ホーム › Storage.FileSystem › BackupWrite
BackupWrite
関数バックアップデータをファイルへ逐次書き込んで復元する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL BackupWrite(
HANDLE hFile,
BYTE* lpBuffer,
DWORD nNumberOfBytesToWrite,
DWORD* lpNumberOfBytesWritten,
BOOL bAbort,
BOOL bProcessSecurity,
void** lpContext
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hFile | HANDLE | in |
| lpBuffer | BYTE* | in |
| nNumberOfBytesToWrite | DWORD | in |
| lpNumberOfBytesWritten | DWORD* | out |
| bAbort | BOOL | in |
| bProcessSecurity | BOOL | in |
| lpContext | void** | inout |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL BackupWrite(
HANDLE hFile,
BYTE* lpBuffer,
DWORD nNumberOfBytesToWrite,
DWORD* lpNumberOfBytesWritten,
BOOL bAbort,
BOOL bProcessSecurity,
void** lpContext
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool BackupWrite(
IntPtr hFile, // HANDLE
IntPtr lpBuffer, // BYTE*
uint nNumberOfBytesToWrite, // DWORD
out uint lpNumberOfBytesWritten, // DWORD* out
bool bAbort, // BOOL
bool bProcessSecurity, // BOOL
IntPtr lpContext // void** in/out
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function BackupWrite(
hFile As IntPtr, ' HANDLE
lpBuffer As IntPtr, ' BYTE*
nNumberOfBytesToWrite As UInteger, ' DWORD
<Out> ByRef lpNumberOfBytesWritten As UInteger, ' DWORD* out
bAbort As Boolean, ' BOOL
bProcessSecurity As Boolean, ' BOOL
lpContext As IntPtr ' void** in/out
) As Boolean
End Function' hFile : HANDLE
' lpBuffer : BYTE*
' nNumberOfBytesToWrite : DWORD
' lpNumberOfBytesWritten : DWORD* out
' bAbort : BOOL
' bProcessSecurity : BOOL
' lpContext : void** in/out
Declare PtrSafe Function BackupWrite Lib "kernel32" ( _
ByVal hFile As LongPtr, _
ByVal lpBuffer As LongPtr, _
ByVal nNumberOfBytesToWrite As Long, _
ByRef lpNumberOfBytesWritten As Long, _
ByVal bAbort As Long, _
ByVal bProcessSecurity As Long, _
ByVal lpContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
BackupWrite = ctypes.windll.kernel32.BackupWrite
BackupWrite.restype = wintypes.BOOL
BackupWrite.argtypes = [
wintypes.HANDLE, # hFile : HANDLE
ctypes.POINTER(ctypes.c_ubyte), # lpBuffer : BYTE*
wintypes.DWORD, # nNumberOfBytesToWrite : DWORD
ctypes.POINTER(wintypes.DWORD), # lpNumberOfBytesWritten : DWORD* out
wintypes.BOOL, # bAbort : BOOL
wintypes.BOOL, # bProcessSecurity : BOOL
ctypes.c_void_p, # lpContext : void** in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
BackupWrite = Fiddle::Function.new(
lib['BackupWrite'],
[
Fiddle::TYPE_VOIDP, # hFile : HANDLE
Fiddle::TYPE_VOIDP, # lpBuffer : BYTE*
-Fiddle::TYPE_INT, # nNumberOfBytesToWrite : DWORD
Fiddle::TYPE_VOIDP, # lpNumberOfBytesWritten : DWORD* out
Fiddle::TYPE_INT, # bAbort : BOOL
Fiddle::TYPE_INT, # bProcessSecurity : BOOL
Fiddle::TYPE_VOIDP, # lpContext : void** in/out
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn BackupWrite(
hFile: *mut core::ffi::c_void, // HANDLE
lpBuffer: *mut u8, // BYTE*
nNumberOfBytesToWrite: u32, // DWORD
lpNumberOfBytesWritten: *mut u32, // DWORD* out
bAbort: i32, // BOOL
bProcessSecurity: i32, // BOOL
lpContext: *mut *mut () // void** in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool BackupWrite(IntPtr hFile, IntPtr lpBuffer, uint nNumberOfBytesToWrite, out uint lpNumberOfBytesWritten, bool bAbort, bool bProcessSecurity, IntPtr lpContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_BackupWrite' -Namespace Win32 -PassThru
# $api::BackupWrite(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, bAbort, bProcessSecurity, lpContext)#uselib "KERNEL32.dll"
#func global BackupWrite "BackupWrite" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; BackupWrite hFile, varptr(lpBuffer), nNumberOfBytesToWrite, varptr(lpNumberOfBytesWritten), bAbort, bProcessSecurity, lpContext ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; lpBuffer : BYTE* -> "sptr"
; nNumberOfBytesToWrite : DWORD -> "sptr"
; lpNumberOfBytesWritten : DWORD* out -> "sptr"
; bAbort : BOOL -> "sptr"
; bProcessSecurity : BOOL -> "sptr"
; lpContext : void** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global BackupWrite "BackupWrite" sptr, var, int, var, int, int, sptr ; res = BackupWrite(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, bAbort, bProcessSecurity, lpContext) ; hFile : HANDLE -> "sptr" ; lpBuffer : BYTE* -> "var" ; nNumberOfBytesToWrite : DWORD -> "int" ; lpNumberOfBytesWritten : DWORD* out -> "var" ; bAbort : BOOL -> "int" ; bProcessSecurity : BOOL -> "int" ; lpContext : void** in/out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global BackupWrite "BackupWrite" sptr, sptr, int, sptr, int, int, sptr ; res = BackupWrite(hFile, varptr(lpBuffer), nNumberOfBytesToWrite, varptr(lpNumberOfBytesWritten), bAbort, bProcessSecurity, lpContext) ; hFile : HANDLE -> "sptr" ; lpBuffer : BYTE* -> "sptr" ; nNumberOfBytesToWrite : DWORD -> "int" ; lpNumberOfBytesWritten : DWORD* out -> "sptr" ; bAbort : BOOL -> "int" ; bProcessSecurity : BOOL -> "int" ; lpContext : void** in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL BackupWrite(HANDLE hFile, BYTE* lpBuffer, DWORD nNumberOfBytesToWrite, DWORD* lpNumberOfBytesWritten, BOOL bAbort, BOOL bProcessSecurity, void** lpContext) #uselib "KERNEL32.dll" #cfunc global BackupWrite "BackupWrite" intptr, var, int, var, int, int, intptr ; res = BackupWrite(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, bAbort, bProcessSecurity, lpContext) ; hFile : HANDLE -> "intptr" ; lpBuffer : BYTE* -> "var" ; nNumberOfBytesToWrite : DWORD -> "int" ; lpNumberOfBytesWritten : DWORD* out -> "var" ; bAbort : BOOL -> "int" ; bProcessSecurity : BOOL -> "int" ; lpContext : void** in/out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL BackupWrite(HANDLE hFile, BYTE* lpBuffer, DWORD nNumberOfBytesToWrite, DWORD* lpNumberOfBytesWritten, BOOL bAbort, BOOL bProcessSecurity, void** lpContext) #uselib "KERNEL32.dll" #cfunc global BackupWrite "BackupWrite" intptr, intptr, int, intptr, int, int, intptr ; res = BackupWrite(hFile, varptr(lpBuffer), nNumberOfBytesToWrite, varptr(lpNumberOfBytesWritten), bAbort, bProcessSecurity, lpContext) ; hFile : HANDLE -> "intptr" ; lpBuffer : BYTE* -> "intptr" ; nNumberOfBytesToWrite : DWORD -> "int" ; lpNumberOfBytesWritten : DWORD* out -> "intptr" ; bAbort : BOOL -> "int" ; bProcessSecurity : BOOL -> "int" ; lpContext : void** in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procBackupWrite = kernel32.NewProc("BackupWrite")
)
// hFile (HANDLE), lpBuffer (BYTE*), nNumberOfBytesToWrite (DWORD), lpNumberOfBytesWritten (DWORD* out), bAbort (BOOL), bProcessSecurity (BOOL), lpContext (void** in/out)
r1, _, err := procBackupWrite.Call(
uintptr(hFile),
uintptr(lpBuffer),
uintptr(nNumberOfBytesToWrite),
uintptr(lpNumberOfBytesWritten),
uintptr(bAbort),
uintptr(bProcessSecurity),
uintptr(lpContext),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction BackupWrite(
hFile: THandle; // HANDLE
lpBuffer: Pointer; // BYTE*
nNumberOfBytesToWrite: DWORD; // DWORD
lpNumberOfBytesWritten: Pointer; // DWORD* out
bAbort: BOOL; // BOOL
bProcessSecurity: BOOL; // BOOL
lpContext: Pointer // void** in/out
): BOOL; stdcall;
external 'KERNEL32.dll' name 'BackupWrite';result := DllCall("KERNEL32\BackupWrite"
, "Ptr", hFile ; HANDLE
, "Ptr", lpBuffer ; BYTE*
, "UInt", nNumberOfBytesToWrite ; DWORD
, "Ptr", lpNumberOfBytesWritten ; DWORD* out
, "Int", bAbort ; BOOL
, "Int", bProcessSecurity ; BOOL
, "Ptr", lpContext ; void** in/out
, "Int") ; return: BOOL●BackupWrite(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, bAbort, bProcessSecurity, lpContext) = DLL("KERNEL32.dll", "bool BackupWrite(void*, void*, dword, void*, bool, bool, void*)")
# 呼び出し: BackupWrite(hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, bAbort, bProcessSecurity, lpContext)
# hFile : HANDLE -> "void*"
# lpBuffer : BYTE* -> "void*"
# nNumberOfBytesToWrite : DWORD -> "dword"
# lpNumberOfBytesWritten : DWORD* out -> "void*"
# bAbort : BOOL -> "bool"
# bProcessSecurity : BOOL -> "bool"
# lpContext : void** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。