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