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

ConvertInterfaceIndexToLuid

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

シグネチャ

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

WIN32_ERROR ConvertInterfaceIndexToLuid(
    DWORD InterfaceIndex,
    NET_LUID_LH* InterfaceLuid
);

パラメーター

名前方向
InterfaceIndexDWORDin
InterfaceLuidNET_LUID_LH*out

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

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

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

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

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procConvertInterfaceIndexToLuid = iphlpapi.NewProc("ConvertInterfaceIndexToLuid")
)

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