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

ConvertInterfaceLuidToIndex

関数
インターフェイスLUIDをインターフェイス索引に変換する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

WIN32_ERROR ConvertInterfaceLuidToIndex(
    const NET_LUID_LH* InterfaceLuid,
    DWORD* InterfaceIndex
);

パラメーター

名前方向
InterfaceLuidNET_LUID_LH*in
InterfaceIndexDWORD*out

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR ConvertInterfaceLuidToIndex(
    const NET_LUID_LH* InterfaceLuid,
    DWORD* InterfaceIndex
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint ConvertInterfaceLuidToIndex(
    IntPtr InterfaceLuid,   // NET_LUID_LH*
    out uint InterfaceIndex   // DWORD* out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function ConvertInterfaceLuidToIndex(
    InterfaceLuid As IntPtr,   ' NET_LUID_LH*
    <Out> ByRef InterfaceIndex As UInteger   ' DWORD* out
) As UInteger
End Function
' InterfaceLuid : NET_LUID_LH*
' InterfaceIndex : DWORD* out
Declare PtrSafe Function ConvertInterfaceLuidToIndex Lib "iphlpapi" ( _
    ByVal InterfaceLuid As LongPtr, _
    ByRef InterfaceIndex As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ConvertInterfaceLuidToIndex = ctypes.windll.iphlpapi.ConvertInterfaceLuidToIndex
ConvertInterfaceLuidToIndex.restype = wintypes.DWORD
ConvertInterfaceLuidToIndex.argtypes = [
    ctypes.c_void_p,  # InterfaceLuid : NET_LUID_LH*
    ctypes.POINTER(wintypes.DWORD),  # InterfaceIndex : DWORD* out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procConvertInterfaceLuidToIndex = iphlpapi.NewProc("ConvertInterfaceLuidToIndex")
)

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