NotifyRouteChange2
関数シグネチャ
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR NotifyRouteChange2(
ADDRESS_FAMILY AddressFamily,
PIPFORWARD_CHANGE_CALLBACK Callback,
void* CallerContext,
BOOLEAN InitialNotification,
HANDLE* NotificationHandle
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| AddressFamily | ADDRESS_FAMILY | in | 変更通知の登録対象となるアドレスファミリです。 アドレスファミリに指定できる値は Winsock2.h ヘッダーファイルに記載されています。AF_ アドレスファミリ定数と PF_ プロトコルファミリ定数の値は同一である(たとえば AF_INET と PF_INET)ため、どちらの定数も使用できます。 Windows Vista 以降向けにリリースされた Windows SDK では、ヘッダーファイルの構成が変更されており、このメンバーに指定可能な値は Ws2def.h ヘッダーファイルで定義されています。Ws2def.h ヘッダーファイルは Winsock2.h に自動的にインクルードされるため、直接使用してはなりません。 現在サポートされている値は AF_INET、AF_INET6、AF_UNSPEC です。
| ||||||||
| Callback | PIPFORWARD_CHANGE_CALLBACK | in | 変更が発生したときに呼び出す関数へのポインターです。この関数は IP ルート通知を受信したときに呼び出されます。 | ||||||||
| CallerContext | void* | in | IP ルート通知を受信したときに Callback パラメーターで指定したコールバック関数へ渡されるユーザーコンテキストです。 | ||||||||
| InitialNotification | BOOLEAN | in | 変更通知の登録が完了した直後にコールバックを呼び出すかどうかを示す値です。この初期通知は IP ルートエントリに変更が発生したことを示すものではありません。このパラメーターの目的は、コールバックが登録されたことを確認することにあります。 | ||||||||
| NotificationHandle | HANDLE* | inout | 後で変更通知を登録解除するために使用できるハンドルを返すためのポインターです。成功した場合、このパラメーターに通知ハンドルが返されます。エラーが発生した場合は NULL が返されます。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
ローカルコンピューター上の IP ルートエントリの変更について通知を受け取るよう登録します。
戻り値
関数が成功した場合、戻り値は NO_ERROR です。
関数が失敗した場合、戻り値は次のいずれかのエラーコードになります。
| 戻り値 | 説明 |
|---|---|
| 無効なハンドルが検出される内部エラーが発生しました。 | |
| 関数に無効なパラメーターが渡されました。このエラーは、Family パラメーターが AF_INET、AF_INET6、AF_UNSPEC のいずれでもなかった場合に返されます。 | |
| メモリが不足していました。 | |
|
返されたエラーのメッセージ文字列を取得するには、 FormatMessage を使用してください。 |
解説(Remarks)
NotifyRouteChange2 関数は Windows Vista 以降で定義されています。
Family パラメーターには AF_INET、AF_INET6、AF_UNSPEC のいずれかを設定する必要があります。
Callback パラメーターで指定したコールバック関数の呼び出しは直列化されます。コールバック関数は VOID 型の関数として定義してください。コールバック関数に渡されるパラメーターには次のものが含まれます。
| パラメーター | 説明 |
|---|---|
| IN PVOID CallerContext | 通知を登録する際に NotifyRouteChange2 関数へ渡された CallerContext パラメーターです。 |
| IN PMIB_IPFORWARD_ROW2 Row OPTIONAL | 変更された IP ルートエントリの MIB_IPFORWARD_ROW2 エントリへのポインターです。このパラメーターは、コールバック関数の NotificationType パラメーターに渡される MIB_NOTIFICATION_TYPE 値が MibInitialNotification に設定されている場合は NULL ポインターになります。これは、通知を登録する際に NotifyRouteChange2 に渡された InitialNotification パラメーターが TRUE に設定されていた場合にのみ発生します。 |
| IN MIB_NOTIFICATION_TYPE NotificationType | 通知の種類です。このメンバーには、Netioapi.h ヘッダーファイルで定義されている MIB_NOTIFICATION_TYPE 列挙型の値のいずれかを指定できます。 |
Callback パラメーターで指定したコールバック関数は、NotifyRouteChange2 関数を呼び出すアプリケーションと同じプロセス内で実装する必要があります。コールバック関数が別の DLL にある場合は、変更通知を登録するために NotifyRouteChange2 関数を呼び出す前にその DLL を読み込んでおく必要があります。
変更が発生してコールバック関数を受け取った際に Row パラメーターが NULL でない場合、Row パラメーターに渡される MIB_IPFORWARD_ROW2 構造体へのポインターには不完全なデータが含まれています。MIB_IPFORWARD_ROW2 構造体で返される情報は、アプリケーションが GetIpForwardEntry2 関数を呼び出して、変更された IP ルートに関する完全な情報を照会できる程度の情報のみです。コールバック関数を受け取ったら、アプリケーションは MIB_IPFORWARD_ROW2 構造体を割り当て、受け取った Row パラメーターが指す MIB_IPFORWARD_ROW2 構造体の DestinationPrefix、NextHop、InterfaceLuid、InterfaceIndex の各メンバーで初期化してください。この新しく初期化した MIB_IPFORWARD_ROW2 構造体へのポインターを GetIpForwardEntry2 関数に渡すことで、変更された IP ルートに関する完全な情報を取得できます。
コールバック通知で使用される Row パラメーターが指すメモリは、オペレーティングシステムによって管理されます。通知を受け取ったアプリケーションは、Row パラメーターが指すメモリを決して解放しようとしてはなりません。
変更通知を登録するために NotifyRouteChange2 関数を呼び出すと、アプリケーションが変更通知を登録解除するか、またはアプリケーションが終了するまで、これらの通知は送信され続けます。アプリケーションが終了すると、システムは変更通知のあらゆる登録を自動的に解除します。それでも、アプリケーションは終了する前に変更通知を明示的に登録解除することが推奨されます。
変更通知のあらゆる登録は、システムがシャットダウンまたは再起動された場合には保持されません。
変更通知を登録解除するには、NotifyRouteChange2 によって返された NotificationHandle パラメーターを渡して CancelMibChangeNotify2 関数を呼び出します。
アプリケーションは、同じ NotificationHandle パラメーターに対する通知コールバック関数を現在実行しているスレッドのコンテキストから CancelMibChangeNotify2 関数を呼び出すことはできません。これを行うと、そのコールバックを実行しているスレッドはデッドロックに陥ります。したがって、CancelMibChangeNotify2 関数を通知コールバックルーチンの一部として直接呼び出してはなりません。より一般的な状況として、CancelMibChangeNotify2 関数を実行するスレッドは、通知コールバック処理を実行するスレッドが待機するリソースを所有することはできません。同様のデッドロックを引き起こすためです。CancelMibChangeNotify2 関数は、通知コールバックを受け取るスレッドが依存していない別のスレッドから呼び出す必要があります。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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*
wintypes.BOOLEAN, # 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_ERRORfunction 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)。const std = @import("std");
extern "iphlpapi" fn NotifyRouteChange2(
AddressFamily: u16, // ADDRESS_FAMILY
Callback: ?*anyopaque, // PIPFORWARD_CHANGE_CALLBACK
CallerContext: ?*anyopaque, // void*
InitialNotification: u8, // BOOLEAN
NotificationHandle: ?*anyopaque // HANDLE* in/out
) callconv(std.os.windows.WINAPI) u32;proc NotifyRouteChange2(
AddressFamily: uint16, # ADDRESS_FAMILY
Callback: pointer, # PIPFORWARD_CHANGE_CALLBACK
CallerContext: pointer, # void*
InitialNotification: uint8, # BOOLEAN
NotificationHandle: pointer # HANDLE* in/out
): uint32 {.importc: "NotifyRouteChange2", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint NotifyRouteChange2(
ushort AddressFamily, // ADDRESS_FAMILY
void* Callback, // PIPFORWARD_CHANGE_CALLBACK
void* CallerContext, // void*
ubyte InitialNotification, // BOOLEAN
void* NotificationHandle // HANDLE* in/out
);ccall((:NotifyRouteChange2, "IPHLPAPI.dll"), stdcall, UInt32,
(UInt16, Ptr{Cvoid}, Ptr{Cvoid}, UInt8, Ptr{Cvoid}),
AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle)
# AddressFamily : ADDRESS_FAMILY -> UInt16
# Callback : PIPFORWARD_CHANGE_CALLBACK -> Ptr{Cvoid}
# CallerContext : void* -> Ptr{Cvoid}
# InitialNotification : BOOLEAN -> UInt8
# NotificationHandle : HANDLE* in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t NotifyRouteChange2(
uint16_t AddressFamily,
void* Callback,
void* CallerContext,
uint8_t InitialNotification,
void* NotificationHandle);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.NotifyRouteChange2(AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle)
-- AddressFamily : ADDRESS_FAMILY
-- Callback : PIPFORWARD_CHANGE_CALLBACK
-- CallerContext : void*
-- InitialNotification : BOOLEAN
-- NotificationHandle : HANDLE* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const NotifyRouteChange2 = lib.func('__stdcall', 'NotifyRouteChange2', 'uint32_t', ['uint16_t', 'void *', 'void *', 'uint8_t', 'void *']);
// NotifyRouteChange2(AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle)
// AddressFamily : ADDRESS_FAMILY -> 'uint16_t'
// Callback : PIPFORWARD_CHANGE_CALLBACK -> 'void *'
// CallerContext : void* -> 'void *'
// InitialNotification : BOOLEAN -> 'uint8_t'
// NotificationHandle : HANDLE* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。const lib = Deno.dlopen("IPHLPAPI.dll", {
NotifyRouteChange2: { parameters: ["u16", "pointer", "pointer", "u8", "pointer"], result: "u32" },
});
// lib.symbols.NotifyRouteChange2(AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle)
// AddressFamily : ADDRESS_FAMILY -> "u16"
// Callback : PIPFORWARD_CHANGE_CALLBACK -> "pointer"
// CallerContext : void* -> "pointer"
// InitialNotification : BOOLEAN -> "u8"
// NotificationHandle : HANDLE* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t NotifyRouteChange2(
uint16_t AddressFamily,
void* Callback,
void* CallerContext,
uint8_t InitialNotification,
void* NotificationHandle);
C, "IPHLPAPI.dll");
// $ffi->NotifyRouteChange2(AddressFamily, Callback, CallerContext, InitialNotification, NotificationHandle);
// AddressFamily : ADDRESS_FAMILY
// Callback : PIPFORWARD_CHANGE_CALLBACK
// CallerContext : void*
// InitialNotification : BOOLEAN
// NotificationHandle : HANDLE* 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 Iphlpapi extends StdCallLibrary {
Iphlpapi INSTANCE = Native.load("iphlpapi", Iphlpapi.class);
int NotifyRouteChange2(
short AddressFamily, // ADDRESS_FAMILY
Callback Callback, // PIPFORWARD_CHANGE_CALLBACK
Pointer CallerContext, // void*
byte InitialNotification, // BOOLEAN
Pointer NotificationHandle // HANDLE* in/out
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun NotifyRouteChange2 = NotifyRouteChange2(
AddressFamily : UInt16, # ADDRESS_FAMILY
Callback : Void*, # PIPFORWARD_CHANGE_CALLBACK
CallerContext : Void*, # void*
InitialNotification : UInt8, # BOOLEAN
NotificationHandle : Void* # HANDLE* in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef NotifyRouteChange2Native = Uint32 Function(Uint16, Pointer<Void>, Pointer<Void>, Uint8, Pointer<Void>);
typedef NotifyRouteChange2Dart = int Function(int, Pointer<Void>, Pointer<Void>, int, Pointer<Void>);
final NotifyRouteChange2 = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<NotifyRouteChange2Native, NotifyRouteChange2Dart>('NotifyRouteChange2');
// AddressFamily : ADDRESS_FAMILY -> Uint16
// Callback : PIPFORWARD_CHANGE_CALLBACK -> Pointer<Void>
// CallerContext : void* -> Pointer<Void>
// InitialNotification : BOOLEAN -> Uint8
// NotificationHandle : HANDLE* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "NotifyRouteChange2"
c_NotifyRouteChange2 :: Word16 -> Ptr () -> Ptr () -> Word8 -> Ptr () -> IO Word32
-- AddressFamily : ADDRESS_FAMILY -> Word16
-- Callback : PIPFORWARD_CHANGE_CALLBACK -> Ptr ()
-- CallerContext : void* -> Ptr ()
-- InitialNotification : BOOLEAN -> Word8
-- NotificationHandle : HANDLE* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let notifyroutechange2 =
foreign "NotifyRouteChange2"
(uint16_t @-> (ptr void) @-> (ptr void) @-> uint8_t @-> (ptr void) @-> returning uint32_t)
(* AddressFamily : ADDRESS_FAMILY -> uint16_t *)
(* Callback : PIPFORWARD_CHANGE_CALLBACK -> (ptr void) *)
(* CallerContext : void* -> (ptr void) *)
(* InitialNotification : BOOLEAN -> uint8_t *)
(* NotificationHandle : HANDLE* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)
(cffi:defcfun ("NotifyRouteChange2" notify-route-change2 :convention :stdcall) :uint32
(address-family :uint16) ; ADDRESS_FAMILY
(callback :pointer) ; PIPFORWARD_CHANGE_CALLBACK
(caller-context :pointer) ; void*
(initial-notification :uint8) ; BOOLEAN
(notification-handle :pointer)) ; HANDLE* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $NotifyRouteChange2 = Win32::API::More->new('IPHLPAPI',
'DWORD NotifyRouteChange2(WORD AddressFamily, LPVOID Callback, LPVOID CallerContext, BYTE InitialNotification, HANDLE NotificationHandle)');
# my $ret = $NotifyRouteChange2->Call($AddressFamily, $Callback, $CallerContext, $InitialNotification, $NotificationHandle);
# AddressFamily : ADDRESS_FAMILY -> WORD
# Callback : PIPFORWARD_CHANGE_CALLBACK -> LPVOID
# CallerContext : void* -> LPVOID
# InitialNotification : BOOLEAN -> BYTE
# NotificationHandle : HANDLE* in/out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。関連項目
- f NotifyRouteChange — ルーティングテーブルの変更を通知するよう登録する。
- f CancelMibChangeNotify2 — MIB変更通知の登録をキャンセルする。
- f CreateIpForwardEntry2 — IPルーティングテーブルに新しい経路エントリを追加する。
- f DeleteIpForwardEntry2 — IPルーティングテーブルから経路エントリを削除する。
- f GetBestRoute2 — 指定送信元・宛先アドレスに最適な経路と送信元を取得する。
- f GetIpForwardEntry2 — 指定したIP経路エントリの情報を取得する。
- f GetIpForwardTable2 — 指定アドレスファミリのIPルーティングテーブルを取得する。
- f InitializeIpForwardEntry — IP経路行構造体を既定値で初期化する。
- s MIB_IPFORWARD_ROW2
- s MIB_IPFORWARD_TABLE2
- e MIB_NOTIFICATION_TYPE
- f SetIpForwardEntry2 — 指定したIP経路エントリの内容を設定する。