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

バックアップ対象のファイルまたはディレクトリへのハンドル。ハンドルを取得するには、CreateFile 関数を呼び出します。ファイルハンドルが ACCESS_SYSTEM_SECURITY アクセス権を指定して作成されていない限り、SACL は読み取られません。詳細については、ファイルのセキュリティとアクセス権 を参照してください。

ハンドルは同期(非オーバーラップ)である必要があります。つまり、CreateFile を呼び出す際に FILE_FLAG_OVERLAPPED フラグを設定してはなりません。この関数は受け取ったハンドルが同期であるかどうかを検証しないため、同期ハンドルに対してエラーコードを返すことはありませんが、非同期(オーバーラップ)ハンドルを指定して呼び出すと、デバッグが非常に困難な微妙なエラーが発生する可能性があります。

CreateFileFILE_FLAG_NO_BUFFERING フラグを指定して呼び出された場合、BackupRead 関数は失敗することがあります。この場合、GetLastError 関数は ERROR_INVALID_PARAMETER を返します。

lpBufferBYTE*outデータを受け取るバッファへのポインター。
nNumberOfBytesToReadDWORDinバッファの長さ(バイト単位)。バッファのサイズは WIN32_STREAM_ID 構造体のサイズよりも大きくなければなりません。
lpNumberOfBytesReadDWORD*out

読み取られたバイト数を受け取る変数へのポインター。

関数が 0 以外の値を返し、lpNumberOfBytesRead が指す変数が 0 の場合、ファイルハンドルに関連付けられたすべてのデータが読み取られたことを意味します。

bAbortBOOLinハンドルに対する BackupRead の使用を終了したかどうかを示します。ファイルをバックアップしている間は、このパラメーターに FALSE を指定します。BackupRead の使用が完了したら、このパラメーターに TRUE を指定し、適切な lpContext を渡して、BackupRead をもう一度呼び出す必要があります。bAbortTRUE の場合は lpContext を渡す必要があり、その他のパラメーターはすべて無視されます。
bProcessSecurityBOOLin

この関数がファイルまたはディレクトリのアクセス制御リスト(ACL)データを復元するかどうかを示します。

bProcessSecurityTRUE の場合、ACL データがバックアップされます。

lpContextvoid**inout

BackupRead がバックアップ操作中にコンテキスト情報を保持するために使用する内部データ構造へのポインターを受け取る変数へのポインター。

指定したファイルまたはディレクトリに対して BackupRead を最初に呼び出す前に、lpContext が指す変数を NULL に設定する必要があります。関数はデータ構造用のメモリを割り当て、その構造を指すように変数を設定します。BackupRead の呼び出しの間に、lpContext またはそれが指す変数を変更してはなりません。

データ構造で使用されているメモリを解放するには、バックアップ操作の完了時に bAbort パラメーターを TRUE に設定して BackupRead を呼び出します。

戻り値の型: BOOL

公式ドキュメント

セキュリティ情報を含めて、ファイルまたはディレクトリをバックアップします。

戻り値

関数が成功した場合、戻り値は 0 以外の値になります。

関数が失敗した場合、戻り値は 0 になり、I/O エラーが発生したことを示します。拡張エラー情報を取得するには、GetLastError を呼び出します。

解説(Remarks)

この関数は、Encrypted File System で暗号化されたファイルのバックアップに使用することを意図したものではありません。その目的には ReadEncryptedFileRaw を使用してください。

BackupRead がデータを読み取っている間にエラーが発生した場合、呼び出し側プロセスは BackupSeek 関数を呼び出すことで不良データをスキップできます。

ファイルまたはディレクトリは BackupWrite 関数を使用して復元する必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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 <MarshalAs(UnmanagedType.Bool)> 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)。
const std = @import("std");

