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

FlushFileBuffers

関数
ファイルのバッファをディスクに書き込んで反映する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL FlushFileBuffers(
    HANDLE hFile
);

パラメーター

名前方向
hFileHANDLEin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL FlushFileBuffers(
    HANDLE hFile
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool FlushFileBuffers(
    IntPtr hFile   // HANDLE
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FlushFileBuffers(
    hFile As IntPtr   ' HANDLE
) As Boolean
End Function
' hFile : HANDLE
Declare PtrSafe Function FlushFileBuffers Lib "kernel32" ( _
    ByVal hFile As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

FlushFileBuffers = ctypes.windll.kernel32.FlushFileBuffers
FlushFileBuffers.restype = wintypes.BOOL
FlushFileBuffers.argtypes = [
    wintypes.HANDLE,  # hFile : HANDLE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
FlushFileBuffers = Fiddle::Function.new(
  lib['FlushFileBuffers'],
  [
    Fiddle::TYPE_VOIDP,  # hFile : HANDLE
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn FlushFileBuffers(
        hFile: *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", SetLastError = true)]
public static extern bool FlushFileBuffers(IntPtr hFile);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FlushFileBuffers' -Namespace Win32 -PassThru
# $api::FlushFileBuffers(hFile)
#uselib "KERNEL32.dll"
#func global FlushFileBuffers "FlushFileBuffers" sptr
; FlushFileBuffers hFile   ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global FlushFileBuffers "FlushFileBuffers" sptr
; res = FlushFileBuffers(hFile)
; hFile : HANDLE -> "sptr"
; BOOL FlushFileBuffers(HANDLE hFile)
#uselib "KERNEL32.dll"
#cfunc global FlushFileBuffers "FlushFileBuffers" intptr
; res = FlushFileBuffers(hFile)
; hFile : HANDLE -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procFlushFileBuffers = kernel32.NewProc("FlushFileBuffers")
)

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