Win32 API 日本語リファレンス
ホームNetworking.Clustering › RegisterClusterNotifyV2

RegisterClusterNotifyV2

関数
V2通知ポートにイベントフィルターを登録する。
DLLCLUSAPI.dll呼出規約winapi対応OSwindowsserver2016

シグネチャ

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

DWORD RegisterClusterNotifyV2(
    HCHANGE hChange,
    NOTIFY_FILTER_AND_TYPE Filter,
    HANDLE hObject,
    UINT_PTR dwNotifyKey
);

パラメーター

名前方向説明
hChangeHCHANGEinCreateClusterNotifyPortV2で作成した通知ポートハンドル。
FilterNOTIFY_FILTER_AND_TYPEin登録するイベントのフィルタと種別を示す構造体。
hObjectHANDLEin通知対象のクラスタオブジェクトハンドル。
dwNotifyKeyUINT_PTRinこの登録に紐付けるユーザー定義キー。通知取得時に返される。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD RegisterClusterNotifyV2(
    HCHANGE hChange,
    NOTIFY_FILTER_AND_TYPE Filter,
    HANDLE hObject,
    UINT_PTR dwNotifyKey
);
[DllImport("CLUSAPI.dll", ExactSpelling = true)]
static extern uint RegisterClusterNotifyV2(
    IntPtr hChange,   // HCHANGE
    NOTIFY_FILTER_AND_TYPE Filter,   // NOTIFY_FILTER_AND_TYPE
    IntPtr hObject,   // HANDLE
    UIntPtr dwNotifyKey   // UINT_PTR
);
<DllImport("CLUSAPI.dll", ExactSpelling:=True)>
Public Shared Function RegisterClusterNotifyV2(
    hChange As IntPtr,   ' HCHANGE
    Filter As NOTIFY_FILTER_AND_TYPE,   ' NOTIFY_FILTER_AND_TYPE
    hObject As IntPtr,   ' HANDLE
    dwNotifyKey As UIntPtr   ' UINT_PTR
) As UInteger
End Function
' hChange : HCHANGE
' Filter : NOTIFY_FILTER_AND_TYPE
' hObject : HANDLE
' dwNotifyKey : UINT_PTR
Declare PtrSafe Function RegisterClusterNotifyV2 Lib "clusapi" ( _
    ByVal hChange As LongPtr, _
    ByVal Filter As LongPtr, _
    ByVal hObject As LongPtr, _
    ByVal dwNotifyKey As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RegisterClusterNotifyV2 = ctypes.windll.clusapi.RegisterClusterNotifyV2
RegisterClusterNotifyV2.restype = wintypes.DWORD
RegisterClusterNotifyV2.argtypes = [
    ctypes.c_ssize_t,  # hChange : HCHANGE
    NOTIFY_FILTER_AND_TYPE,  # Filter : NOTIFY_FILTER_AND_TYPE
    wintypes.HANDLE,  # hObject : HANDLE
    ctypes.c_size_t,  # dwNotifyKey : UINT_PTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CLUSAPI.dll')
RegisterClusterNotifyV2 = Fiddle::Function.new(
  lib['RegisterClusterNotifyV2'],
  [
    Fiddle::TYPE_INTPTR_T,  # hChange : HCHANGE
    Fiddle::TYPE_VOIDP,  # Filter : NOTIFY_FILTER_AND_TYPE
    Fiddle::TYPE_VOIDP,  # hObject : HANDLE
    Fiddle::TYPE_UINTPTR_T,  # dwNotifyKey : UINT_PTR
  ],
  -Fiddle::TYPE_INT)
#[link(name = "clusapi")]
extern "system" {
    fn RegisterClusterNotifyV2(
        hChange: isize,  // HCHANGE
        Filter: NOTIFY_FILTER_AND_TYPE,  // NOTIFY_FILTER_AND_TYPE
        hObject: *mut core::ffi::c_void,  // HANDLE
        dwNotifyKey: usize  // UINT_PTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CLUSAPI.dll")]
public static extern uint RegisterClusterNotifyV2(IntPtr hChange, NOTIFY_FILTER_AND_TYPE Filter, IntPtr hObject, UIntPtr dwNotifyKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CLUSAPI_RegisterClusterNotifyV2' -Namespace Win32 -PassThru
# $api::RegisterClusterNotifyV2(hChange, Filter, hObject, dwNotifyKey)
#uselib "CLUSAPI.dll"
#func global RegisterClusterNotifyV2 "RegisterClusterNotifyV2" sptr, sptr, sptr, sptr
; RegisterClusterNotifyV2 hChange, Filter, hObject, dwNotifyKey   ; 戻り値は stat
; hChange : HCHANGE -> "sptr"
; Filter : NOTIFY_FILTER_AND_TYPE -> "sptr"
; hObject : HANDLE -> "sptr"
; dwNotifyKey : UINT_PTR -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CLUSAPI.dll"
#cfunc global RegisterClusterNotifyV2 "RegisterClusterNotifyV2" sptr, int, sptr, sptr
; res = RegisterClusterNotifyV2(hChange, Filter, hObject, dwNotifyKey)
; hChange : HCHANGE -> "sptr"
; Filter : NOTIFY_FILTER_AND_TYPE -> "int"
; hObject : HANDLE -> "sptr"
; dwNotifyKey : UINT_PTR -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; DWORD RegisterClusterNotifyV2(HCHANGE hChange, NOTIFY_FILTER_AND_TYPE Filter, HANDLE hObject, UINT_PTR dwNotifyKey)
#uselib "CLUSAPI.dll"
#cfunc global RegisterClusterNotifyV2 "RegisterClusterNotifyV2" intptr, int, intptr, intptr
; res = RegisterClusterNotifyV2(hChange, Filter, hObject, dwNotifyKey)
; hChange : HCHANGE -> "intptr"
; Filter : NOTIFY_FILTER_AND_TYPE -> "int"
; hObject : HANDLE -> "intptr"
; dwNotifyKey : UINT_PTR -> "intptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procRegisterClusterNotifyV2 = clusapi.NewProc("RegisterClusterNotifyV2")
)

// hChange (HCHANGE), Filter (NOTIFY_FILTER_AND_TYPE), hObject (HANDLE), dwNotifyKey (UINT_PTR)
r1, _, err := procRegisterClusterNotifyV2.Call(
	uintptr(hChange),
	uintptr(Filter),
	uintptr(hObject),
	uintptr(dwNotifyKey),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function RegisterClusterNotifyV2(
  hChange: NativeInt;   // HCHANGE
  Filter: NOTIFY_FILTER_AND_TYPE;   // NOTIFY_FILTER_AND_TYPE
  hObject: THandle;   // HANDLE
  dwNotifyKey: NativeUInt   // UINT_PTR
): DWORD; stdcall;
  external 'CLUSAPI.dll' name 'RegisterClusterNotifyV2';
result := DllCall("CLUSAPI\RegisterClusterNotifyV2"
    , "Ptr", hChange   ; HCHANGE
    , "Ptr", Filter   ; NOTIFY_FILTER_AND_TYPE
    , "Ptr", hObject   ; HANDLE
    , "UPtr", dwNotifyKey   ; UINT_PTR
    , "UInt")   ; return: DWORD
●RegisterClusterNotifyV2(hChange, Filter, hObject, dwNotifyKey) = DLL("CLUSAPI.dll", "dword RegisterClusterNotifyV2(int, void*, void*, int)")
# 呼び出し: RegisterClusterNotifyV2(hChange, Filter, hObject, dwNotifyKey)
# hChange : HCHANGE -> "int"
# Filter : NOTIFY_FILTER_AND_TYPE -> "void*"
# hObject : HANDLE -> "void*"
# dwNotifyKey : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "clusapi" fn RegisterClusterNotifyV2(
    hChange: isize, // HCHANGE
    Filter: NOTIFY_FILTER_AND_TYPE, // NOTIFY_FILTER_AND_TYPE
    hObject: ?*anyopaque, // HANDLE
    dwNotifyKey: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) u32;
proc RegisterClusterNotifyV2(
    hChange: int,  # HCHANGE
    Filter: NOTIFY_FILTER_AND_TYPE,  # NOTIFY_FILTER_AND_TYPE
    hObject: pointer,  # HANDLE
    dwNotifyKey: uint  # UINT_PTR
): uint32 {.importc: "RegisterClusterNotifyV2", stdcall, dynlib: "CLUSAPI.dll".}
pragma(lib, "clusapi");
extern(Windows)
uint RegisterClusterNotifyV2(
    ptrdiff_t hChange,   // HCHANGE
    NOTIFY_FILTER_AND_TYPE Filter,   // NOTIFY_FILTER_AND_TYPE
    void* hObject,   // HANDLE
    size_t dwNotifyKey   // UINT_PTR
);
ccall((:RegisterClusterNotifyV2, "CLUSAPI.dll"), stdcall, UInt32,
      (Int, NOTIFY_FILTER_AND_TYPE, Ptr{Cvoid}, Csize_t),
      hChange, Filter, hObject, dwNotifyKey)
# hChange : HCHANGE -> Int
# Filter : NOTIFY_FILTER_AND_TYPE -> NOTIFY_FILTER_AND_TYPE
# hObject : HANDLE -> Ptr{Cvoid}
# dwNotifyKey : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t RegisterClusterNotifyV2(
    intptr_t hChange,
    NOTIFY_FILTER_AND_TYPE Filter,
    void* hObject,
    uintptr_t dwNotifyKey);
]]
local clusapi = ffi.load("clusapi")
-- clusapi.RegisterClusterNotifyV2(hChange, Filter, hObject, dwNotifyKey)
-- hChange : HCHANGE
-- Filter : NOTIFY_FILTER_AND_TYPE
-- hObject : HANDLE
-- dwNotifyKey : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('CLUSAPI.dll');
const RegisterClusterNotifyV2 = lib.func('__stdcall', 'RegisterClusterNotifyV2', 'uint32_t', ['intptr_t', 'NOTIFY_FILTER_AND_TYPE', 'void *', 'uintptr_t']);
// RegisterClusterNotifyV2(hChange, Filter, hObject, dwNotifyKey)
// hChange : HCHANGE -> 'intptr_t'
// Filter : NOTIFY_FILTER_AND_TYPE -> 'NOTIFY_FILTER_AND_TYPE'
// hObject : HANDLE -> 'void *'
// dwNotifyKey : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("CLUSAPI.dll", {
  RegisterClusterNotifyV2: { parameters: ["isize", "buffer", "pointer", "usize"], result: "u32" },
});
// lib.symbols.RegisterClusterNotifyV2(hChange, Filter, hObject, dwNotifyKey)
// hChange : HCHANGE -> "isize"
// Filter : NOTIFY_FILTER_AND_TYPE -> "buffer"
// hObject : HANDLE -> "pointer"
// dwNotifyKey : UINT_PTR -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t RegisterClusterNotifyV2(
    intptr_t hChange,
    NOTIFY_FILTER_AND_TYPE Filter,
    void* hObject,
    size_t dwNotifyKey);
