ホーム › Storage.FileSystem › FindFirstChangeNotificationW
FindFirstChangeNotificationW
関数ディレクトリの変更監視を開始し通知ハンドルを返す。
シグネチャ
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
HANDLE FindFirstChangeNotificationW(
LPCWSTR lpPathName,
BOOL bWatchSubtree,
FILE_NOTIFY_CHANGE dwNotifyFilter
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| lpPathName | LPCWSTR | in |
| bWatchSubtree | BOOL | in |
| dwNotifyFilter | FILE_NOTIFY_CHANGE | in |
戻り値の型: HANDLE
各言語での呼び出し定義
// KERNEL32.dll (Unicode / -W)
#include <windows.h>
HANDLE FindFirstChangeNotificationW(
LPCWSTR lpPathName,
BOOL bWatchSubtree,
FILE_NOTIFY_CHANGE dwNotifyFilter
);[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr FindFirstChangeNotificationW(
[MarshalAs(UnmanagedType.LPWStr)] string lpPathName, // LPCWSTR
bool bWatchSubtree, // BOOL
uint dwNotifyFilter // FILE_NOTIFY_CHANGE
);<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function FindFirstChangeNotificationW(
<MarshalAs(UnmanagedType.LPWStr)> lpPathName As String, ' LPCWSTR
bWatchSubtree As Boolean, ' BOOL
dwNotifyFilter As UInteger ' FILE_NOTIFY_CHANGE
) As IntPtr
End Function' lpPathName : LPCWSTR
' bWatchSubtree : BOOL
' dwNotifyFilter : FILE_NOTIFY_CHANGE
Declare PtrSafe Function FindFirstChangeNotificationW Lib "kernel32" ( _
ByVal lpPathName As LongPtr, _
ByVal bWatchSubtree As Long, _
ByVal dwNotifyFilter As Long) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
FindFirstChangeNotificationW = ctypes.windll.kernel32.FindFirstChangeNotificationW
FindFirstChangeNotificationW.restype = ctypes.c_void_p
FindFirstChangeNotificationW.argtypes = [
wintypes.LPCWSTR, # lpPathName : LPCWSTR
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')
FindFirstChangeNotificationW = Fiddle::Function.new(
lib['FindFirstChangeNotificationW'],
[
Fiddle::TYPE_VOIDP, # lpPathName : LPCWSTR
Fiddle::TYPE_INT, # bWatchSubtree : BOOL
-Fiddle::TYPE_INT, # dwNotifyFilter : FILE_NOTIFY_CHANGE
],
Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "kernel32")]
extern "system" {
fn FindFirstChangeNotificationW(
lpPathName: *const u16, // LPCWSTR
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.Unicode, SetLastError = true)]
public static extern IntPtr FindFirstChangeNotificationW([MarshalAs(UnmanagedType.LPWStr)] string lpPathName, bool bWatchSubtree, uint dwNotifyFilter);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_FindFirstChangeNotificationW' -Namespace Win32 -PassThru
# $api::FindFirstChangeNotificationW(lpPathName, bWatchSubtree, dwNotifyFilter)#uselib "KERNEL32.dll"
#func global FindFirstChangeNotificationW "FindFirstChangeNotificationW" wptr, wptr, wptr
; FindFirstChangeNotificationW lpPathName, bWatchSubtree, dwNotifyFilter ; 戻り値は stat
; lpPathName : LPCWSTR -> "wptr"
; bWatchSubtree : BOOL -> "wptr"
; dwNotifyFilter : FILE_NOTIFY_CHANGE -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global FindFirstChangeNotificationW "FindFirstChangeNotificationW" wstr, int, int
; res = FindFirstChangeNotificationW(lpPathName, bWatchSubtree, dwNotifyFilter)
; lpPathName : LPCWSTR -> "wstr"
; bWatchSubtree : BOOL -> "int"
; dwNotifyFilter : FILE_NOTIFY_CHANGE -> "int"; HANDLE FindFirstChangeNotificationW(LPCWSTR lpPathName, BOOL bWatchSubtree, FILE_NOTIFY_CHANGE dwNotifyFilter)
#uselib "KERNEL32.dll"
#cfunc global FindFirstChangeNotificationW "FindFirstChangeNotificationW" wstr, int, int
; res = FindFirstChangeNotificationW(lpPathName, bWatchSubtree, dwNotifyFilter)
; lpPathName : LPCWSTR -> "wstr"
; bWatchSubtree : BOOL -> "int"
; dwNotifyFilter : FILE_NOTIFY_CHANGE -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procFindFirstChangeNotificationW = kernel32.NewProc("FindFirstChangeNotificationW")
)
// lpPathName (LPCWSTR), bWatchSubtree (BOOL), dwNotifyFilter (FILE_NOTIFY_CHANGE)
r1, _, err := procFindFirstChangeNotificationW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpPathName))),
uintptr(bWatchSubtree),
uintptr(dwNotifyFilter),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction FindFirstChangeNotificationW(
lpPathName: PWideChar; // LPCWSTR
bWatchSubtree: BOOL; // BOOL
dwNotifyFilter: DWORD // FILE_NOTIFY_CHANGE
): THandle; stdcall;
external 'KERNEL32.dll' name 'FindFirstChangeNotificationW';result := DllCall("KERNEL32\FindFirstChangeNotificationW"
, "WStr", lpPathName ; LPCWSTR
, "Int", bWatchSubtree ; BOOL
, "UInt", dwNotifyFilter ; FILE_NOTIFY_CHANGE
, "Ptr") ; return: HANDLE●FindFirstChangeNotificationW(lpPathName, bWatchSubtree, dwNotifyFilter) = DLL("KERNEL32.dll", "void* FindFirstChangeNotificationW(char*, bool, dword)")
# 呼び出し: FindFirstChangeNotificationW(lpPathName, bWatchSubtree, dwNotifyFilter)
# lpPathName : LPCWSTR -> "char*"
# bWatchSubtree : BOOL -> "bool"
# dwNotifyFilter : FILE_NOTIFY_CHANGE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。