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

SetFileCompletionNotificationModes

関数
ファイルハンドルのI/O完了通知モードを設定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL SetFileCompletionNotificationModes(
    HANDLE FileHandle,
    BYTE Flags
);

パラメーター

名前方向
FileHandleHANDLEin
FlagsBYTEin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

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

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetFileCompletionNotificationModes = kernel32.NewProc("SetFileCompletionNotificationModes")
)

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