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

NotifyStableUnicastIpAddressTable

関数
安定したユニキャストIPアドレステーブルを取得し通知登録する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

WIN32_ERROR NotifyStableUnicastIpAddressTable(
    ADDRESS_FAMILY Family,
    MIB_UNICASTIPADDRESS_TABLE** Table,
    PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK CallerCallback,
    void* CallerContext,
    HANDLE* NotificationHandle
);

パラメーター

名前方向説明
FamilyADDRESS_FAMILYin

取得するアドレスファミリです。

アドレスファミリに指定できる値は Winsock2.h ヘッダーファイルに列挙されています。AF_ アドレスファミリ定数と PF_ プロトコルファミリ定数の値は同一である(たとえば AF_INETPF_INET)ため、どちらの定数も使用できます。

Windows Vista 以降向けにリリースされた Windows SDK では、ヘッダーファイルの構成が変更されており、このメンバーに指定できる値は Ws2def.h ヘッダーファイルで定義されています。なお、Ws2def.h ヘッダーファイルは Winsock2.h に自動的にインクルードされるため、直接使用してはいけません。

現在サポートされている値は AF_INETAF_INET6AF_UNSPEC です。

意味
AF_UNSPEC
0
アドレスファミリが指定されていません。このパラメーターを指定すると、この関数は IPv4 と IPv6 の両方のエントリを含む安定したユニキャスト IP アドレステーブルを取得します。
AF_INET
2
インターネットプロトコルバージョン 4 (IPv4) アドレスファミリです。このパラメーターを指定すると、この関数は IPv4 エントリのみを含む安定したユニキャスト IP アドレステーブルを取得します。
AF_INET6
23
インターネットプロトコルバージョン 6 (IPv6) アドレスファミリです。このパラメーターを指定すると、この関数は IPv6 エントリのみを含む安定したユニキャスト IP アドレステーブルを取得します。
TableMIB_UNICASTIPADDRESS_TABLE**out

MIB_UNICASTIPADDRESS_TABLE 構造体へのポインターです。NotifyStableUnicastIpAddressTable が成功した場合、このパラメーターはローカルコンピューター上の安定したユニキャスト IP アドレステーブルを返します。

NotifyStableUnicastIpAddressTableERROR_IO_PENDING を返して I/O 要求が保留中であることを示す場合、安定したユニキャスト IP アドレステーブルは CallerCallback パラメーターで指定した関数に返されます。

CallerCallbackPSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACKin安定したユニキャスト IP アドレステーブルとともに呼び出される関数へのポインターです。この関数は、NotifyStableUnicastIpAddressTableERROR_IO_PENDING を返して I/O 要求が保留中であることを示した場合に呼び出されます。
CallerContextvoid*in安定したユニキャスト IP アドレステーブルが利用可能になったときに、CallerCallback パラメーターで指定したコールバック関数に渡されるユーザーコンテキストです。
NotificationHandleHANDLE*inout安定したユニキャスト IP アドレステーブルの取得要求をキャンセルするために使用できるハンドルを返すためのポインターです。このパラメーターは、NotifyStableUnicastIpAddressTable の戻り値が ERROR_IO_PENDING で I/O 要求が保留中であることを示す場合に返されます。

戻り値の型: WIN32_ERROR

公式ドキュメント

ローカルコンピューター上の安定したユニキャスト IP アドレステーブルを取得します。

戻り値

関数が即座に成功した場合、戻り値は NO_ERROR となり、安定したユニキャスト IP テーブルが Table パラメーターに返されます。

I/O 要求が保留中の場合、関数は ERROR_IO_PENDING を返し、I/O 要求が完了したときに安定したユニキャスト IP アドレステーブルとともに CallerCallback パラメーターが指す関数が呼び出されます。

関数が失敗した場合、戻り値は次のいずれかのエラーコードになります。