C, "CLUSAPI.dll");
// $ffi->RegisterClusterNotifyV2(hChange, Filter, hObject, dwNotifyKey);
// hChange : HCHANGE
// Filter : NOTIFY_FILTER_AND_TYPE
// hObject : HANDLE
// dwNotifyKey : UINT_PTR
// 構造体/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 Clusapi extends StdCallLibrary {
    Clusapi INSTANCE = Native.load("clusapi", Clusapi.class);
    int RegisterClusterNotifyV2(
        long hChange,   // HCHANGE
        NOTIFY_FILTER_AND_TYPE /* extends Structure (by value) */ Filter,   // NOTIFY_FILTER_AND_TYPE
        Pointer hObject,   // HANDLE
        long dwNotifyKey   // UINT_PTR
    );
}
@[Link("clusapi")]
lib LibCLUSAPI
  fun RegisterClusterNotifyV2 = RegisterClusterNotifyV2(
    hChange : LibC::SSizeT,   # HCHANGE
    Filter : NOTIFY_FILTER_AND_TYPE,   # NOTIFY_FILTER_AND_TYPE
    hObject : Void*,   # HANDLE
    dwNotifyKey : LibC::SizeT   # UINT_PTR
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef RegisterClusterNotifyV2Native = Uint32 Function(IntPtr, NOTIFY_FILTER_AND_TYPE, Pointer<Void>, UintPtr);
typedef RegisterClusterNotifyV2Dart = int Function(int, int, Pointer<Void>, int);
final RegisterClusterNotifyV2 = DynamicLibrary.open('CLUSAPI.dll')
    .lookupFunction<RegisterClusterNotifyV2Native, RegisterClusterNotifyV2Dart>('RegisterClusterNotifyV2');
// hChange : HCHANGE -> IntPtr
// Filter : NOTIFY_FILTER_AND_TYPE -> NOTIFY_FILTER_AND_TYPE
// hObject : HANDLE -> Pointer<Void>
// dwNotifyKey : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function RegisterClusterNotifyV2(
  hChange: NativeInt;   // HCHANGE
  Filter: NOTIFY_FILTER_AND_TYPE;   // NOTIFY_FILTER_AND_TYPE
  hObject: THandle;   // HANDLE
  dwNotifyKey: NativeUInt   // UINT_PTR
): DWORD; stdcall;
  external 'CLUSAPI.dll' name 'RegisterClusterNotifyV2';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RegisterClusterNotifyV2"
  c_RegisterClusterNotifyV2 :: CIntPtr -> NOTIFY_FILTER_AND_TYPE -> Ptr () -> CUIntPtr -> IO Word32