extern "kernel32" fn BackupRead(
    hFile: ?*anyopaque, // HANDLE
    lpBuffer: [*c]u8, // BYTE* out
    nNumberOfBytesToRead: u32, // DWORD
    lpNumberOfBytesRead: [*c]u32, // DWORD* out
    bAbort: i32, // BOOL
    bProcessSecurity: i32, // BOOL
    lpContext: ?*anyopaque // void** in/out
) callconv(std.os.windows.WINAPI) i32;
proc BackupRead(
    hFile: pointer,  # HANDLE
    lpBuffer: ptr uint8,  # BYTE* out
    nNumberOfBytesToRead: uint32,  # DWORD
    lpNumberOfBytesRead: ptr uint32,  # DWORD* out
    bAbort: int32,  # BOOL
    bProcessSecurity: int32,  # BOOL
    lpContext: pointer  # void** in/out
): int32 {.importc: "BackupRead", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int BackupRead(
    void* hFile,   // HANDLE
    ubyte* lpBuffer,   // BYTE* out
    uint nNumberOfBytesToRead,   // DWORD
    uint* lpNumberOfBytesRead,   // DWORD* out
    int bAbort,   // BOOL
    int bProcessSecurity,   // BOOL
    void** lpContext   // void** in/out
);
ccall((:BackupRead, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Ptr{UInt8}, UInt32, Ptr{UInt32}, Int32, Int32, Ptr{Cvoid}),
      hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext)
# hFile : HANDLE -> Ptr{Cvoid}
# lpBuffer : BYTE* out -> Ptr{UInt8}
# nNumberOfBytesToRead : DWORD -> UInt32
# lpNumberOfBytesRead : DWORD* out -> Ptr{UInt32}
# bAbort : BOOL -> Int32
# bProcessSecurity : BOOL -> Int32
# lpContext : void** in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t BackupRead(
    void* hFile,
    uint8_t* lpBuffer,
    uint32_t nNumberOfBytesToRead,
    uint32_t* lpNumberOfBytesRead,
    int32_t bAbort,
    int32_t bProcessSecurity,
    void** lpContext);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.BackupRead(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext)
-- hFile : HANDLE
-- lpBuffer : BYTE* out
-- nNumberOfBytesToRead : DWORD
-- lpNumberOfBytesRead : DWORD* out
-- bAbort : BOOL
-- bProcessSecurity : BOOL
-- lpContext : void** in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const BackupRead = lib.func('__stdcall', 'BackupRead', 'int32_t', ['void *', 'uint8_t *', 'uint32_t', 'uint32_t *', 'int32_t', 'int32_t', 'void *']);
// BackupRead(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext)
// hFile : HANDLE -> 'void *'
// lpBuffer : BYTE* out -> 'uint8_t *'
// nNumberOfBytesToRead : DWORD -> 'uint32_t'
// lpNumberOfBytesRead : DWORD* out -> 'uint32_t *'
// bAbort : BOOL -> 'int32_t'
// bProcessSecurity : BOOL -> 'int32_t'
// lpContext : void** in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  BackupRead: { parameters: ["pointer", "pointer", "u32", "pointer", "i32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.BackupRead(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext)
// hFile : HANDLE -> "pointer"
// lpBuffer : BYTE* out -> "pointer"
// nNumberOfBytesToRead : DWORD -> "u32"
// lpNumberOfBytesRead : DWORD* out -> "pointer"
// bAbort : BOOL -> "i32"
// bProcessSecurity : BOOL -> "i32"
// lpContext : void** in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t BackupRead(
    void* hFile,
    uint8_t* lpBuffer,
    uint32_t nNumberOfBytesToRead,
    uint32_t* lpNumberOfBytesRead,
    int32_t bAbort,
    int32_t bProcessSecurity,
    void** lpContext);
