Win32 API 日本語リファレンス
ホームUI.Accessibility › UiaAddEvent

UiaAddEvent

関数
UIオートメーションノードにイベントリスナーを登録する。
DLLUIAutomationCore.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

HRESULT UiaAddEvent(
    HUIANODE hnode,
    INT eventId,
    UiaEventCallback* pCallback,
    TreeScope scope,
    INT* pProperties,
    INT cProperties,
    UiaCacheRequest* pRequest,
    HUIAEVENT* phEvent
);

パラメーター

名前方向説明
hnodeHUIANODEinイベント監視を登録する起点ノードのハンドル。
eventIdINTin監視するイベントを識別するイベントID。
pCallbackUiaEventCallback*inoutイベント発生時に呼び出されるコールバック関数へのポインター。
scopeTreeScopein監視範囲(要素・子孫・サブツリーなど)を示すTreeScope値。
pPropertiesINT*inoutプロパティ変更イベント時に監視するプロパティIDの配列。
cPropertiesINTinpProperties配列の要素数。
pRequestUiaCacheRequest*inoutイベント発生時に取得するデータを指定するキャッシュ要求。
phEventHUIAEVENT*inout登録されたイベントを表すHUIAEVENTハンドルを受け取る出力先。

戻り値の型: HRESULT

各言語での呼び出し定義

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

