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

FindFirstChangeNotificationA

関数
ディレクトリの変更監視を開始し通知ハンドルを返す(ANSI版)。
DLLKERNEL32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

HANDLE FindFirstChangeNotificationA(
    LPCSTR lpPathName,
    BOOL bWatchSubtree,
    FILE_NOTIFY_CHANGE dwNotifyFilter
);

パラメーター

名前方向
lpPathNameLPCSTRin
bWatchSubtreeBOOLin
dwNotifyFilterFILE_NOTIFY_CHANGEin

戻り値の型: HANDLE

各言語での呼び出し定義

// KERNEL32.dll  (ANSI / -A)
#include <windows.h>

HANDLE FindFirstChangeNotificationA(
    LPCSTR lpPathName,
    BOOL bWatchSubtree,
    FILE_NOTIFY_CHANGE dwNotifyFilter
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindFirstChangeNotificationA(
    [MarshalAs(UnmanagedType.LPStr)] string lpPathName,   // LPCSTR
    bool bWatchSubtree,   // BOOL
    uint dwNotifyFilter   // FILE_NOTIFY_CHANGE
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindFirstChangeNotificationA(
    <MarshalAs(UnmanagedType.LPStr)> lpPathName As String,   ' LPCSTR
    bWatchSubtree As Boolean,   ' BOOL
    dwNotifyFilter As UInteger   ' FILE_NOTIFY_CHANGE
) As IntPtr
End Function
' lpPathName : LPCSTR
' bWatchSubtree : BOOL
' dwNotifyFilter : FILE_NOTIFY_CHANGE
Declare PtrSafe Function FindFirstChangeNotificationA Lib "kernel32" ( _
    ByVal lpPathName As String, _
    ByVal bWatchSubtree As Long, _
    ByVal dwNotifyFilter As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

FindFirstChangeNotificationA = ctypes.windll.kernel32.FindFirstChangeNotificationA
FindFirstChangeNotificationA.restype = ctypes.c_void_p
FindFirstChangeNotificationA.argtypes = [
    wintypes.LPCSTR,  # lpPathName : LPCSTR
    wintypes.BOOL,  # bWatchSubtree : BOOL
    wintypes.DWORD,  # dwNotifyFilter : FILE_NOTIFY_CHANGE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
FindFirstChangeNotificationA = Fiddle::Function.new(
  lib['FindFirstChangeNotificationA'],
  [
    Fiddle::TYPE_VOIDP,  # lpPathName : LPCSTR
    Fiddle::TYPE_INT,  # bWatchSubtree : BOOL
    -Fiddle::TYPE_INT,  # dwNotifyFilter : FILE_NOTIFY_CHANGE
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "kernel32")]
extern "system" {
    fn FindFirstChangeNotificationA(
        lpPathName: *const u8,  // LPCSTR
        bWatchSubtree: i32,  // BOOL
        dwNotifyFilter: u32  // FILE_NOTIFY_CHANGE
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern IntPtr FindFirstChangeNotificationA([MarshalAs(UnmanagedType.LPStr)] string lpPathName, bool bWatchSubtree, uint dwNotifyFilter);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FindFirstChangeNotificationA' -Namespace Win32 -PassThru
# $api::FindFirstChangeNotificationA(lpPathName, bWatchSubtree, dwNotifyFilter)
#uselib "KERNEL32.dll"
#func global FindFirstChangeNotificationA "FindFirstChangeNotificationA" sptr, sptr, sptr
; FindFirstChangeNotificationA lpPathName, bWatchSubtree, dwNotifyFilter   ; 戻り値は stat
; lpPathName : LPCSTR -> "sptr"
; bWatchSubtree : BOOL -> "sptr"
; dwNotifyFilter : FILE_NOTIFY_CHANGE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global FindFirstChangeNotificationA "FindFirstChangeNotificationA" str, int, int
; res = FindFirstChangeNotificationA(lpPathName, bWatchSubtree, dwNotifyFilter)
; lpPathName : LPCSTR -> "str"
; bWatchSubtree : BOOL -> "int"
; dwNotifyFilter : FILE_NOTIFY_CHANGE -> "int"
; HANDLE FindFirstChangeNotificationA(LPCSTR lpPathName, BOOL bWatchSubtree, FILE_NOTIFY_CHANGE dwNotifyFilter)
#uselib "KERNEL32.dll"
#cfunc global FindFirstChangeNotificationA "FindFirstChangeNotificationA" str, int, int
; res = FindFirstChangeNotificationA(lpPathName, bWatchSubtree, dwNotifyFilter)
; lpPathName : LPCSTR -> "str"
; bWatchSubtree : BOOL -> "int"
; dwNotifyFilter : FILE_NOTIFY_CHANGE -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procFindFirstChangeNotificationA = kernel32.NewProc("FindFirstChangeNotificationA")
)

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