戻り値 説明
ERROR_INVALID_HANDLE
無効なハンドルが検出される内部エラーが発生しました。
ERROR_INVALID_PARAMETER
無効なパラメーターが関数に渡されました。このエラーは、Table パラメーターが NULL ポインターである場合、NotificationHandle パラメーターが NULL ポインターである場合、または Family パラメーターが AF_INETAF_INET6AF_UNSPEC のいずれでもない場合に返されます。
ERROR_NOT_ENOUGH_MEMORY
メモリが不足していました。
その他
返されたエラーのメッセージ文字列を取得するには、FormatMessage を使用してください。

解説(Remarks)

NotifyStableUnicastIpAddressTable 関数は Windows Vista 以降で定義されています。

NotifyStableUnicastIpAddressTable 関数が即座に成功した場合、戻り値は NO_ERROR となり、安定したユニキャスト IP テーブルが Table パラメーターに返されます。呼び出し側アプリケーションは、MIB_UNICASTIPADDRESS_TABLE の情報が不要になった時点で、FreeMibTable 関数を使用して Table パラメーターが指すメモリを解放する必要があります。

ダイヤルオンデマンドアドレスを除くすべてのユニキャスト IP アドレスは、優先(preferred)状態にある場合にのみ安定していると見なされます。通常のユニキャスト IP アドレスエントリの場合、これはその IP アドレスの MIB_UNICASTIPADDRESS_ROW の DadState メンバーが IpDadStatePreferred に設定されている状態に相当します。 ダイヤルオンデマンドアドレスはそれぞれ独自の安定性メトリックを定義します。現在、この関数が考慮するダイヤルオンデマンドアドレスは、ローカルコンピューター上の Teredo クライアントが使用するユニキャスト IP アドレスのみです。

Family パラメーターには AF_INETAF_INET6AF_UNSPEC のいずれかを設定する必要があります。

NotifyStableUnicastIpAddressTable が成功して NO_ERROR を返した場合、Table パラメーターはローカルコンピューター上の安定したユニキャスト IP アドレステーブルを返します。

NotifyStableUnicastIpAddressTableERROR_IO_PENDING を返して I/O 要求が保留中であることを示す場合、安定したユニキャスト IP アドレステーブルは CallerCallback パラメーターで指定した関数に返されます。

NotifyStableUnicastIpAddressTable 関数は主に Teredo クライアントを使用するアプリケーションで利用されます。

Teredo が使用するユニキャスト IP アドレスがローカルコンピューター上で利用可能であるものの、安定した(認定された)状態にない場合、NotifyStableUnicastIpAddressTableERROR_IO_PENDING を返し、最終的に CallerCallback パラメーターで指定した関数を呼び出すことで安定したユニキャスト IP アドレステーブルが返されます。Teredo アドレスが利用できない場合、または安定した状態にあり、かつその他のユニキャスト IP アドレスも安定した状態にある場合は、CallerCallback パラメーターで指定した関数は一切呼び出されません。

CallerCallback パラメーターで指定するコールバック関数は、VOID 型の関数として定義する必要があります。コールバック関数に渡されるパラメーターは次のとおりです。

パラメーター 説明
IN PVOID CallerContext 通知を登録する際に NotifyStableUnicastIpAddressTable 関数に渡された CallerContext パラメーターです。
IN PMIB_UNICASTIPADDRESS_TABLE AddressTable ローカルコンピューター上の安定したユニキャスト IP アドレステーブルを含む MIB_UNICASTIPADDRESS_TABLE へのポインターです。

CallerCallback パラメーターで指定するコールバック関数は、NotifyStableUnicastIpAddressTable 関数を呼び出すアプリケーションと同じプロセス内で実装する必要があります。コールバック関数が別の DLL 内にある場合は、変更通知を登録するために NotifyStableUnicastIpAddressTable 関数を呼び出す前にその DLL を読み込んでおく必要があります。

