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

BackupRead

関数
ファイルとそのストリームをバックアップ用に逐次読み取る。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

BOOL BackupRead(
    HANDLE hFile,
    BYTE* lpBuffer,
    DWORD nNumberOfBytesToRead,
    DWORD* lpNumberOfBytesRead,
    BOOL bAbort,
    BOOL bProcessSecurity,
    void** lpContext
);

パラメーター

名前方向
hFileHANDLEin
lpBufferBYTE*out
nNumberOfBytesToReadDWORDin
lpNumberOfBytesReadDWORD*out
bAbortBOOLin
bProcessSecurityBOOLin
lpContextvoid**inout

戻り値の型: BOOL

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

BOOL BackupRead(
    HANDLE hFile,
    BYTE* lpBuffer,
    DWORD nNumberOfBytesToRead,
    DWORD* lpNumberOfBytesRead,
    BOOL bAbort,
    BOOL bProcessSecurity,
    void** lpContext
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool BackupRead(
    IntPtr hFile,   // HANDLE
    IntPtr lpBuffer,   // BYTE* out
    uint nNumberOfBytesToRead,   // DWORD
    out uint lpNumberOfBytesRead,   // DWORD* out
    bool bAbort,   // BOOL
    bool bProcessSecurity,   // BOOL
    IntPtr lpContext   // void** in/out
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function BackupRead(
    hFile As IntPtr,   ' HANDLE
    lpBuffer As IntPtr,   ' BYTE* out
    nNumberOfBytesToRead As UInteger,   ' DWORD
    <Out> ByRef lpNumberOfBytesRead 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* out
' nNumberOfBytesToRead : DWORD
' lpNumberOfBytesRead : DWORD* out
' bAbort : BOOL
' bProcessSecurity : BOOL
' lpContext : void** in/out
Declare PtrSafe Function BackupRead Lib "kernel32" ( _
    ByVal hFile As LongPtr, _
    ByVal lpBuffer As LongPtr, _
    ByVal nNumberOfBytesToRead As Long, _
    ByRef lpNumberOfBytesRead 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

BackupRead = ctypes.windll.kernel32.BackupRead
BackupRead.restype = wintypes.BOOL
BackupRead.argtypes = [
    wintypes.HANDLE,  # hFile : HANDLE
    ctypes.POINTER(ctypes.c_ubyte),  # lpBuffer : BYTE* out
    wintypes.DWORD,  # nNumberOfBytesToRead : DWORD
    ctypes.POINTER(wintypes.DWORD),  # lpNumberOfBytesRead : 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')
BackupRead = Fiddle::Function.new(
  lib['BackupRead'],
  [
    Fiddle::TYPE_VOIDP,  # hFile : HANDLE
    Fiddle::TYPE_VOIDP,  # lpBuffer : BYTE* out
    -Fiddle::TYPE_INT,  # nNumberOfBytesToRead : DWORD
    Fiddle::TYPE_VOIDP,  # lpNumberOfBytesRead : 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 BackupRead(
        hFile: *mut core::ffi::c_void,  // HANDLE
        lpBuffer: *mut u8,  // BYTE* out
        nNumberOfBytesToRead: u32,  // DWORD
        lpNumberOfBytesRead: *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 BackupRead(IntPtr hFile, IntPtr lpBuffer, uint nNumberOfBytesToRead, out uint lpNumberOfBytesRead, bool bAbort, bool bProcessSecurity, IntPtr lpContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_BackupRead' -Namespace Win32 -PassThru
# $api::BackupRead(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext)
#uselib "KERNEL32.dll"
#func global BackupRead "BackupRead" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; BackupRead hFile, varptr(lpBuffer), nNumberOfBytesToRead, varptr(lpNumberOfBytesRead), bAbort, bProcessSecurity, lpContext   ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; lpBuffer : BYTE* out -> "sptr"
; nNumberOfBytesToRead : DWORD -> "sptr"
; lpNumberOfBytesRead : DWORD* out -> "sptr"
; bAbort : BOOL -> "sptr"
; bProcessSecurity : BOOL -> "sptr"
; lpContext : void** in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global BackupRead "BackupRead" sptr, var, int, var, int, int, sptr
; res = BackupRead(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext)
; hFile : HANDLE -> "sptr"
; lpBuffer : BYTE* out -> "var"
; nNumberOfBytesToRead : DWORD -> "int"
; lpNumberOfBytesRead : DWORD* out -> "var"
; bAbort : BOOL -> "int"
; bProcessSecurity : BOOL -> "int"
; lpContext : void** in/out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL BackupRead(HANDLE hFile, BYTE* lpBuffer, DWORD nNumberOfBytesToRead, DWORD* lpNumberOfBytesRead, BOOL bAbort, BOOL bProcessSecurity, void** lpContext)
#uselib "KERNEL32.dll"
#cfunc global BackupRead "BackupRead" intptr, var, int, var, int, int, intptr
; res = BackupRead(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext)
; hFile : HANDLE -> "intptr"
; lpBuffer : BYTE* out -> "var"
; nNumberOfBytesToRead : DWORD -> "int"
; lpNumberOfBytesRead : DWORD* out -> "var"
; bAbort : BOOL -> "int"
; bProcessSecurity : BOOL -> "int"
; lpContext : void** in/out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procBackupRead = kernel32.NewProc("BackupRead")
)

// hFile (HANDLE), lpBuffer (BYTE* out), nNumberOfBytesToRead (DWORD), lpNumberOfBytesRead (DWORD* out), bAbort (BOOL), bProcessSecurity (BOOL), lpContext (void** in/out)
r1, _, err := procBackupRead.Call(
	uintptr(hFile),
	uintptr(lpBuffer),
	uintptr(nNumberOfBytesToRead),
	uintptr(lpNumberOfBytesRead),
	uintptr(bAbort),
	uintptr(bProcessSecurity),
	uintptr(lpContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function BackupRead(
  hFile: THandle;   // HANDLE
  lpBuffer: Pointer;   // BYTE* out
  nNumberOfBytesToRead: DWORD;   // DWORD
  lpNumberOfBytesRead: Pointer;   // DWORD* out
  bAbort: BOOL;   // BOOL
  bProcessSecurity: BOOL;   // BOOL
  lpContext: Pointer   // void** in/out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'BackupRead';
result := DllCall("KERNEL32\BackupRead"
    , "Ptr", hFile   ; HANDLE
    , "Ptr", lpBuffer   ; BYTE* out
    , "UInt", nNumberOfBytesToRead   ; DWORD
    , "Ptr", lpNumberOfBytesRead   ; DWORD* out
    , "Int", bAbort   ; BOOL
    , "Int", bProcessSecurity   ; BOOL
    , "Ptr", lpContext   ; void** in/out
    , "Int")   ; return: BOOL
●BackupRead(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext) = DLL("KERNEL32.dll", "bool BackupRead(void*, void*, dword, void*, bool, bool, void*)")
# 呼び出し: BackupRead(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext)
# hFile : HANDLE -> "void*"
# lpBuffer : BYTE* out -> "void*"
# nNumberOfBytesToRead : DWORD -> "dword"
# lpNumberOfBytesRead : DWORD* out -> "void*"
# bAbort : BOOL -> "bool"
# bProcessSecurity : BOOL -> "bool"
# lpContext : void** in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。