ホーム › UI.Accessibility › SetWinEventHook
SetWinEventHook
関数指定範囲のWinEventを受け取るフックを設定する。
シグネチャ
// USER32.dll
#include <windows.h>
HWINEVENTHOOK SetWinEventHook(
DWORD eventMin,
DWORD eventMax,
HMODULE hmodWinEventProc, // optional
WINEVENTPROC pfnWinEventProc,
DWORD idProcess,
DWORD idThread,
DWORD dwFlags
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| eventMin | DWORD | in | フックする最小のイベント定数。監視範囲の下限を示す。 |
| eventMax | DWORD | in | フックする最大のイベント定数。監視範囲の上限を示す。 |
| hmodWinEventProc | HMODULE | inoptional | コールバック関数を含むDLLのモジュールハンドル。インプロセス時に指定、それ以外はNULL。 |
| pfnWinEventProc | WINEVENTPROC | in | イベント発生時に呼び出されるWINEVENTPROCコールバック関数へのポインター。 |
| idProcess | DWORD | in | 監視対象のプロセスID。全プロセス監視は0を指定する。 |
| idThread | DWORD | in | 監視対象のスレッドID。全スレッド監視は0を指定する。 |
| dwFlags | DWORD | in | フックの動作を制御するフラグ(WINEVENT_INCONTEXT・WINEVENT_OUTOFCONTEXT等)。 |
戻り値の型: HWINEVENTHOOK
各言語での呼び出し定義
// USER32.dll
#include <windows.h>
HWINEVENTHOOK SetWinEventHook(
DWORD eventMin,
DWORD eventMax,
HMODULE hmodWinEventProc, // optional
WINEVENTPROC pfnWinEventProc,
DWORD idProcess,
DWORD idThread,
DWORD dwFlags
);[DllImport("USER32.dll", ExactSpelling = true)]
static extern IntPtr SetWinEventHook(
uint eventMin, // DWORD
uint eventMax, // DWORD
IntPtr hmodWinEventProc, // HMODULE optional
IntPtr pfnWinEventProc, // WINEVENTPROC
uint idProcess, // DWORD
uint idThread, // DWORD
uint dwFlags // DWORD
);<DllImport("USER32.dll", ExactSpelling:=True)>
Public Shared Function SetWinEventHook(
eventMin As UInteger, ' DWORD
eventMax As UInteger, ' DWORD
hmodWinEventProc As IntPtr, ' HMODULE optional
pfnWinEventProc As IntPtr, ' WINEVENTPROC
idProcess As UInteger, ' DWORD
idThread As UInteger, ' DWORD
dwFlags As UInteger ' DWORD
) As IntPtr
End Function' eventMin : DWORD
' eventMax : DWORD
' hmodWinEventProc : HMODULE optional
' pfnWinEventProc : WINEVENTPROC
' idProcess : DWORD
' idThread : DWORD
' dwFlags : DWORD
Declare PtrSafe Function SetWinEventHook Lib "user32" ( _
ByVal eventMin As Long, _
ByVal eventMax As Long, _
ByVal hmodWinEventProc As LongPtr, _
ByVal pfnWinEventProc As LongPtr, _
ByVal idProcess As Long, _
ByVal idThread As Long, _
ByVal dwFlags As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetWinEventHook = ctypes.windll.user32.SetWinEventHook
SetWinEventHook.restype = ctypes.c_void_p
SetWinEventHook.argtypes = [
wintypes.DWORD, # eventMin : DWORD
wintypes.DWORD, # eventMax : DWORD
wintypes.HANDLE, # hmodWinEventProc : HMODULE optional
ctypes.c_void_p, # pfnWinEventProc : WINEVENTPROC
wintypes.DWORD, # idProcess : DWORD
wintypes.DWORD, # idThread : DWORD
wintypes.DWORD, # dwFlags : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('USER32.dll')
SetWinEventHook = Fiddle::Function.new(
lib['SetWinEventHook'],
[
-Fiddle::TYPE_INT, # eventMin : DWORD
-Fiddle::TYPE_INT, # eventMax : DWORD
Fiddle::TYPE_VOIDP, # hmodWinEventProc : HMODULE optional
Fiddle::TYPE_VOIDP, # pfnWinEventProc : WINEVENTPROC
-Fiddle::TYPE_INT, # idProcess : DWORD
-Fiddle::TYPE_INT, # idThread : DWORD
-Fiddle::TYPE_INT, # dwFlags : DWORD
],
Fiddle::TYPE_VOIDP)#[link(name = "user32")]
extern "system" {
fn SetWinEventHook(
eventMin: u32, // DWORD
eventMax: u32, // DWORD
hmodWinEventProc: *mut core::ffi::c_void, // HMODULE optional
pfnWinEventProc: *const core::ffi::c_void, // WINEVENTPROC
idProcess: u32, // DWORD
idThread: u32, // DWORD
dwFlags: u32 // DWORD
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("USER32.dll")]
public static extern IntPtr SetWinEventHook(uint eventMin, uint eventMax, IntPtr hmodWinEventProc, IntPtr pfnWinEventProc, uint idProcess, uint idThread, uint dwFlags);
"@
$api = Add-Type -MemberDefinition $sig -Name 'USER32_SetWinEventHook' -Namespace Win32 -PassThru
# $api::SetWinEventHook(eventMin, eventMax, hmodWinEventProc, pfnWinEventProc, idProcess, idThread, dwFlags)#uselib "USER32.dll"
#func global SetWinEventHook "SetWinEventHook" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetWinEventHook eventMin, eventMax, hmodWinEventProc, pfnWinEventProc, idProcess, idThread, dwFlags ; 戻り値は stat
; eventMin : DWORD -> "sptr"
; eventMax : DWORD -> "sptr"
; hmodWinEventProc : HMODULE optional -> "sptr"
; pfnWinEventProc : WINEVENTPROC -> "sptr"
; idProcess : DWORD -> "sptr"
; idThread : DWORD -> "sptr"
; dwFlags : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "USER32.dll"
#cfunc global SetWinEventHook "SetWinEventHook" int, int, sptr, sptr, int, int, int
; res = SetWinEventHook(eventMin, eventMax, hmodWinEventProc, pfnWinEventProc, idProcess, idThread, dwFlags)
; eventMin : DWORD -> "int"
; eventMax : DWORD -> "int"
; hmodWinEventProc : HMODULE optional -> "sptr"
; pfnWinEventProc : WINEVENTPROC -> "sptr"
; idProcess : DWORD -> "int"
; idThread : DWORD -> "int"
; dwFlags : DWORD -> "int"; HWINEVENTHOOK SetWinEventHook(DWORD eventMin, DWORD eventMax, HMODULE hmodWinEventProc, WINEVENTPROC pfnWinEventProc, DWORD idProcess, DWORD idThread, DWORD dwFlags)
#uselib "USER32.dll"
#cfunc global SetWinEventHook "SetWinEventHook" int, int, intptr, intptr, int, int, int
; res = SetWinEventHook(eventMin, eventMax, hmodWinEventProc, pfnWinEventProc, idProcess, idThread, dwFlags)
; eventMin : DWORD -> "int"
; eventMax : DWORD -> "int"
; hmodWinEventProc : HMODULE optional -> "intptr"
; pfnWinEventProc : WINEVENTPROC -> "intptr"
; idProcess : DWORD -> "int"
; idThread : DWORD -> "int"
; dwFlags : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
user32 = windows.NewLazySystemDLL("USER32.dll")
procSetWinEventHook = user32.NewProc("SetWinEventHook")
)
// eventMin (DWORD), eventMax (DWORD), hmodWinEventProc (HMODULE optional), pfnWinEventProc (WINEVENTPROC), idProcess (DWORD), idThread (DWORD), dwFlags (DWORD)
r1, _, err := procSetWinEventHook.Call(
uintptr(eventMin),
uintptr(eventMax),
uintptr(hmodWinEventProc),
uintptr(pfnWinEventProc),
uintptr(idProcess),
uintptr(idThread),
uintptr(dwFlags),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HWINEVENTHOOKfunction SetWinEventHook(
eventMin: DWORD; // DWORD
eventMax: DWORD; // DWORD
hmodWinEventProc: THandle; // HMODULE optional
pfnWinEventProc: Pointer; // WINEVENTPROC
idProcess: DWORD; // DWORD
idThread: DWORD; // DWORD
dwFlags: DWORD // DWORD
): THandle; stdcall;
external 'USER32.dll' name 'SetWinEventHook';result := DllCall("USER32\SetWinEventHook"
, "UInt", eventMin ; DWORD
, "UInt", eventMax ; DWORD
, "Ptr", hmodWinEventProc ; HMODULE optional
, "Ptr", pfnWinEventProc ; WINEVENTPROC
, "UInt", idProcess ; DWORD
, "UInt", idThread ; DWORD
, "UInt", dwFlags ; DWORD
, "Ptr") ; return: HWINEVENTHOOK●SetWinEventHook(eventMin, eventMax, hmodWinEventProc, pfnWinEventProc, idProcess, idThread, dwFlags) = DLL("USER32.dll", "void* SetWinEventHook(dword, dword, void*, void*, dword, dword, dword)")
# 呼び出し: SetWinEventHook(eventMin, eventMax, hmodWinEventProc, pfnWinEventProc, idProcess, idThread, dwFlags)
# eventMin : DWORD -> "dword"
# eventMax : DWORD -> "dword"
# hmodWinEventProc : HMODULE optional -> "void*"
# pfnWinEventProc : WINEVENTPROC -> "void*"
# idProcess : DWORD -> "dword"
# idThread : DWORD -> "dword"
# dwFlags : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。