コールバック通知で使用される AddressTable パラメーターが指すメモリはオペレーティングシステムによって割り当てられます。通知を受け取るアプリケーションは、MIB_UNICASTIPADDRESS_TABLE の情報が不要になった時点で、FreeMibTable 関数を使用して AddressTable パラメーターが指すメモリを解放する必要があります。

変更通知を登録するために NotifyStableUnicastIpAddressTable 関数を一度呼び出すと、アプリケーションが変更通知の登録を解除するか、アプリケーションが終了するまで、これらの通知は送信され続けます。アプリケーションが終了した場合、システムは変更通知の登録を自動的に解除します。ただし、アプリケーションは終了する前に変更通知を明示的に登録解除することが推奨されます。

変更通知の登録は、システムのシャットダウンや再起動を行うと保持されません。

変更通知の登録を解除するには、NotifyStableUnicastIpAddressTable が返した NotificationHandle パラメーターを渡して CancelMibChangeNotify2 関数を呼び出します。

アプリケーションは、同じ NotificationHandle パラメーターに対する通知コールバック関数を現在実行しているスレッドのコンテキストから CancelMibChangeNotify2 関数を呼び出すことはできません。これを行うと、そのコールバックを実行しているスレッドはデッドロックに陥ります。したがって、CancelMibChangeNotify2 関数を通知コールバックルーチンの一部として直接呼び出してはいけません。より一般的に言えば、CancelMibChangeNotify2 関数を実行するスレッドは、通知コールバック処理を実行するスレッドが待機するリソースを所有することはできません。所有すると同様のデッドロックが発生するためです。CancelMibChangeNotify2 関数は、通知コールバックを受け取るスレッドが依存関係を持たない別のスレッドから呼び出す必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