-- hChange : HCHANGE -> CIntPtr
-- Filter : NOTIFY_FILTER_AND_TYPE -> NOTIFY_FILTER_AND_TYPE
-- hObject : HANDLE -> Ptr ()
-- dwNotifyKey : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。
open Ctypes
open Foreign

let registerclusternotifyv2 =
  foreign "RegisterClusterNotifyV2"
    (intptr_t @-> NOTIFY_FILTER_AND_TYPE @-> (ptr void) @-> size_t @-> returning uint32_t)
(* hChange : HCHANGE -> intptr_t *)
(* Filter : NOTIFY_FILTER_AND_TYPE -> NOTIFY_FILTER_AND_TYPE *)
(* hObject : HANDLE -> (ptr void) *)
(* dwNotifyKey : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library clusapi (t "CLUSAPI.dll"))
(cffi:use-foreign-library clusapi)

(cffi:defcfun ("RegisterClusterNotifyV2" register-cluster-notify-v2 :convention :stdcall) :uint32
  (h-change :int64)   ; HCHANGE
  (filter (:struct notify-filter-and-type))   ; NOTIFY_FILTER_AND_TYPE
  (h-object :pointer)   ; HANDLE
  (dw-notify-key :uint64))   ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RegisterClusterNotifyV2 = Win32::API::More->new('CLUSAPI',
    'DWORD RegisterClusterNotifyV2(LPARAM hChange, LPVOID Filter, HANDLE hObject, WPARAM dwNotifyKey)');
# my $ret = $RegisterClusterNotifyV2->Call($hChange, $Filter, $hObject, $dwNotifyKey);
# hChange : HCHANGE -> LPARAM
# Filter : NOTIFY_FILTER_AND_TYPE -> LPVOID
# hObject : HANDLE -> HANDLE
# dwNotifyKey : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型