ホーム › NetworkManagement.IpHelper › GetIfTable
GetIfTable
関数ローカルマシンのネットワークインターフェイス一覧をMIB_IFTABLEで取得する。
シグネチャ
// IPHLPAPI.dll
#include <windows.h>
DWORD GetIfTable(
MIB_IFTABLE* pIfTable, // optional
DWORD* pdwSize,
BOOL bOrder
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pIfTable | MIB_IFTABLE* | outoptional |
| pdwSize | DWORD* | inout |
| bOrder | BOOL | in |
戻り値の型: DWORD
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
DWORD GetIfTable(
MIB_IFTABLE* pIfTable, // optional
DWORD* pdwSize,
BOOL bOrder
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetIfTable(
IntPtr pIfTable, // MIB_IFTABLE* optional, out
ref uint pdwSize, // DWORD* in/out
bool bOrder // BOOL
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetIfTable(
pIfTable As IntPtr, ' MIB_IFTABLE* optional, out
ByRef pdwSize As UInteger, ' DWORD* in/out
bOrder As Boolean ' BOOL
) As UInteger
End Function' pIfTable : MIB_IFTABLE* optional, out
' pdwSize : DWORD* in/out
' bOrder : BOOL
Declare PtrSafe Function GetIfTable Lib "iphlpapi" ( _
ByVal pIfTable As LongPtr, _
ByRef pdwSize As Long, _
ByVal bOrder As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetIfTable = ctypes.windll.iphlpapi.GetIfTable
GetIfTable.restype = wintypes.DWORD
GetIfTable.argtypes = [
ctypes.c_void_p, # pIfTable : MIB_IFTABLE* optional, out
ctypes.POINTER(wintypes.DWORD), # pdwSize : DWORD* in/out
wintypes.BOOL, # bOrder : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
GetIfTable = Fiddle::Function.new(
lib['GetIfTable'],
[
Fiddle::TYPE_VOIDP, # pIfTable : MIB_IFTABLE* optional, out
Fiddle::TYPE_VOIDP, # pdwSize : DWORD* in/out
Fiddle::TYPE_INT, # bOrder : BOOL
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn GetIfTable(
pIfTable: *mut MIB_IFTABLE, // MIB_IFTABLE* optional, out
pdwSize: *mut u32, // DWORD* in/out
bOrder: i32 // BOOL
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint GetIfTable(IntPtr pIfTable, ref uint pdwSize, bool bOrder);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetIfTable' -Namespace Win32 -PassThru
# $api::GetIfTable(pIfTable, pdwSize, bOrder)#uselib "IPHLPAPI.dll"
#func global GetIfTable "GetIfTable" sptr, sptr, sptr
; GetIfTable varptr(pIfTable), varptr(pdwSize), bOrder ; 戻り値は stat
; pIfTable : MIB_IFTABLE* optional, out -> "sptr"
; pdwSize : DWORD* in/out -> "sptr"
; bOrder : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "IPHLPAPI.dll" #cfunc global GetIfTable "GetIfTable" var, var, int ; res = GetIfTable(pIfTable, pdwSize, bOrder) ; pIfTable : MIB_IFTABLE* optional, out -> "var" ; pdwSize : DWORD* in/out -> "var" ; bOrder : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global GetIfTable "GetIfTable" sptr, sptr, int ; res = GetIfTable(varptr(pIfTable), varptr(pdwSize), bOrder) ; pIfTable : MIB_IFTABLE* optional, out -> "sptr" ; pdwSize : DWORD* in/out -> "sptr" ; bOrder : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD GetIfTable(MIB_IFTABLE* pIfTable, DWORD* pdwSize, BOOL bOrder) #uselib "IPHLPAPI.dll" #cfunc global GetIfTable "GetIfTable" var, var, int ; res = GetIfTable(pIfTable, pdwSize, bOrder) ; pIfTable : MIB_IFTABLE* optional, out -> "var" ; pdwSize : DWORD* in/out -> "var" ; bOrder : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD GetIfTable(MIB_IFTABLE* pIfTable, DWORD* pdwSize, BOOL bOrder) #uselib "IPHLPAPI.dll" #cfunc global GetIfTable "GetIfTable" intptr, intptr, int ; res = GetIfTable(varptr(pIfTable), varptr(pdwSize), bOrder) ; pIfTable : MIB_IFTABLE* optional, out -> "intptr" ; pdwSize : DWORD* in/out -> "intptr" ; bOrder : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procGetIfTable = iphlpapi.NewProc("GetIfTable")
)
// pIfTable (MIB_IFTABLE* optional, out), pdwSize (DWORD* in/out), bOrder (BOOL)
r1, _, err := procGetIfTable.Call(
uintptr(pIfTable),
uintptr(pdwSize),
uintptr(bOrder),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetIfTable(
pIfTable: Pointer; // MIB_IFTABLE* optional, out
pdwSize: Pointer; // DWORD* in/out
bOrder: BOOL // BOOL
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetIfTable';result := DllCall("IPHLPAPI\GetIfTable"
, "Ptr", pIfTable ; MIB_IFTABLE* optional, out
, "Ptr", pdwSize ; DWORD* in/out
, "Int", bOrder ; BOOL
, "UInt") ; return: DWORD●GetIfTable(pIfTable, pdwSize, bOrder) = DLL("IPHLPAPI.dll", "dword GetIfTable(void*, void*, bool)")
# 呼び出し: GetIfTable(pIfTable, pdwSize, bOrder)
# pIfTable : MIB_IFTABLE* optional, out -> "void*"
# pdwSize : DWORD* in/out -> "void*"
# bOrder : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。