WIN32_ERROR NotifyStableUnicastIpAddressTable(
    ADDRESS_FAMILY Family,
    MIB_UNICASTIPADDRESS_TABLE** Table,
    PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK CallerCallback,
    void* CallerContext,
    HANDLE* NotificationHandle
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint NotifyStableUnicastIpAddressTable(
    ushort Family,   // ADDRESS_FAMILY
    IntPtr Table,   // MIB_UNICASTIPADDRESS_TABLE** out
    IntPtr CallerCallback,   // PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
    IntPtr CallerContext,   // void*
    IntPtr NotificationHandle   // HANDLE* in/out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function NotifyStableUnicastIpAddressTable(
    Family As UShort,   ' ADDRESS_FAMILY
    Table As IntPtr,   ' MIB_UNICASTIPADDRESS_TABLE** out
    CallerCallback As IntPtr,   ' PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
    CallerContext As IntPtr,   ' void*
    NotificationHandle As IntPtr   ' HANDLE* in/out
) As UInteger
End Function
' Family : ADDRESS_FAMILY
' Table : MIB_UNICASTIPADDRESS_TABLE** out
' CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
' CallerContext : void*
' NotificationHandle : HANDLE* in/out
Declare PtrSafe Function NotifyStableUnicastIpAddressTable Lib "iphlpapi" ( _
    ByVal Family As Integer, _
    ByVal Table As LongPtr, _
    ByVal CallerCallback As LongPtr, _
    ByVal CallerContext As LongPtr, _
    ByVal NotificationHandle As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

NotifyStableUnicastIpAddressTable = ctypes.windll.iphlpapi.NotifyStableUnicastIpAddressTable
NotifyStableUnicastIpAddressTable.restype = wintypes.DWORD
NotifyStableUnicastIpAddressTable.argtypes = [
    ctypes.c_ushort,  # Family : ADDRESS_FAMILY
    ctypes.c_void_p,  # Table : MIB_UNICASTIPADDRESS_TABLE** out
    ctypes.c_void_p,  # CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
    ctypes.POINTER(None),  # CallerContext : void*
    ctypes.c_void_p,  # NotificationHandle : HANDLE* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
NotifyStableUnicastIpAddressTable = Fiddle::Function.new(
  lib['NotifyStableUnicastIpAddressTable'],
  [
    -Fiddle::TYPE_SHORT,  # Family : ADDRESS_FAMILY
    Fiddle::TYPE_VOIDP,  # Table : MIB_UNICASTIPADDRESS_TABLE** out
    Fiddle::TYPE_VOIDP,  # CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
    Fiddle::TYPE_VOIDP,  # CallerContext : void*
    Fiddle::TYPE_VOIDP,  # NotificationHandle : HANDLE* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn NotifyStableUnicastIpAddressTable(
        Family: u16,  // ADDRESS_FAMILY
        Table: *mut *mut MIB_UNICASTIPADDRESS_TABLE,  // MIB_UNICASTIPADDRESS_TABLE** out
        CallerCallback: *const core::ffi::c_void,  // PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
        CallerContext: *mut (),  // void*
        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 NotifyStableUnicastIpAddressTable(ushort Family, IntPtr Table, IntPtr CallerCallback, IntPtr CallerContext, IntPtr NotificationHandle);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_NotifyStableUnicastIpAddressTable' -Namespace Win32 -PassThru
# $api::NotifyStableUnicastIpAddressTable(Family, Table, CallerCallback, CallerContext, NotificationHandle)
#uselib "IPHLPAPI.dll"
#func global NotifyStableUnicastIpAddressTable "NotifyStableUnicastIpAddressTable" sptr, sptr, sptr, sptr, sptr
; NotifyStableUnicastIpAddressTable Family, varptr(Table), CallerCallback, CallerContext, NotificationHandle   ; 戻り値は stat
; Family : ADDRESS_FAMILY -> "sptr"
; Table : MIB_UNICASTIPADDRESS_TABLE** out -> "sptr"
; CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> "sptr"
; CallerContext : void* -> "sptr"
; NotificationHandle : HANDLE* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "IPHLPAPI.dll"
#cfunc global NotifyStableUnicastIpAddressTable "NotifyStableUnicastIpAddressTable" int, var, sptr, sptr, sptr
; res = NotifyStableUnicastIpAddressTable(Family, Table, CallerCallback, CallerContext, NotificationHandle)
; Family : ADDRESS_FAMILY -> "int"
; Table : MIB_UNICASTIPADDRESS_TABLE** out -> "var"
; CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> "sptr"
; CallerContext : void* -> "sptr"
; NotificationHandle : HANDLE* in/out -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR NotifyStableUnicastIpAddressTable(ADDRESS_FAMILY Family, MIB_UNICASTIPADDRESS_TABLE** Table, PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK CallerCallback, void* CallerContext, HANDLE* NotificationHandle)
#uselib "IPHLPAPI.dll"
#cfunc global NotifyStableUnicastIpAddressTable "NotifyStableUnicastIpAddressTable" int, var, intptr, intptr, intptr
; res = NotifyStableUnicastIpAddressTable(Family, Table, CallerCallback, CallerContext, NotificationHandle)
; Family : ADDRESS_FAMILY -> "int"
; Table : MIB_UNICASTIPADDRESS_TABLE** out -> "var"
; CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> "intptr"
; CallerContext : void* -> "intptr"
; NotificationHandle : HANDLE* in/out -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procNotifyStableUnicastIpAddressTable = iphlpapi.NewProc("NotifyStableUnicastIpAddressTable")
)

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

extern "iphlpapi" fn NotifyStableUnicastIpAddressTable(
    Family: u16, // ADDRESS_FAMILY
    Table: [*c][*c]MIB_UNICASTIPADDRESS_TABLE, // MIB_UNICASTIPADDRESS_TABLE** out
    CallerCallback: ?*anyopaque, // PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
    CallerContext: ?*anyopaque, // void*
    NotificationHandle: ?*anyopaque // HANDLE* in/out
) callconv(std.os.windows.WINAPI) u32;
proc NotifyStableUnicastIpAddressTable(
    Family: uint16,  # ADDRESS_FAMILY
    Table: ptr MIB_UNICASTIPADDRESS_TABLE,  # MIB_UNICASTIPADDRESS_TABLE** out
    CallerCallback: pointer,  # PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
    CallerContext: pointer,  # void*
    NotificationHandle: pointer  # HANDLE* in/out
): uint32 {.importc: "NotifyStableUnicastIpAddressTable", stdcall, dynlib: "IPHLPAPI.dll".}
pragma(lib, "iphlpapi");
extern(Windows)
uint NotifyStableUnicastIpAddressTable(
    ushort Family,   // ADDRESS_FAMILY
    MIB_UNICASTIPADDRESS_TABLE** Table,   // MIB_UNICASTIPADDRESS_TABLE** out
    void* CallerCallback,   // PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
    void* CallerContext,   // void*
    void* NotificationHandle   // HANDLE* in/out
);
ccall((:NotifyStableUnicastIpAddressTable, "IPHLPAPI.dll"), stdcall, UInt32,
      (UInt16, Ptr{MIB_UNICASTIPADDRESS_TABLE}, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
      Family, Table, CallerCallback, CallerContext, NotificationHandle)
# Family : ADDRESS_FAMILY -> UInt16
# Table : MIB_UNICASTIPADDRESS_TABLE** out -> Ptr{MIB_UNICASTIPADDRESS_TABLE}
# CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> Ptr{Cvoid}
# CallerContext : void* -> Ptr{Cvoid}
# NotificationHandle : HANDLE* in/out -> Ptr{Cvoid}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t NotifyStableUnicastIpAddressTable(
    uint16_t Family,
    void* Table,
    void* CallerCallback,
    void* CallerContext,
    void* NotificationHandle);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.NotifyStableUnicastIpAddressTable(Family, Table, CallerCallback, CallerContext, NotificationHandle)
-- Family : ADDRESS_FAMILY
-- Table : MIB_UNICASTIPADDRESS_TABLE** out
-- CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
-- CallerContext : void*
-- NotificationHandle : HANDLE* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const NotifyStableUnicastIpAddressTable = lib.func('__stdcall', 'NotifyStableUnicastIpAddressTable', 'uint32_t', ['uint16_t', 'void *', 'void *', 'void *', 'void *']);
// NotifyStableUnicastIpAddressTable(Family, Table, CallerCallback, CallerContext, NotificationHandle)
// Family : ADDRESS_FAMILY -> 'uint16_t'
// Table : MIB_UNICASTIPADDRESS_TABLE** out -> 'void *'
// CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> 'void *'
// CallerContext : void* -> 'void *'
// NotificationHandle : HANDLE* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
// コールバック(関数ポインタ)は koffi.proto/koffi.register で型を定義して渡す(素の void* では JS 関数を渡せない)。
const lib = Deno.dlopen("IPHLPAPI.dll", {
  NotifyStableUnicastIpAddressTable: { parameters: ["u16", "pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.NotifyStableUnicastIpAddressTable(Family, Table, CallerCallback, CallerContext, NotificationHandle)
// Family : ADDRESS_FAMILY -> "u16"
// Table : MIB_UNICASTIPADDRESS_TABLE** out -> "pointer"
// CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> "pointer"
// CallerContext : void* -> "pointer"
// NotificationHandle : HANDLE* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t NotifyStableUnicastIpAddressTable(
    uint16_t Family,
    void* Table,
    void* CallerCallback,
    void* CallerContext,
    void* NotificationHandle);
C, "IPHLPAPI.dll");
// $ffi->NotifyStableUnicastIpAddressTable(Family, Table, CallerCallback, CallerContext, NotificationHandle);
// Family : ADDRESS_FAMILY
// Table : MIB_UNICASTIPADDRESS_TABLE** out
// CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
// CallerContext : void*
// 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 NotifyStableUnicastIpAddressTable(
        short Family,   // ADDRESS_FAMILY
        Pointer Table,   // MIB_UNICASTIPADDRESS_TABLE** out
        Callback CallerCallback,   // PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
        Pointer CallerContext,   // void*
        Pointer NotificationHandle   // HANDLE* in/out
    );
}
@[Link("iphlpapi")]
lib LibIPHLPAPI
  fun NotifyStableUnicastIpAddressTable = NotifyStableUnicastIpAddressTable(
    Family : UInt16,   # ADDRESS_FAMILY
    Table : MIB_UNICASTIPADDRESS_TABLE**,   # MIB_UNICASTIPADDRESS_TABLE** out
    CallerCallback : Void*,   # PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
    CallerContext : Void*,   # void*
    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 NotifyStableUnicastIpAddressTableNative = Uint32 Function(Uint16, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef NotifyStableUnicastIpAddressTableDart = int Function(int, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final NotifyStableUnicastIpAddressTable = DynamicLibrary.open('IPHLPAPI.dll')
    .lookupFunction<NotifyStableUnicastIpAddressTableNative, NotifyStableUnicastIpAddressTableDart>('NotifyStableUnicastIpAddressTable');
// Family : ADDRESS_FAMILY -> Uint16
// Table : MIB_UNICASTIPADDRESS_TABLE** out -> Pointer<Void>
// CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> Pointer<Void>
// CallerContext : void* -> Pointer<Void>
// NotificationHandle : HANDLE* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function NotifyStableUnicastIpAddressTable(
  Family: Word;   // ADDRESS_FAMILY
  Table: Pointer;   // MIB_UNICASTIPADDRESS_TABLE** out
  CallerCallback: Pointer;   // PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
  CallerContext: Pointer;   // void*
  NotificationHandle: Pointer   // HANDLE* in/out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'NotifyStableUnicastIpAddressTable';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "NotifyStableUnicastIpAddressTable"
  c_NotifyStableUnicastIpAddressTable :: Word16 -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO Word32
-- Family : ADDRESS_FAMILY -> Word16
-- Table : MIB_UNICASTIPADDRESS_TABLE** out -> Ptr ()
-- CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> Ptr ()
-- CallerContext : void* -> Ptr ()
-- NotificationHandle : HANDLE* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let notifystableunicastipaddresstable =
  foreign "NotifyStableUnicastIpAddressTable"
    (uint16_t @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* Family : ADDRESS_FAMILY -> uint16_t *)
(* Table : MIB_UNICASTIPADDRESS_TABLE** out -> (ptr void) *)
(* CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> (ptr void) *)
(* CallerContext : void* -> (ptr void) *)
(* 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 ("NotifyStableUnicastIpAddressTable" notify-stable-unicast-ip-address-table :convention :stdcall) :uint32
  (family :uint16)   ; ADDRESS_FAMILY
  (table :pointer)   ; MIB_UNICASTIPADDRESS_TABLE** out
  (caller-callback :pointer)   ; PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK
  (caller-context :pointer)   ; void*
  (notification-handle :pointer))   ; HANDLE* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $NotifyStableUnicastIpAddressTable = Win32::API::More->new('IPHLPAPI',
    'DWORD NotifyStableUnicastIpAddressTable(WORD Family, LPVOID Table, LPVOID CallerCallback, LPVOID CallerContext, HANDLE NotificationHandle)');
# my $ret = $NotifyStableUnicastIpAddressTable->Call($Family, $Table, $CallerCallback, $CallerContext, $NotificationHandle);
# Family : ADDRESS_FAMILY -> WORD
# Table : MIB_UNICASTIPADDRESS_TABLE** out -> LPVOID
# CallerCallback : PSTABLE_UNICAST_IPADDRESS_TABLE_CALLBACK -> LPVOID
# CallerContext : void* -> LPVOID
# NotificationHandle : HANDLE* in/out -> HANDLE
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

公式の関連項目
使用する型