Win32 API 日本語リファレンス
ホームNetworkManagement.IpHelper › NotifyRouteChange2

NotifyRouteChange2

関数
IP経路の変更を通知するコールバックを登録する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

WIN32_ERROR NotifyRouteChange2(
    ADDRESS_FAMILY AddressFamily,
    PIPFORWARD_CHANGE_CALLBACK Callback,
    void* CallerContext,
    BOOLEAN InitialNotification,
    HANDLE* NotificationHandle
);

パラメーター

名前方向
AddressFamilyADDRESS_FAMILYin
CallbackPIPFORWARD_CHANGE_CALLBACKin
CallerContextvoid*in
InitialNotificationBOOLEANin
NotificationHandleHANDLE*inout

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR NotifyRouteChange2(
    ADDRESS_FAMILY AddressFamily,
    PIPFORWARD_CHANGE_CALLBACK Callback,
    void* CallerContext,
    BOOLEAN InitialNotification,
    HANDLE* NotificationHandle
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint NotifyRouteChange2(
    ushort AddressFamily,   // ADDRESS_FAMILY
    IntPtr Callback,   // PIPFORWARD_CHANGE_CALLBACK
    IntPtr CallerContext,   // void*
    [MarshalAs(UnmanagedType.U1)] bool InitialNotification,   // BOOLEAN
    IntPtr NotificationHandle   // HANDLE* in/out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function NotifyRouteChange2(
    AddressFamily As UShort,   ' ADDRESS_FAMILY
    Callback As IntPtr,   ' PIPFORWARD_CHANGE_CALLBACK
    CallerContext As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.U1)> InitialNotification As Boolean,   ' BOOLEAN
    NotificationHandle As IntPtr   ' HANDLE* in/out
) As UInteger
End Function
' AddressFamily : ADDRESS_FAMILY
' Callback : PIPFORWARD_CHANGE_CALLBACK
' CallerContext : void*
' InitialNotification : BOOLEAN
' NotificationHandle : HANDLE* in/out
Declare PtrSafe Function NotifyRouteChange2 Lib "iphlpapi" ( _
    ByVal AddressFamily As Integer, _
    ByVal Callback As LongPtr, _
    ByVal CallerContext As LongPtr, _
    ByVal InitialNotification As Byte, _
    ByVal NotificationHandle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NotifyRouteChange2 = ctypes.windll.iphlpapi.NotifyRouteChange2
NotifyRouteChange2.restype = wintypes.DWORD
NotifyRouteChange2.argtypes = [
    ctypes.c_ushort,  # AddressFamily : ADDRESS_FAMILY
    ctypes.c_void_p,  # Callback : PIPFORWARD_CHANGE_CALLBACK
    ctypes.POINTER(None),  # CallerContext : void*
    ctypes.c_byte,  # InitialNotification : BOOLEAN
    ctypes.c_void_p,  # NotificationHandle : HANDLE* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
NotifyRouteChange2 = Fiddle::Function.new(
  lib['NotifyRouteChange2'],
  [
    -Fiddle::TYPE_SHORT,  # AddressFamily : ADDRESS_FAMILY
    Fiddle::TYPE_VOIDP,  # Callback : PIPFORWARD_CHANGE_CALLBACK
    Fiddle::TYPE_VOIDP,  # CallerContext : void*
    Fiddle::TYPE_CHAR,  # InitialNotification : BOOLEAN
    Fiddle::TYPE_VOIDP,  # NotificationHandle : HANDLE* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn NotifyRouteChange2(
        AddressFamily: u16,  // ADDRESS_FAMILY
        Callback: *const core::ffi::c_void,  // PIPFORWARD_CHANGE_CALLBACK
        CallerContext: *mut (),  // void*
        InitialNotification: u8,  // BOOLEAN
        NotificationHandle: *mut *mut core::ffi::c_void  // HANDLE* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint NotifyRouteChange2(ushort AddressFamily, IntPtr Callback, IntPtr CallerContext, [MarshalAs(UnmanagedType.U1)] bool InitialNotification, IntPtr NotificationHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_NotifyRouteChange2' -Namespace Win32 -PassThru
# $api::NotifyRouteChange2(AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle)
#uselib "IPHLPAPI.dll"
#func global NotifyRouteChange2 "NotifyRouteChange2" sptr, sptr, sptr, sptr, sptr
; NotifyRouteChange2 AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle   ; 戻り値は stat
; AddressFamily : ADDRESS_FAMILY -> "sptr"
; Callback : PIPFORWARD_CHANGE_CALLBACK -> "sptr"
; CallerContext : void* -> "sptr"
; InitialNotification : BOOLEAN -> "sptr"
; NotificationHandle : HANDLE* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "IPHLPAPI.dll"
#cfunc global NotifyRouteChange2 "NotifyRouteChange2" int, sptr, sptr, int, sptr
; res = NotifyRouteChange2(AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle)
; AddressFamily : ADDRESS_FAMILY -> "int"
; Callback : PIPFORWARD_CHANGE_CALLBACK -> "sptr"
; CallerContext : void* -> "sptr"
; InitialNotification : BOOLEAN -> "int"
; NotificationHandle : HANDLE* in/out -> "sptr"
; WIN32_ERROR NotifyRouteChange2(ADDRESS_FAMILY AddressFamily, PIPFORWARD_CHANGE_CALLBACK Callback, void* CallerContext, BOOLEAN InitialNotification, HANDLE* NotificationHandle)
#uselib "IPHLPAPI.dll"
#cfunc global NotifyRouteChange2 "NotifyRouteChange2" int, intptr, intptr, int, intptr
; res = NotifyRouteChange2(AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle)
; AddressFamily : ADDRESS_FAMILY -> "int"
; Callback : PIPFORWARD_CHANGE_CALLBACK -> "intptr"
; CallerContext : void* -> "intptr"
; InitialNotification : BOOLEAN -> "int"
; NotificationHandle : HANDLE* in/out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procNotifyRouteChange2 = iphlpapi.NewProc("NotifyRouteChange2")
)

// AddressFamily (ADDRESS_FAMILY), Callback (PIPFORWARD_CHANGE_CALLBACK), CallerContext (void*), InitialNotification (BOOLEAN), NotificationHandle (HANDLE* in/out)
r1, _, err := procNotifyRouteChange2.Call(
	uintptr(AddressFamily),
	uintptr(Callback),
	uintptr(CallerContext),
	uintptr(InitialNotification),
	uintptr(NotificationHandle),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function NotifyRouteChange2(
  AddressFamily: Word;   // ADDRESS_FAMILY
  Callback: Pointer;   // PIPFORWARD_CHANGE_CALLBACK
  CallerContext: Pointer;   // void*
  InitialNotification: ByteBool;   // BOOLEAN
  NotificationHandle: Pointer   // HANDLE* in/out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'NotifyRouteChange2';
result := DllCall("IPHLPAPI\NotifyRouteChange2"
    , "UShort", AddressFamily   ; ADDRESS_FAMILY
    , "Ptr", Callback   ; PIPFORWARD_CHANGE_CALLBACK
    , "Ptr", CallerContext   ; void*
    , "Char", InitialNotification   ; BOOLEAN
    , "Ptr", NotificationHandle   ; HANDLE* in/out
    , "UInt")   ; return: WIN32_ERROR
●NotifyRouteChange2(AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle) = DLL("IPHLPAPI.dll", "dword NotifyRouteChange2(int, void*, void*, byte, void*)")
# 呼び出し: NotifyRouteChange2(AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle)
# AddressFamily : ADDRESS_FAMILY -> "int"
# Callback : PIPFORWARD_CHANGE_CALLBACK -> "void*"
# CallerContext : void* -> "void*"
# InitialNotification : BOOLEAN -> "byte"
# NotificationHandle : HANDLE* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。