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

NotifyUnicastIpAddressChange

関数
ユニキャストIPアドレスの変更を通知登録する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

WIN32_ERROR NotifyUnicastIpAddressChange(
    ADDRESS_FAMILY Family,
    PUNICAST_IPADDRESS_CHANGE_CALLBACK Callback,
    void* CallerContext,   // optional
    BOOLEAN InitialNotification,
    HANDLE* NotificationHandle
);

パラメーター

名前方向
FamilyADDRESS_FAMILYin
CallbackPUNICAST_IPADDRESS_CHANGE_CALLBACKin
CallerContextvoid*inoptional
InitialNotificationBOOLEANin
NotificationHandleHANDLE*inout

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR NotifyUnicastIpAddressChange(
    ADDRESS_FAMILY Family,
    PUNICAST_IPADDRESS_CHANGE_CALLBACK Callback,
    void* CallerContext,   // optional
    BOOLEAN InitialNotification,
    HANDLE* NotificationHandle
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint NotifyUnicastIpAddressChange(
    ushort Family,   // ADDRESS_FAMILY
    IntPtr Callback,   // PUNICAST_IPADDRESS_CHANGE_CALLBACK
    IntPtr CallerContext,   // void* optional
    [MarshalAs(UnmanagedType.U1)] bool InitialNotification,   // BOOLEAN
    IntPtr NotificationHandle   // HANDLE* in/out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function NotifyUnicastIpAddressChange(
    Family As UShort,   ' ADDRESS_FAMILY
    Callback As IntPtr,   ' PUNICAST_IPADDRESS_CHANGE_CALLBACK
    CallerContext As IntPtr,   ' void* optional
    <MarshalAs(UnmanagedType.U1)> InitialNotification As Boolean,   ' BOOLEAN
    NotificationHandle As IntPtr   ' HANDLE* in/out
) As UInteger
End Function
' Family : ADDRESS_FAMILY
' Callback : PUNICAST_IPADDRESS_CHANGE_CALLBACK
' CallerContext : void* optional
' InitialNotification : BOOLEAN
' NotificationHandle : HANDLE* in/out
Declare PtrSafe Function NotifyUnicastIpAddressChange Lib "iphlpapi" ( _
    ByVal Family 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

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

lib = Fiddle.dlopen('IPHLPAPI.dll')
NotifyUnicastIpAddressChange = Fiddle::Function.new(
  lib['NotifyUnicastIpAddressChange'],
  [
    -Fiddle::TYPE_SHORT,  # Family : ADDRESS_FAMILY
    Fiddle::TYPE_VOIDP,  # Callback : PUNICAST_IPADDRESS_CHANGE_CALLBACK
    Fiddle::TYPE_VOIDP,  # CallerContext : void* optional
    Fiddle::TYPE_CHAR,  # InitialNotification : BOOLEAN
    Fiddle::TYPE_VOIDP,  # NotificationHandle : HANDLE* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn NotifyUnicastIpAddressChange(
        Family: u16,  // ADDRESS_FAMILY
        Callback: *const core::ffi::c_void,  // PUNICAST_IPADDRESS_CHANGE_CALLBACK
        CallerContext: *mut (),  // void* optional
        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 NotifyUnicastIpAddressChange(ushort Family, IntPtr Callback, IntPtr CallerContext, [MarshalAs(UnmanagedType.U1)] bool InitialNotification, IntPtr NotificationHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_NotifyUnicastIpAddressChange' -Namespace Win32 -PassThru
# $api::NotifyUnicastIpAddressChange(Family, Callback, CallerContext, InitialNotification, NotificationHandle)
#uselib "IPHLPAPI.dll"
#func global NotifyUnicastIpAddressChange "NotifyUnicastIpAddressChange" sptr, sptr, sptr, sptr, sptr
; NotifyUnicastIpAddressChange Family, Callback, CallerContext, InitialNotification, NotificationHandle   ; 戻り値は stat
; Family : ADDRESS_FAMILY -> "sptr"
; Callback : PUNICAST_IPADDRESS_CHANGE_CALLBACK -> "sptr"
; CallerContext : void* optional -> "sptr"
; InitialNotification : BOOLEAN -> "sptr"
; NotificationHandle : HANDLE* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "IPHLPAPI.dll"
#cfunc global NotifyUnicastIpAddressChange "NotifyUnicastIpAddressChange" int, sptr, sptr, int, sptr
; res = NotifyUnicastIpAddressChange(Family, Callback, CallerContext, InitialNotification, NotificationHandle)
; Family : ADDRESS_FAMILY -> "int"
; Callback : PUNICAST_IPADDRESS_CHANGE_CALLBACK -> "sptr"
; CallerContext : void* optional -> "sptr"
; InitialNotification : BOOLEAN -> "int"
; NotificationHandle : HANDLE* in/out -> "sptr"
; WIN32_ERROR NotifyUnicastIpAddressChange(ADDRESS_FAMILY Family, PUNICAST_IPADDRESS_CHANGE_CALLBACK Callback, void* CallerContext, BOOLEAN InitialNotification, HANDLE* NotificationHandle)
#uselib "IPHLPAPI.dll"
#cfunc global NotifyUnicastIpAddressChange "NotifyUnicastIpAddressChange" int, intptr, intptr, int, intptr
; res = NotifyUnicastIpAddressChange(Family, Callback, CallerContext, InitialNotification, NotificationHandle)
; Family : ADDRESS_FAMILY -> "int"
; Callback : PUNICAST_IPADDRESS_CHANGE_CALLBACK -> "intptr"
; CallerContext : void* optional -> "intptr"
; InitialNotification : BOOLEAN -> "int"
; NotificationHandle : HANDLE* in/out -> "intptr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procNotifyUnicastIpAddressChange = iphlpapi.NewProc("NotifyUnicastIpAddressChange")
)

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