C, "KERNEL32.dll");
// $ffi->BackupRead(hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, bAbort, bProcessSecurity, lpContext);
// hFile : HANDLE
// lpBuffer : BYTE* out
// nNumberOfBytesToRead : DWORD
// lpNumberOfBytesRead : DWORD* out
// bAbort : BOOL
// bProcessSecurity : BOOL
// lpContext : void** in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    boolean BackupRead(
        Pointer hFile,   // HANDLE
        byte[] lpBuffer,   // BYTE* out
        int nNumberOfBytesToRead,   // DWORD
        IntByReference lpNumberOfBytesRead,   // DWORD* out
        boolean bAbort,   // BOOL
        boolean bProcessSecurity,   // BOOL
        Pointer lpContext   // void** in/out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun BackupRead = BackupRead(
    hFile : Void*,   # HANDLE
    lpBuffer : UInt8*,   # BYTE* out
    nNumberOfBytesToRead : UInt32,   # DWORD
    lpNumberOfBytesRead : UInt32*,   # DWORD* out
    bAbort : Int32,   # BOOL
    bProcessSecurity : Int32,   # BOOL
    lpContext : Void**   # void** in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef BackupReadNative = Int32 Function(Pointer<Void>, Pointer<Uint8>, Uint32, Pointer<Uint32>, Int32, Int32, Pointer<Void>);
typedef BackupReadDart = int Function(Pointer<Void>, Pointer<Uint8>, int, Pointer<Uint32>, int, int, Pointer<Void>);
final BackupRead = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<BackupReadNative, BackupReadDart>('BackupRead');
// hFile : HANDLE -> Pointer<Void>
// lpBuffer : BYTE* out -> Pointer<Uint8>
// nNumberOfBytesToRead : DWORD -> Uint32
// lpNumberOfBytesRead : DWORD* out -> Pointer<Uint32>
// bAbort : BOOL -> Int32
// bProcessSecurity : BOOL -> Int32
// lpContext : void** in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "BackupRead"
  c_BackupRead :: Ptr () -> Ptr Word8 -> Word32 -> Ptr Word32 -> CInt -> CInt -> Ptr () -> IO CInt
-- hFile : HANDLE -> Ptr ()
-- lpBuffer : BYTE* out -> Ptr Word8
-- nNumberOfBytesToRead : DWORD -> Word32
-- lpNumberOfBytesRead : DWORD* out -> Ptr Word32
-- bAbort : BOOL -> CInt
-- bProcessSecurity : BOOL -> CInt
-- lpContext : void** in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let backupread =
  foreign "BackupRead"
    ((ptr void) @-> (ptr uint8_t) @-> uint32_t @-> (ptr uint32_t) @-> int32_t @-> int32_t @-> (ptr void) @-> returning int32_t)
(* hFile : HANDLE -> (ptr void) *)
(* lpBuffer : BYTE* out -> (ptr uint8_t) *)
(* nNumberOfBytesToRead : DWORD -> uint32_t *)
(* lpNumberOfBytesRead : DWORD* out -> (ptr uint32_t) *)
(* bAbort : BOOL -> int32_t *)
(* bProcessSecurity : BOOL -> int32_t *)
(* lpContext : void** in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("BackupRead" backup-read :convention :stdcall) :int32
  (h-file :pointer)   ; HANDLE
  (lp-buffer :pointer)   ; BYTE* out
  (n-number-of-bytes-to-read :uint32)   ; DWORD
  (lp-number-of-bytes-read :pointer)   ; DWORD* out
  (b-abort :int32)   ; BOOL
  (b-process-security :int32)   ; BOOL
  (lp-context :pointer))   ; void** in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $BackupRead = Win32::API::More->new('KERNEL32',
    'BOOL BackupRead(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPVOID lpNumberOfBytesRead, BOOL bAbort, BOOL bProcessSecurity, LPVOID lpContext)');
# my $ret = $BackupRead->Call($hFile, $lpBuffer, $nNumberOfBytesToRead, $lpNumberOfBytesRead, $bAbort, $bProcessSecurity, $lpContext);
# hFile : HANDLE -> HANDLE
# lpBuffer : BYTE* out -> LPVOID
# nNumberOfBytesToRead : DWORD -> DWORD
# lpNumberOfBytesRead : DWORD* out -> LPVOID
# bAbort : BOOL -> BOOL
# bProcessSecurity : BOOL -> BOOL
# lpContext : void** in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目