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

CreateClusterNotifyPort

関数
クラスター通知ポートを作成する。
DLLCLUSAPI.dll呼出規約winapiSetLastErrorあり対応OSwindowsserver2008

シグネチャ

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

HCHANGE CreateClusterNotifyPort(
    HCHANGE hChange,
    HCLUSTER hCluster,
    DWORD dwFilter,
    UINT_PTR dwNotifyKey
);

パラメーター

名前方向説明
hChangeHCHANGEin既存の通知ポートハンドル。新規作成時はINVALID_HANDLE_VALUEを指定する。
hClusterHCLUSTERin通知を受け取る対象クラスタへのハンドル。
dwFilterDWORDin受信するイベント種別を示すCLUSTER_CHANGE_*ビットフラグ。
dwNotifyKeyUINT_PTRinこのフィルタに紐付けるユーザー定義キー。通知取得時に返される。

戻り値の型: HCHANGE

各言語での呼び出し定義

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

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

CreateClusterNotifyPort = ctypes.windll.clusapi.CreateClusterNotifyPort
CreateClusterNotifyPort.restype = ctypes.c_ssize_t
CreateClusterNotifyPort.argtypes = [
    ctypes.c_ssize_t,  # hChange : HCHANGE
    ctypes.c_ssize_t,  # hCluster : HCLUSTER
    wintypes.DWORD,  # dwFilter : DWORD
    ctypes.c_size_t,  # dwNotifyKey : UINT_PTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('CLUSAPI.dll')
CreateClusterNotifyPort = Fiddle::Function.new(
  lib['CreateClusterNotifyPort'],
  [
    Fiddle::TYPE_INTPTR_T,  # hChange : HCHANGE
    Fiddle::TYPE_INTPTR_T,  # hCluster : HCLUSTER
    -Fiddle::TYPE_INT,  # dwFilter : DWORD
    Fiddle::TYPE_UINTPTR_T,  # dwNotifyKey : UINT_PTR
  ],
  Fiddle::TYPE_INTPTR_T)
#[link(name = "clusapi")]
extern "system" {
    fn CreateClusterNotifyPort(
        hChange: isize,  // HCHANGE
        hCluster: isize,  // HCLUSTER
        dwFilter: u32,  // DWORD
        dwNotifyKey: usize  // UINT_PTR
    ) -> isize;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("CLUSAPI.dll", SetLastError = true)]
public static extern IntPtr CreateClusterNotifyPort(IntPtr hChange, IntPtr hCluster, uint dwFilter, UIntPtr dwNotifyKey);
"@
$api = Add-Type -MemberDefinition $sig -Name 'CLUSAPI_CreateClusterNotifyPort' -Namespace Win32 -PassThru
# $api::CreateClusterNotifyPort(hChange, hCluster, dwFilter, dwNotifyKey)
#uselib "CLUSAPI.dll"
#func global CreateClusterNotifyPort "CreateClusterNotifyPort" sptr, sptr, sptr, sptr
; CreateClusterNotifyPort hChange, hCluster, dwFilter, dwNotifyKey   ; 戻り値は stat
; hChange : HCHANGE -> "sptr"
; hCluster : HCLUSTER -> "sptr"
; dwFilter : DWORD -> "sptr"
; dwNotifyKey : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "CLUSAPI.dll"
#cfunc global CreateClusterNotifyPort "CreateClusterNotifyPort" sptr, sptr, int, sptr
; res = CreateClusterNotifyPort(hChange, hCluster, dwFilter, dwNotifyKey)
; hChange : HCHANGE -> "sptr"
; hCluster : HCLUSTER -> "sptr"
; dwFilter : DWORD -> "int"
; dwNotifyKey : UINT_PTR -> "sptr"
; HCHANGE CreateClusterNotifyPort(HCHANGE hChange, HCLUSTER hCluster, DWORD dwFilter, UINT_PTR dwNotifyKey)
#uselib "CLUSAPI.dll"
#cfunc global CreateClusterNotifyPort "CreateClusterNotifyPort" intptr, intptr, int, intptr
; res = CreateClusterNotifyPort(hChange, hCluster, dwFilter, dwNotifyKey)
; hChange : HCHANGE -> "intptr"
; hCluster : HCLUSTER -> "intptr"
; dwFilter : DWORD -> "int"
; dwNotifyKey : UINT_PTR -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	clusapi = windows.NewLazySystemDLL("CLUSAPI.dll")
	procCreateClusterNotifyPort = clusapi.NewProc("CreateClusterNotifyPort")
)

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

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

typedef CreateClusterNotifyPortNative = IntPtr Function(IntPtr, IntPtr, Uint32, UintPtr);
typedef CreateClusterNotifyPortDart = int Function(int, int, int, int);
final CreateClusterNotifyPort = DynamicLibrary.open('CLUSAPI.dll')
    .lookupFunction<CreateClusterNotifyPortNative, CreateClusterNotifyPortDart>('CreateClusterNotifyPort');
// hChange : HCHANGE -> IntPtr
// hCluster : HCLUSTER -> IntPtr
// dwFilter : DWORD -> Uint32
// dwNotifyKey : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function CreateClusterNotifyPort(
  hChange: NativeInt;   // HCHANGE
  hCluster: NativeInt;   // HCLUSTER
  dwFilter: DWORD;   // DWORD
  dwNotifyKey: NativeUInt   // UINT_PTR
): NativeInt; stdcall;
  external 'CLUSAPI.dll' name 'CreateClusterNotifyPort';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "CreateClusterNotifyPort"
  c_CreateClusterNotifyPort :: CIntPtr -> CIntPtr -> Word32 -> CUIntPtr -> IO CIntPtr
-- hChange : HCHANGE -> CIntPtr
-- hCluster : HCLUSTER -> CIntPtr
-- dwFilter : DWORD -> Word32
-- dwNotifyKey : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let createclusternotifyport =
  foreign "CreateClusterNotifyPort"
    (intptr_t @-> intptr_t @-> uint32_t @-> size_t @-> returning intptr_t)
(* hChange : HCHANGE -> intptr_t *)
(* hCluster : HCLUSTER -> intptr_t *)
(* dwFilter : DWORD -> uint32_t *)
(* 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 ("CreateClusterNotifyPort" create-cluster-notify-port :convention :stdcall) :int64
  (h-change :int64)   ; HCHANGE
  (h-cluster :int64)   ; HCLUSTER
  (dw-filter :uint32)   ; DWORD
  (dw-notify-key :uint64))   ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $CreateClusterNotifyPort = Win32::API::More->new('CLUSAPI',
    'LPARAM CreateClusterNotifyPort(LPARAM hChange, LPARAM hCluster, DWORD dwFilter, WPARAM dwNotifyKey)');
# my $ret = $CreateClusterNotifyPort->Call($hChange, $hCluster, $dwFilter, $dwNotifyKey);
# hChange : HCHANGE -> LPARAM
# hCluster : HCLUSTER -> LPARAM
# dwFilter : DWORD -> DWORD
# dwNotifyKey : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。