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

GetIfEntry2Ex

関数
指定レベルでネットワークインターフェイスの詳細情報を取得する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows 10 以降

シグネチャ

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

WIN32_ERROR GetIfEntry2Ex(
    MIB_IF_ENTRY_LEVEL Level,
    MIB_IF_ROW2* Row
);

パラメーター

名前方向
LevelMIB_IF_ENTRY_LEVELin
RowMIB_IF_ROW2*inout

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR GetIfEntry2Ex(
    MIB_IF_ENTRY_LEVEL Level,
    MIB_IF_ROW2* Row
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetIfEntry2Ex(
    int Level,   // MIB_IF_ENTRY_LEVEL
    IntPtr Row   // MIB_IF_ROW2* in/out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetIfEntry2Ex(
    Level As Integer,   ' MIB_IF_ENTRY_LEVEL
    Row As IntPtr   ' MIB_IF_ROW2* in/out
) As UInteger
End Function
' Level : MIB_IF_ENTRY_LEVEL
' Row : MIB_IF_ROW2* in/out
Declare PtrSafe Function GetIfEntry2Ex Lib "iphlpapi" ( _
    ByVal Level As Long, _
    ByVal Row As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetIfEntry2Ex = ctypes.windll.iphlpapi.GetIfEntry2Ex
GetIfEntry2Ex.restype = wintypes.DWORD
GetIfEntry2Ex.argtypes = [
    ctypes.c_int,  # Level : MIB_IF_ENTRY_LEVEL
    ctypes.c_void_p,  # Row : MIB_IF_ROW2* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
GetIfEntry2Ex = Fiddle::Function.new(
  lib['GetIfEntry2Ex'],
  [
    Fiddle::TYPE_INT,  # Level : MIB_IF_ENTRY_LEVEL
    Fiddle::TYPE_VOIDP,  # Row : MIB_IF_ROW2* in/out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn GetIfEntry2Ex(
        Level: i32,  // MIB_IF_ENTRY_LEVEL
        Row: *mut MIB_IF_ROW2  // MIB_IF_ROW2* in/out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint GetIfEntry2Ex(int Level, IntPtr Row);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetIfEntry2Ex' -Namespace Win32 -PassThru
# $api::GetIfEntry2Ex(Level, Row)
#uselib "IPHLPAPI.dll"
#func global GetIfEntry2Ex "GetIfEntry2Ex" sptr, sptr
; GetIfEntry2Ex Level, varptr(Row)   ; 戻り値は stat
; Level : MIB_IF_ENTRY_LEVEL -> "sptr"
; Row : MIB_IF_ROW2* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "IPHLPAPI.dll"
#cfunc global GetIfEntry2Ex "GetIfEntry2Ex" int, var
; res = GetIfEntry2Ex(Level, Row)
; Level : MIB_IF_ENTRY_LEVEL -> "int"
; Row : MIB_IF_ROW2* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR GetIfEntry2Ex(MIB_IF_ENTRY_LEVEL Level, MIB_IF_ROW2* Row)
#uselib "IPHLPAPI.dll"
#cfunc global GetIfEntry2Ex "GetIfEntry2Ex" int, var
; res = GetIfEntry2Ex(Level, Row)
; Level : MIB_IF_ENTRY_LEVEL -> "int"
; Row : MIB_IF_ROW2* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procGetIfEntry2Ex = iphlpapi.NewProc("GetIfEntry2Ex")
)

// Level (MIB_IF_ENTRY_LEVEL), Row (MIB_IF_ROW2* in/out)
r1, _, err := procGetIfEntry2Ex.Call(
	uintptr(Level),
	uintptr(Row),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function GetIfEntry2Ex(
  Level: Integer;   // MIB_IF_ENTRY_LEVEL
  Row: Pointer   // MIB_IF_ROW2* in/out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'GetIfEntry2Ex';
result := DllCall("IPHLPAPI\GetIfEntry2Ex"
    , "Int", Level   ; MIB_IF_ENTRY_LEVEL
    , "Ptr", Row   ; MIB_IF_ROW2* in/out
    , "UInt")   ; return: WIN32_ERROR
●GetIfEntry2Ex(Level, Row) = DLL("IPHLPAPI.dll", "dword GetIfEntry2Ex(int, void*)")
# 呼び出し: GetIfEntry2Ex(Level, Row)
# Level : MIB_IF_ENTRY_LEVEL -> "int"
# Row : MIB_IF_ROW2* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。