SHChangeNotifyRegister
関数シグネチャ
// SHELL32.dll
#include <windows.h>
DWORD SHChangeNotifyRegister(
HWND hwnd,
SHCNRF_SOURCE fSources,
INT fEvents,
DWORD wMsg,
INT cEntries,
const SHChangeNotifyEntry* pshcne
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hwnd | HWND | in | 変更通知メッセージを受け取るウィンドウのハンドル。 |
| fSources | SHCNRF_SOURCE | in | 通知を受け取るイベントの種類を示す、次の値のうち 1 つ以上。 注意 以前のバージョンの SDK では、これらのフラグはヘッダーファイルで定義されておらず、実装者がこれらの値を自分で定義するか、数値を直接使用する必要がありました。Windows Vista 以降では、これらのフラグは Shlobj.h で定義されています。
SHCNRF_InterruptLevel (0x0001)ファイルシステムからの割り込みレベルの通知。 SHCNRF_ShellLevel (0x0002)シェルからのシェルレベルの通知。 SHCNRF_RecursiveInterrupt (0x1000)サブツリー全体に対する割り込みイベント。このフラグは SHCNRF_InterruptLevel フラグと組み合わせて使用する必要があります。このフラグを使用する場合、pshcne が参照する対応する SHChangeNotifyEntry 構造体の fRecursive メンバーを TRUE に設定して、通知も再帰的にする必要があります。単一レベルのビュー(たとえば、相対的で 1 つの SHITEMID のみを含む PIDL)で SHCNRF_RecursiveInterrupt を使用すると、最上位レベルでのイベント通知がブロックされ、再帰的な子の更新が妨げられます。そのため、フォルダー階層の最下位レベルにドラッグされたアイコンが、期待どおりにビューに表示されない場合があります。 SHCNRF_NewDelivery (0x8000)受信するメッセージは共有メモリを使用します。実際のデータにアクセスするには SHChangeNotification_Lock を呼び出します。処理が完了したらメモリを解放するために SHChangeNotification_Unlock を呼び出します。 注意 このフラグは、より堅牢な配信方法を提供するため推奨されます。すべてのクライアントでこのフラグを指定する必要があります。
|
| fEvents | INT | in | 通知を受け取る変更通知イベント。指定可能な値については、SHChangeNotify に記載されている SHCNE フラグを参照してください。 |
| wMsg | DWORD | in | ウィンドウプロシージャにポストされるメッセージ。 |
| cEntries | INT | in | pshcne 配列内のエントリ数。 |
| pshcne | SHChangeNotifyEntry* | in | 通知を含む SHChangeNotifyEntry 構造体の配列。SHChangeNotifyRegister を呼び出す際は、この配列を常に 1 に設定する必要があります。そうしないと SHChangeNotifyDeregister が正しく機能しません。 |
戻り値の型: DWORD
公式ドキュメント
ファイルシステムまたはシェルから通知を受け取るためにウィンドウを登録します。ただし、ファイルシステムが通知をサポートしている場合に限ります。
戻り値
型: ULONG
正の整数の登録 ID を返します。メモリ不足の場合、または無効なパラメーターに応答する場合は 0 を返します。
解説(Remarks)
この関数の使用方法を示す完全な例については、Windows ソフトウェア開発キット (SDK) の Change Notify Watcher Sample を参照してください。
変更通知イベントが発生すると、wMsg で示されるメッセージが hwnd パラメーターで指定されたウィンドウに配信されます。
- SHCNRF_NewDelivery が指定されている場合、メッセージ内の wParam および lParam の値は、それぞれ hChange および dwProcID パラメーターとして SHChangeNotification_Lock に渡す必要があります。
- SHCNRF_NewDelivery が指定されていない場合、wParam は 2 つの PIDLIST_ABSOLUTE ポインターへのポインターであり、lParam はイベントを指定します。送信されるイベントによっては、2 つの PIDLIST_ABSOLUTE ポインターが NULL になる場合があります。
パフォーマンス上の理由から、複数の通知を 1 つの通知にまとめることができます。たとえば、同じフォルダー内のファイルに対して多数の SHCNE_UPDATEITEM 通知が生成された場合、それらを 1 つの SHCNE_UPDATEDIR 通知に結合できます。
Windows Vista 以降は利用できなくなった NTSHChangeNotifyRegister 関数は、SHCNRF_NewDelivery フラグを指定した SHChangeNotifyRegister と同等でした。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// SHELL32.dll
#include <windows.h>
DWORD SHChangeNotifyRegister(
HWND hwnd,
SHCNRF_SOURCE fSources,
INT fEvents,
DWORD wMsg,
INT cEntries,
const SHChangeNotifyEntry* pshcne
);[DllImport("SHELL32.dll", ExactSpelling = true)]
static extern uint SHChangeNotifyRegister(
IntPtr hwnd, // HWND
int fSources, // SHCNRF_SOURCE
int fEvents, // INT
uint wMsg, // DWORD
int cEntries, // INT
IntPtr pshcne // SHChangeNotifyEntry*
);<DllImport("SHELL32.dll", ExactSpelling:=True)>
Public Shared Function SHChangeNotifyRegister(
hwnd As IntPtr, ' HWND
fSources As Integer, ' SHCNRF_SOURCE
fEvents As Integer, ' INT
wMsg As UInteger, ' DWORD
cEntries As Integer, ' INT
pshcne As IntPtr ' SHChangeNotifyEntry*
) As UInteger
End Function' hwnd : HWND
' fSources : SHCNRF_SOURCE
' fEvents : INT
' wMsg : DWORD
' cEntries : INT
' pshcne : SHChangeNotifyEntry*
Declare PtrSafe Function SHChangeNotifyRegister Lib "shell32" ( _
ByVal hwnd As LongPtr, _
ByVal fSources As Long, _
ByVal fEvents As Long, _
ByVal wMsg As Long, _
ByVal cEntries As Long, _
ByVal pshcne As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SHChangeNotifyRegister = ctypes.windll.shell32.SHChangeNotifyRegister
SHChangeNotifyRegister.restype = wintypes.DWORD
SHChangeNotifyRegister.argtypes = [
wintypes.HANDLE, # hwnd : HWND
ctypes.c_int, # fSources : SHCNRF_SOURCE
ctypes.c_int, # fEvents : INT
wintypes.DWORD, # wMsg : DWORD
ctypes.c_int, # cEntries : INT
ctypes.c_void_p, # pshcne : SHChangeNotifyEntry*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('SHELL32.dll')
SHChangeNotifyRegister = Fiddle::Function.new(
lib['SHChangeNotifyRegister'],
[
Fiddle::TYPE_VOIDP, # hwnd : HWND
Fiddle::TYPE_INT, # fSources : SHCNRF_SOURCE
Fiddle::TYPE_INT, # fEvents : INT
-Fiddle::TYPE_INT, # wMsg : DWORD
Fiddle::TYPE_INT, # cEntries : INT
Fiddle::TYPE_VOIDP, # pshcne : SHChangeNotifyEntry*
],
-Fiddle::TYPE_INT)#[link(name = "shell32")]
extern "system" {
fn SHChangeNotifyRegister(
hwnd: *mut core::ffi::c_void, // HWND
fSources: i32, // SHCNRF_SOURCE
fEvents: i32, // INT
wMsg: u32, // DWORD
cEntries: i32, // INT
pshcne: *const SHChangeNotifyEntry // SHChangeNotifyEntry*
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("SHELL32.dll")]
public static extern uint SHChangeNotifyRegister(IntPtr hwnd, int fSources, int fEvents, uint wMsg, int cEntries, IntPtr pshcne);
"@
$api = Add-Type -MemberDefinition $sig -Name 'SHELL32_SHChangeNotifyRegister' -Namespace Win32 -PassThru
# $api::SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, pshcne)#uselib "SHELL32.dll"
#func global SHChangeNotifyRegister "SHChangeNotifyRegister" sptr, sptr, sptr, sptr, sptr, sptr
; SHChangeNotifyRegister hwnd, fSources, fEvents, wMsg, cEntries, varptr(pshcne) ; 戻り値は stat
; hwnd : HWND -> "sptr"
; fSources : SHCNRF_SOURCE -> "sptr"
; fEvents : INT -> "sptr"
; wMsg : DWORD -> "sptr"
; cEntries : INT -> "sptr"
; pshcne : SHChangeNotifyEntry* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "SHELL32.dll" #cfunc global SHChangeNotifyRegister "SHChangeNotifyRegister" sptr, int, int, int, int, var ; res = SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, pshcne) ; hwnd : HWND -> "sptr" ; fSources : SHCNRF_SOURCE -> "int" ; fEvents : INT -> "int" ; wMsg : DWORD -> "int" ; cEntries : INT -> "int" ; pshcne : SHChangeNotifyEntry* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "SHELL32.dll" #cfunc global SHChangeNotifyRegister "SHChangeNotifyRegister" sptr, int, int, int, int, sptr ; res = SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, varptr(pshcne)) ; hwnd : HWND -> "sptr" ; fSources : SHCNRF_SOURCE -> "int" ; fEvents : INT -> "int" ; wMsg : DWORD -> "int" ; cEntries : INT -> "int" ; pshcne : SHChangeNotifyEntry* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; DWORD SHChangeNotifyRegister(HWND hwnd, SHCNRF_SOURCE fSources, INT fEvents, DWORD wMsg, INT cEntries, SHChangeNotifyEntry* pshcne) #uselib "SHELL32.dll" #cfunc global SHChangeNotifyRegister "SHChangeNotifyRegister" intptr, int, int, int, int, var ; res = SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, pshcne) ; hwnd : HWND -> "intptr" ; fSources : SHCNRF_SOURCE -> "int" ; fEvents : INT -> "int" ; wMsg : DWORD -> "int" ; cEntries : INT -> "int" ; pshcne : SHChangeNotifyEntry* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD SHChangeNotifyRegister(HWND hwnd, SHCNRF_SOURCE fSources, INT fEvents, DWORD wMsg, INT cEntries, SHChangeNotifyEntry* pshcne) #uselib "SHELL32.dll" #cfunc global SHChangeNotifyRegister "SHChangeNotifyRegister" intptr, int, int, int, int, intptr ; res = SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, varptr(pshcne)) ; hwnd : HWND -> "intptr" ; fSources : SHCNRF_SOURCE -> "int" ; fEvents : INT -> "int" ; wMsg : DWORD -> "int" ; cEntries : INT -> "int" ; pshcne : SHChangeNotifyEntry* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
shell32 = windows.NewLazySystemDLL("SHELL32.dll")
procSHChangeNotifyRegister = shell32.NewProc("SHChangeNotifyRegister")
)
// hwnd (HWND), fSources (SHCNRF_SOURCE), fEvents (INT), wMsg (DWORD), cEntries (INT), pshcne (SHChangeNotifyEntry*)
r1, _, err := procSHChangeNotifyRegister.Call(
uintptr(hwnd),
uintptr(fSources),
uintptr(fEvents),
uintptr(wMsg),
uintptr(cEntries),
uintptr(pshcne),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction SHChangeNotifyRegister(
hwnd: THandle; // HWND
fSources: Integer; // SHCNRF_SOURCE
fEvents: Integer; // INT
wMsg: DWORD; // DWORD
cEntries: Integer; // INT
pshcne: Pointer // SHChangeNotifyEntry*
): DWORD; stdcall;
external 'SHELL32.dll' name 'SHChangeNotifyRegister';result := DllCall("SHELL32\SHChangeNotifyRegister"
, "Ptr", hwnd ; HWND
, "Int", fSources ; SHCNRF_SOURCE
, "Int", fEvents ; INT
, "UInt", wMsg ; DWORD
, "Int", cEntries ; INT
, "Ptr", pshcne ; SHChangeNotifyEntry*
, "UInt") ; return: DWORD●SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, pshcne) = DLL("SHELL32.dll", "dword SHChangeNotifyRegister(void*, int, int, dword, int, void*)")
# 呼び出し: SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, pshcne)
# hwnd : HWND -> "void*"
# fSources : SHCNRF_SOURCE -> "int"
# fEvents : INT -> "int"
# wMsg : DWORD -> "dword"
# cEntries : INT -> "int"
# pshcne : SHChangeNotifyEntry* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "shell32" fn SHChangeNotifyRegister(
hwnd: ?*anyopaque, // HWND
fSources: i32, // SHCNRF_SOURCE
fEvents: i32, // INT
wMsg: u32, // DWORD
cEntries: i32, // INT
pshcne: [*c]SHChangeNotifyEntry // SHChangeNotifyEntry*
) callconv(std.os.windows.WINAPI) u32;proc SHChangeNotifyRegister(
hwnd: pointer, # HWND
fSources: int32, # SHCNRF_SOURCE
fEvents: int32, # INT
wMsg: uint32, # DWORD
cEntries: int32, # INT
pshcne: ptr SHChangeNotifyEntry # SHChangeNotifyEntry*
): uint32 {.importc: "SHChangeNotifyRegister", stdcall, dynlib: "SHELL32.dll".}pragma(lib, "shell32");
extern(Windows)
uint SHChangeNotifyRegister(
void* hwnd, // HWND
int fSources, // SHCNRF_SOURCE
int fEvents, // INT
uint wMsg, // DWORD
int cEntries, // INT
SHChangeNotifyEntry* pshcne // SHChangeNotifyEntry*
);ccall((:SHChangeNotifyRegister, "SHELL32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Int32, Int32, UInt32, Int32, Ptr{SHChangeNotifyEntry}),
hwnd, fSources, fEvents, wMsg, cEntries, pshcne)
# hwnd : HWND -> Ptr{Cvoid}
# fSources : SHCNRF_SOURCE -> Int32
# fEvents : INT -> Int32
# wMsg : DWORD -> UInt32
# cEntries : INT -> Int32
# pshcne : SHChangeNotifyEntry* -> Ptr{SHChangeNotifyEntry}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t SHChangeNotifyRegister(
void* hwnd,
int32_t fSources,
int32_t fEvents,
uint32_t wMsg,
int32_t cEntries,
void* pshcne);
]]
local shell32 = ffi.load("shell32")
-- shell32.SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, pshcne)
-- hwnd : HWND
-- fSources : SHCNRF_SOURCE
-- fEvents : INT
-- wMsg : DWORD
-- cEntries : INT
-- pshcne : SHChangeNotifyEntry*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('SHELL32.dll');
const SHChangeNotifyRegister = lib.func('__stdcall', 'SHChangeNotifyRegister', 'uint32_t', ['void *', 'int32_t', 'int32_t', 'uint32_t', 'int32_t', 'void *']);
// SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, pshcne)
// hwnd : HWND -> 'void *'
// fSources : SHCNRF_SOURCE -> 'int32_t'
// fEvents : INT -> 'int32_t'
// wMsg : DWORD -> 'uint32_t'
// cEntries : INT -> 'int32_t'
// pshcne : SHChangeNotifyEntry* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("SHELL32.dll", {
SHChangeNotifyRegister: { parameters: ["pointer", "i32", "i32", "u32", "i32", "pointer"], result: "u32" },
});
// lib.symbols.SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, pshcne)
// hwnd : HWND -> "pointer"
// fSources : SHCNRF_SOURCE -> "i32"
// fEvents : INT -> "i32"
// wMsg : DWORD -> "u32"
// cEntries : INT -> "i32"
// pshcne : SHChangeNotifyEntry* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t SHChangeNotifyRegister(
void* hwnd,
int32_t fSources,
int32_t fEvents,
uint32_t wMsg,
int32_t cEntries,
void* pshcne);
C, "SHELL32.dll");
// $ffi->SHChangeNotifyRegister(hwnd, fSources, fEvents, wMsg, cEntries, pshcne);
// hwnd : HWND
// fSources : SHCNRF_SOURCE
// fEvents : INT
// wMsg : DWORD
// cEntries : INT
// pshcne : SHChangeNotifyEntry*
// 構造体/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 Shell32 extends StdCallLibrary {
Shell32 INSTANCE = Native.load("shell32", Shell32.class);
int SHChangeNotifyRegister(
Pointer hwnd, // HWND
int fSources, // SHCNRF_SOURCE
int fEvents, // INT
int wMsg, // DWORD
int cEntries, // INT
Pointer pshcne // SHChangeNotifyEntry*
);
}@[Link("shell32")]
lib LibSHELL32
fun SHChangeNotifyRegister = SHChangeNotifyRegister(
hwnd : Void*, # HWND
fSources : Int32, # SHCNRF_SOURCE
fEvents : Int32, # INT
wMsg : UInt32, # DWORD
cEntries : Int32, # INT
pshcne : SHChangeNotifyEntry* # SHChangeNotifyEntry*
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SHChangeNotifyRegisterNative = Uint32 Function(Pointer<Void>, Int32, Int32, Uint32, Int32, Pointer<Void>);
typedef SHChangeNotifyRegisterDart = int Function(Pointer<Void>, int, int, int, int, Pointer<Void>);
final SHChangeNotifyRegister = DynamicLibrary.open('SHELL32.dll')
.lookupFunction<SHChangeNotifyRegisterNative, SHChangeNotifyRegisterDart>('SHChangeNotifyRegister');
// hwnd : HWND -> Pointer<Void>
// fSources : SHCNRF_SOURCE -> Int32
// fEvents : INT -> Int32
// wMsg : DWORD -> Uint32
// cEntries : INT -> Int32
// pshcne : SHChangeNotifyEntry* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SHChangeNotifyRegister(
hwnd: THandle; // HWND
fSources: Integer; // SHCNRF_SOURCE
fEvents: Integer; // INT
wMsg: DWORD; // DWORD
cEntries: Integer; // INT
pshcne: Pointer // SHChangeNotifyEntry*
): DWORD; stdcall;
external 'SHELL32.dll' name 'SHChangeNotifyRegister';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SHChangeNotifyRegister"
c_SHChangeNotifyRegister :: Ptr () -> Int32 -> Int32 -> Word32 -> Int32 -> Ptr () -> IO Word32
-- hwnd : HWND -> Ptr ()
-- fSources : SHCNRF_SOURCE -> Int32
-- fEvents : INT -> Int32
-- wMsg : DWORD -> Word32
-- cEntries : INT -> Int32
-- pshcne : SHChangeNotifyEntry* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let shchangenotifyregister =
foreign "SHChangeNotifyRegister"
((ptr void) @-> int32_t @-> int32_t @-> uint32_t @-> int32_t @-> (ptr void) @-> returning uint32_t)
(* hwnd : HWND -> (ptr void) *)
(* fSources : SHCNRF_SOURCE -> int32_t *)
(* fEvents : INT -> int32_t *)
(* wMsg : DWORD -> uint32_t *)
(* cEntries : INT -> int32_t *)
(* pshcne : SHChangeNotifyEntry* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library shell32 (t "SHELL32.dll"))
(cffi:use-foreign-library shell32)
(cffi:defcfun ("SHChangeNotifyRegister" shchange-notify-register :convention :stdcall) :uint32
(hwnd :pointer) ; HWND
(f-sources :int32) ; SHCNRF_SOURCE
(f-events :int32) ; INT
(w-msg :uint32) ; DWORD
(c-entries :int32) ; INT
(pshcne :pointer)) ; SHChangeNotifyEntry*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SHChangeNotifyRegister = Win32::API::More->new('SHELL32',
'DWORD SHChangeNotifyRegister(HANDLE hwnd, int fSources, int fEvents, DWORD wMsg, int cEntries, LPVOID pshcne)');
# my $ret = $SHChangeNotifyRegister->Call($hwnd, $fSources, $fEvents, $wMsg, $cEntries, $pshcne);
# hwnd : HWND -> HANDLE
# fSources : SHCNRF_SOURCE -> int
# fEvents : INT -> int
# wMsg : DWORD -> DWORD
# cEntries : INT -> int
# pshcne : SHChangeNotifyEntry* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。