HRESULT UiaAddEvent(
    HUIANODE hnode,
    INT eventId,
    UiaEventCallback* pCallback,
    TreeScope scope,
    INT* pProperties,
    INT cProperties,
    UiaCacheRequest* pRequest,
    HUIAEVENT* phEvent
);
[DllImport("UIAutomationCore.dll", ExactSpelling = true)]
static extern int UiaAddEvent(
    IntPtr hnode,   // HUIANODE
    int eventId,   // INT
    IntPtr pCallback,   // UiaEventCallback* in/out
    int scope,   // TreeScope
    ref int pProperties,   // INT* in/out
    int cProperties,   // INT
    IntPtr pRequest,   // UiaCacheRequest* in/out
    IntPtr phEvent   // HUIAEVENT* in/out
);
<DllImport("UIAutomationCore.dll", ExactSpelling:=True)>
Public Shared Function UiaAddEvent(
    hnode As IntPtr,   ' HUIANODE
    eventId As Integer,   ' INT
    pCallback As IntPtr,   ' UiaEventCallback* in/out
    scope As Integer,   ' TreeScope
    ByRef pProperties As Integer,   ' INT* in/out
    cProperties As Integer,   ' INT
    pRequest As IntPtr,   ' UiaCacheRequest* in/out
    phEvent As IntPtr   ' HUIAEVENT* in/out
) As Integer
End Function
' hnode : HUIANODE
' eventId : INT
' pCallback : UiaEventCallback* in/out
' scope : TreeScope
' pProperties : INT* in/out
' cProperties : INT
' pRequest : UiaCacheRequest* in/out
' phEvent : HUIAEVENT* in/out
Declare PtrSafe Function UiaAddEvent Lib "uiautomationcore" ( _
    ByVal hnode As LongPtr, _
    ByVal eventId As Long, _
    ByVal pCallback As LongPtr, _
    ByVal scope As Long, _
    ByRef pProperties As Long, _
    ByVal cProperties As Long, _
    ByVal pRequest As LongPtr, _
    ByVal phEvent As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

UiaAddEvent = ctypes.windll.uiautomationcore.UiaAddEvent
UiaAddEvent.restype = ctypes.c_int
UiaAddEvent.argtypes = [
    wintypes.HANDLE,  # hnode : HUIANODE
    ctypes.c_int,  # eventId : INT
    ctypes.c_void_p,  # pCallback : UiaEventCallback* in/out
    ctypes.c_int,  # scope : TreeScope
    ctypes.POINTER(ctypes.c_int),  # pProperties : INT* in/out
    ctypes.c_int,  # cProperties : INT
    ctypes.c_void_p,  # pRequest : UiaCacheRequest* in/out
    ctypes.c_void_p,  # phEvent : HUIAEVENT* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('UIAutomationCore.dll')
UiaAddEvent = Fiddle::Function.new(
  lib['UiaAddEvent'],
  [
    Fiddle::TYPE_VOIDP,  # hnode : HUIANODE
    Fiddle::TYPE_INT,  # eventId : INT
    Fiddle::TYPE_VOIDP,  # pCallback : UiaEventCallback* in/out
    Fiddle::TYPE_INT,  # scope : TreeScope
    Fiddle::TYPE_VOIDP,  # pProperties : INT* in/out
    Fiddle::TYPE_INT,  # cProperties : INT
    Fiddle::TYPE_VOIDP,  # pRequest : UiaCacheRequest* in/out
    Fiddle::TYPE_VOIDP,  # phEvent : HUIAEVENT* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "uiautomationcore")]
extern "system" {
    fn UiaAddEvent(
        hnode: *mut core::ffi::c_void,  // HUIANODE
        eventId: i32,  // INT
        pCallback: *mut *const core::ffi::c_void,  // UiaEventCallback* in/out
        scope: i32,  // TreeScope
        pProperties: *mut i32,  // INT* in/out
        cProperties: i32,  // INT
        pRequest: *mut UiaCacheRequest,  // UiaCacheRequest* in/out
        phEvent: *mut *mut core::ffi::c_void  // HUIAEVENT* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("UIAutomationCore.dll")]
public static extern int UiaAddEvent(IntPtr hnode, int eventId, IntPtr pCallback, int scope, ref int pProperties, int cProperties, IntPtr pRequest, IntPtr phEvent);
"@
$api = Add-Type -MemberDefinition $sig -Name 'UIAutomationCore_UiaAddEvent' -Namespace Win32 -PassThru
# $api::UiaAddEvent(hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent)
#uselib "UIAutomationCore.dll"
#func global UiaAddEvent "UiaAddEvent" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; UiaAddEvent hnode, eventId, pCallback, scope, varptr(pProperties), cProperties, varptr(pRequest), phEvent   ; 戻り値は stat
; hnode : HUIANODE -> "sptr"
; eventId : INT -> "sptr"
; pCallback : UiaEventCallback* in/out -> "sptr"
; scope : TreeScope -> "sptr"
; pProperties : INT* in/out -> "sptr"
; cProperties : INT -> "sptr"
; pRequest : UiaCacheRequest* in/out -> "sptr"
; phEvent : HUIAEVENT* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "UIAutomationCore.dll"
#cfunc global UiaAddEvent "UiaAddEvent" sptr, int, sptr, int, var, int, var, sptr
; res = UiaAddEvent(hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent)
; hnode : HUIANODE -> "sptr"
; eventId : INT -> "int"
; pCallback : UiaEventCallback* in/out -> "sptr"
; scope : TreeScope -> "int"
; pProperties : INT* in/out -> "var"
; cProperties : INT -> "int"
; pRequest : UiaCacheRequest* in/out -> "var"
; phEvent : HUIAEVENT* in/out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HRESULT UiaAddEvent(HUIANODE hnode, INT eventId, UiaEventCallback* pCallback, TreeScope scope, INT* pProperties, INT cProperties, UiaCacheRequest* pRequest, HUIAEVENT* phEvent)
#uselib "UIAutomationCore.dll"
#cfunc global UiaAddEvent "UiaAddEvent" intptr, int, intptr, int, var, int, var, intptr
; res = UiaAddEvent(hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent)
; hnode : HUIANODE -> "intptr"
; eventId : INT -> "int"
; pCallback : UiaEventCallback* in/out -> "intptr"
; scope : TreeScope -> "int"
; pProperties : INT* in/out -> "var"
; cProperties : INT -> "int"
; pRequest : UiaCacheRequest* in/out -> "var"
; phEvent : HUIAEVENT* in/out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	uiautomationcore = windows.NewLazySystemDLL("UIAutomationCore.dll")
	procUiaAddEvent = uiautomationcore.NewProc("UiaAddEvent")
)

// hnode (HUIANODE), eventId (INT), pCallback (UiaEventCallback* in/out), scope (TreeScope), pProperties (INT* in/out), cProperties (INT), pRequest (UiaCacheRequest* in/out), phEvent (HUIAEVENT* in/out)
r1, _, err := procUiaAddEvent.Call(
	uintptr(hnode),
	uintptr(eventId),
	uintptr(pCallback),
	uintptr(scope),
	uintptr(pProperties),
	uintptr(cProperties),
	uintptr(pRequest),
	uintptr(phEvent),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function UiaAddEvent(
  hnode: THandle;   // HUIANODE
  eventId: Integer;   // INT
  pCallback: Pointer;   // UiaEventCallback* in/out
  scope: Integer;   // TreeScope
  pProperties: Pointer;   // INT* in/out
  cProperties: Integer;   // INT
  pRequest: Pointer;   // UiaCacheRequest* in/out
  phEvent: Pointer   // HUIAEVENT* in/out
): Integer; stdcall;
  external 'UIAutomationCore.dll' name 'UiaAddEvent';
result := DllCall("UIAutomationCore\UiaAddEvent"
    , "Ptr", hnode   ; HUIANODE
    , "Int", eventId   ; INT
    , "Ptr", pCallback   ; UiaEventCallback* in/out
    , "Int", scope   ; TreeScope
    , "Ptr", pProperties   ; INT* in/out
    , "Int", cProperties   ; INT
    , "Ptr", pRequest   ; UiaCacheRequest* in/out
    , "Ptr", phEvent   ; HUIAEVENT* in/out
    , "Int")   ; return: HRESULT
●UiaAddEvent(hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent) = DLL("UIAutomationCore.dll", "int UiaAddEvent(void*, int, void*, int, void*, int, void*, void*)")
# 呼び出し: UiaAddEvent(hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent)
# hnode : HUIANODE -> "void*"
# eventId : INT -> "int"
# pCallback : UiaEventCallback* in/out -> "void*"
# scope : TreeScope -> "int"
# pProperties : INT* in/out -> "void*"
# cProperties : INT -> "int"
# pRequest : UiaCacheRequest* in/out -> "void*"
# phEvent : HUIAEVENT* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "uiautomationcore" fn UiaAddEvent(
    hnode: ?*anyopaque, // HUIANODE
    eventId: i32, // INT
    pCallback: ?*anyopaque, // UiaEventCallback* in/out
    scope: i32, // TreeScope
    pProperties: [*c]i32, // INT* in/out
    cProperties: i32, // INT
    pRequest: [*c]UiaCacheRequest, // UiaCacheRequest* in/out
    phEvent: ?*anyopaque // HUIAEVENT* in/out
) callconv(std.os.windows.WINAPI) i32;
proc UiaAddEvent(
    hnode: pointer,  # HUIANODE
    eventId: int32,  # INT
    pCallback: pointer,  # UiaEventCallback* in/out
    scope: int32,  # TreeScope
    pProperties: ptr int32,  # INT* in/out
    cProperties: int32,  # INT
    pRequest: ptr UiaCacheRequest,  # UiaCacheRequest* in/out
    phEvent: pointer  # HUIAEVENT* in/out
): int32 {.importc: "UiaAddEvent", stdcall, dynlib: "UIAutomationCore.dll".}
pragma(lib, "uiautomationcore");
extern(Windows)
int UiaAddEvent(
    void* hnode,   // HUIANODE
    int eventId,   // INT
    void* pCallback,   // UiaEventCallback* in/out
    int scope,   // TreeScope
    int* pProperties,   // INT* in/out
    int cProperties,   // INT
    UiaCacheRequest* pRequest,   // UiaCacheRequest* in/out
    void* phEvent   // HUIAEVENT* in/out
);
ccall((:UiaAddEvent, "UIAutomationCore.dll"), stdcall, Int32,
      (Ptr{Cvoid}, Int32, Ptr{Cvoid}, Int32, Ptr{Int32}, Int32, Ptr{UiaCacheRequest}, Ptr{Cvoid}),
      hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent)
# hnode : HUIANODE -> Ptr{Cvoid}
# eventId : INT -> Int32
# pCallback : UiaEventCallback* in/out -> Ptr{Cvoid}
# scope : TreeScope -> Int32
# pProperties : INT* in/out -> Ptr{Int32}
# cProperties : INT -> Int32
# pRequest : UiaCacheRequest* in/out -> Ptr{UiaCacheRequest}
# phEvent : HUIAEVENT* in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t UiaAddEvent(
    void* hnode,
    int32_t eventId,
    void* pCallback,
    int32_t scope,
    int32_t* pProperties,
    int32_t cProperties,
    void* pRequest,
    void* phEvent);
]]
local uiautomationcore = ffi.load("uiautomationcore")
-- uiautomationcore.UiaAddEvent(hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent)
-- hnode : HUIANODE
-- eventId : INT
-- pCallback : UiaEventCallback* in/out
-- scope : TreeScope
-- pProperties : INT* in/out
-- cProperties : INT
-- pRequest : UiaCacheRequest* in/out
-- phEvent : HUIAEVENT* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('UIAutomationCore.dll');
const UiaAddEvent = lib.func('__stdcall', 'UiaAddEvent', 'int32_t', ['void *', 'int32_t', 'void *', 'int32_t', 'int32_t *', 'int32_t', 'void *', 'void *']);
// UiaAddEvent(hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent)
// hnode : HUIANODE -> 'void *'
// eventId : INT -> 'int32_t'
// pCallback : UiaEventCallback* in/out -> 'void *'
// scope : TreeScope -> 'int32_t'
// pProperties : INT* in/out -> 'int32_t *'
// cProperties : INT -> 'int32_t'
// pRequest : UiaCacheRequest* in/out -> 'void *'
// phEvent : HUIAEVENT* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("UIAutomationCore.dll", {
  UiaAddEvent: { parameters: ["pointer", "i32", "pointer", "i32", "pointer", "i32", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.UiaAddEvent(hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent)
// hnode : HUIANODE -> "pointer"
// eventId : INT -> "i32"
// pCallback : UiaEventCallback* in/out -> "pointer"
// scope : TreeScope -> "i32"
// pProperties : INT* in/out -> "pointer"
// cProperties : INT -> "i32"
// pRequest : UiaCacheRequest* in/out -> "pointer"
// phEvent : HUIAEVENT* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t UiaAddEvent(
    void* hnode,
    int32_t eventId,
    void* pCallback,
    int32_t scope,
    int32_t* pProperties,
    int32_t cProperties,
    void* pRequest,
    void* phEvent);
C, "UIAutomationCore.dll");
// $ffi->UiaAddEvent(hnode, eventId, pCallback, scope, pProperties, cProperties, pRequest, phEvent);
// hnode : HUIANODE
// eventId : INT
// pCallback : UiaEventCallback* in/out
// scope : TreeScope
// pProperties : INT* in/out
// cProperties : INT
// pRequest : UiaCacheRequest* in/out
// phEvent : HUIAEVENT* in/out
// 構造体/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 Uiautomationcore extends StdCallLibrary {
    Uiautomationcore INSTANCE = Native.load("uiautomationcore", Uiautomationcore.class);
    int UiaAddEvent(
        Pointer hnode,   // HUIANODE
        int eventId,   // INT
        Callback pCallback,   // UiaEventCallback* in/out
        int scope,   // TreeScope
        IntByReference pProperties,   // INT* in/out
        int cProperties,   // INT
        Pointer pRequest,   // UiaCacheRequest* in/out
        Pointer phEvent   // HUIAEVENT* in/out
    );
}
@[Link("uiautomationcore")]
lib LibUIAutomationCore
  fun UiaAddEvent = UiaAddEvent(
    hnode : Void*,   # HUIANODE
    eventId : Int32,   # INT
    pCallback : Void*,   # UiaEventCallback* in/out
    scope : Int32,   # TreeScope
    pProperties : Int32*,   # INT* in/out
    cProperties : Int32,   # INT
    pRequest : UiaCacheRequest*,   # UiaCacheRequest* in/out
    phEvent : Void*   # HUIAEVENT* in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef UiaAddEventNative = Int32 Function(Pointer<Void>, Int32, Pointer<Void>, Int32, Pointer<Int32>, Int32, Pointer<Void>, Pointer<Void>);
typedef UiaAddEventDart = int Function(Pointer<Void>, int, Pointer<Void>, int, Pointer<Int32>, int, Pointer<Void>, Pointer<Void>);
final UiaAddEvent = DynamicLibrary.open('UIAutomationCore.dll')
    .lookupFunction<UiaAddEventNative, UiaAddEventDart>('UiaAddEvent');
// hnode : HUIANODE -> Pointer<Void>
// eventId : INT -> Int32
// pCallback : UiaEventCallback* in/out -> Pointer<Void>
// scope : TreeScope -> Int32
// pProperties : INT* in/out -> Pointer<Int32>
// cProperties : INT -> Int32
// pRequest : UiaCacheRequest* in/out -> Pointer<Void>
// phEvent : HUIAEVENT* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function UiaAddEvent(
  hnode: THandle;   // HUIANODE
  eventId: Integer;   // INT
  pCallback: Pointer;   // UiaEventCallback* in/out
  scope: Integer;   // TreeScope
  pProperties: Pointer;   // INT* in/out
  cProperties: Integer;   // INT
  pRequest: Pointer;   // UiaCacheRequest* in/out
  phEvent: Pointer   // HUIAEVENT* in/out
): Integer; stdcall;
  external 'UIAutomationCore.dll' name 'UiaAddEvent';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "UiaAddEvent"
  c_UiaAddEvent :: Ptr () -> Int32 -> Ptr () -> Int32 -> Ptr Int32 -> Int32 -> Ptr () -> Ptr () -> IO Int32
-- hnode : HUIANODE -> Ptr ()
-- eventId : INT -> Int32
-- pCallback : UiaEventCallback* in/out -> Ptr ()
-- scope : TreeScope -> Int32
-- pProperties : INT* in/out -> Ptr Int32
-- cProperties : INT -> Int32
-- pRequest : UiaCacheRequest* in/out -> Ptr ()
-- phEvent : HUIAEVENT* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let uiaaddevent =
  foreign "UiaAddEvent"
    ((ptr void) @-> int32_t @-> (ptr void) @-> int32_t @-> (ptr int32_t) @-> int32_t @-> (ptr void) @-> (ptr void) @-> returning int32_t)
(* hnode : HUIANODE -> (ptr void) *)
(* eventId : INT -> int32_t *)
(* pCallback : UiaEventCallback* in/out -> (ptr void) *)
(* scope : TreeScope -> int32_t *)
(* pProperties : INT* in/out -> (ptr int32_t) *)
(* cProperties : INT -> int32_t *)
(* pRequest : UiaCacheRequest* in/out -> (ptr void) *)
(* phEvent : HUIAEVENT* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library uiautomationcore (t "UIAutomationCore.dll"))
(cffi:use-foreign-library uiautomationcore)

(cffi:defcfun ("UiaAddEvent" uia-add-event :convention :stdcall) :int32
  (hnode :pointer)   ; HUIANODE
  (event-id :int32)   ; INT
  (p-callback :pointer)   ; UiaEventCallback* in/out
  (scope :int32)   ; TreeScope
  (p-properties :pointer)   ; INT* in/out
  (c-properties :int32)   ; INT
  (p-request :pointer)   ; UiaCacheRequest* in/out
  (ph-event :pointer))   ; HUIAEVENT* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $UiaAddEvent = Win32::API::More->new('UIAutomationCore',
    'int UiaAddEvent(HANDLE hnode, int eventId, LPVOID pCallback, int scope, LPVOID pProperties, int cProperties, LPVOID pRequest, HANDLE phEvent)');
# my $ret = $UiaAddEvent->Call($hnode, $eventId, $pCallback, $scope, $pProperties, $cProperties, $pRequest, $phEvent);
# hnode : HUIANODE -> HANDLE
# eventId : INT -> int
# pCallback : UiaEventCallback* in/out -> LPVOID
# scope : TreeScope -> int
# pProperties : INT* in/out -> LPVOID
# cProperties : INT -> int
# pRequest : UiaCacheRequest* in/out -> LPVOID
# phEvent : HUIAEVENT* in/out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

使用する型