ホーム › NetworkManagement.IpHelper › ConvertInterfaceLuidToIndex
ConvertInterfaceLuidToIndex
関数インターフェイスLUIDをインターフェイス索引に変換する。
シグネチャ
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR ConvertInterfaceLuidToIndex(
const NET_LUID_LH* InterfaceLuid,
DWORD* InterfaceIndex
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| InterfaceLuid | NET_LUID_LH* | in | ネットワークインターフェイスの NET_LUID へのポインターです。 |
| InterfaceIndex | DWORD* | out | インターフェイスのローカルインデックス値です。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
ネットワークインターフェイスのローカル一意識別子 (LUID) を、そのインターフェイスのローカルインデックスに変換します。
戻り値
成功した場合、 ConvertInterfaceLuidToIndex は NO_ERROR を返します。0 以外の戻り値はすべて失敗を示し、InterfaceIndex パラメーターには NET_IFINDEX_UNSPECIFIED が返されます。
| エラーコード | 意味 |
|---|---|
| いずれかのパラメーターが無効でした。このエラーは、InterfaceLuid または InterfaceIndex パラメーターが NULL であった場合、もしくは InterfaceLuid パラメーターが無効であった場合に返されます。 |
解説(Remarks)
ConvertInterfaceLuidToIndex 関数は、Windows Vista 以降で使用できます。
ConvertInterfaceLuidToIndex 関数はプロトコルに依存せず、IPv6 と IPv4 の両方のプロトコルのネットワークインターフェイスで動作します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global ConvertInterfaceLuidToIndex "ConvertInterfaceLuidToIndex" sptr, sptr ; res = ConvertInterfaceLuidToIndex(varptr(InterfaceLuid), varptr(InterfaceIndex)) ; InterfaceLuid : NET_LUID_LH* -> "sptr" ; InterfaceIndex : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; WIN32_ERROR ConvertInterfaceLuidToIndex(NET_LUID_LH* InterfaceLuid, DWORD* InterfaceIndex) #uselib "IPHLPAPI.dll" #cfunc global ConvertInterfaceLuidToIndex "ConvertInterfaceLuidToIndex" intptr, intptr ; res = ConvertInterfaceLuidToIndex(varptr(InterfaceLuid), varptr(InterfaceIndex)) ; InterfaceLuid : NET_LUID_LH* -> "intptr" ; InterfaceIndex : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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_ERRORfunction 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)。const std = @import("std");
extern "iphlpapi" fn ConvertInterfaceLuidToIndex(
InterfaceLuid: [*c]NET_LUID_LH, // NET_LUID_LH*
InterfaceIndex: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) u32;proc ConvertInterfaceLuidToIndex(
InterfaceLuid: ptr NET_LUID_LH, # NET_LUID_LH*
InterfaceIndex: ptr uint32 # DWORD* out
): uint32 {.importc: "ConvertInterfaceLuidToIndex", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint ConvertInterfaceLuidToIndex(
NET_LUID_LH* InterfaceLuid, // NET_LUID_LH*
uint* InterfaceIndex // DWORD* out
);ccall((:ConvertInterfaceLuidToIndex, "IPHLPAPI.dll"), stdcall, UInt32,
(Ptr{NET_LUID_LH}, Ptr{UInt32}),
InterfaceLuid, InterfaceIndex)
# InterfaceLuid : NET_LUID_LH* -> Ptr{NET_LUID_LH}
# InterfaceIndex : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t ConvertInterfaceLuidToIndex(
void* InterfaceLuid,
uint32_t* InterfaceIndex);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.ConvertInterfaceLuidToIndex(InterfaceLuid, InterfaceIndex)
-- InterfaceLuid : NET_LUID_LH*
-- InterfaceIndex : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const ConvertInterfaceLuidToIndex = lib.func('__stdcall', 'ConvertInterfaceLuidToIndex', 'uint32_t', ['void *', 'uint32_t *']);
// ConvertInterfaceLuidToIndex(InterfaceLuid, InterfaceIndex)
// InterfaceLuid : NET_LUID_LH* -> 'void *'
// InterfaceIndex : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
ConvertInterfaceLuidToIndex: { parameters: ["pointer", "pointer"], result: "u32" },
});
// lib.symbols.ConvertInterfaceLuidToIndex(InterfaceLuid, InterfaceIndex)
// InterfaceLuid : NET_LUID_LH* -> "pointer"
// InterfaceIndex : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t ConvertInterfaceLuidToIndex(
void* InterfaceLuid,
uint32_t* InterfaceIndex);
C, "IPHLPAPI.dll");
// $ffi->ConvertInterfaceLuidToIndex(InterfaceLuid, InterfaceIndex);
// InterfaceLuid : NET_LUID_LH*
// InterfaceIndex : DWORD* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Iphlpapi extends StdCallLibrary {
Iphlpapi INSTANCE = Native.load("iphlpapi", Iphlpapi.class);
int ConvertInterfaceLuidToIndex(
Pointer InterfaceLuid, // NET_LUID_LH*
IntByReference InterfaceIndex // DWORD* out
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun ConvertInterfaceLuidToIndex = ConvertInterfaceLuidToIndex(
InterfaceLuid : NET_LUID_LH*, # NET_LUID_LH*
InterfaceIndex : UInt32* # DWORD* out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ConvertInterfaceLuidToIndexNative = Uint32 Function(Pointer<Void>, Pointer<Uint32>);
typedef ConvertInterfaceLuidToIndexDart = int Function(Pointer<Void>, Pointer<Uint32>);
final ConvertInterfaceLuidToIndex = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<ConvertInterfaceLuidToIndexNative, ConvertInterfaceLuidToIndexDart>('ConvertInterfaceLuidToIndex');
// InterfaceLuid : NET_LUID_LH* -> Pointer<Void>
// InterfaceIndex : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ConvertInterfaceLuidToIndex(
InterfaceLuid: Pointer; // NET_LUID_LH*
InterfaceIndex: Pointer // DWORD* out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'ConvertInterfaceLuidToIndex';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ConvertInterfaceLuidToIndex"
c_ConvertInterfaceLuidToIndex :: Ptr () -> Ptr Word32 -> IO Word32
-- InterfaceLuid : NET_LUID_LH* -> Ptr ()
-- InterfaceIndex : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let convertinterfaceluidtoindex =
foreign "ConvertInterfaceLuidToIndex"
((ptr void) @-> (ptr uint32_t) @-> returning uint32_t)
(* InterfaceLuid : NET_LUID_LH* -> (ptr void) *)
(* InterfaceIndex : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)
(cffi:defcfun ("ConvertInterfaceLuidToIndex" convert-interface-luid-to-index :convention :stdcall) :uint32
(interface-luid :pointer) ; NET_LUID_LH*
(interface-index :pointer)) ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ConvertInterfaceLuidToIndex = Win32::API::More->new('IPHLPAPI',
'DWORD ConvertInterfaceLuidToIndex(LPVOID InterfaceLuid, LPVOID InterfaceIndex)');
# my $ret = $ConvertInterfaceLuidToIndex->Call($InterfaceLuid, $InterfaceIndex);
# InterfaceLuid : NET_LUID_LH* -> LPVOID
# InterfaceIndex : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- f ConvertInterfaceAliasToLuid — インターフェイスのエイリアス(別名)をLUIDに変換する。
- f ConvertInterfaceGuidToLuid — インターフェイスGUIDをLUIDに変換する。
- f ConvertInterfaceIndexToLuid — インターフェイス索引をLUIDに変換する。
- f ConvertInterfaceLuidToAlias — インターフェイスLUIDをエイリアス(別名)に変換する。
- f ConvertInterfaceLuidToGuid — インターフェイスLUIDをGUIDに変換する。
- f ConvertInterfaceLuidToNameW — インターフェイスLUIDを名前(Unicode)に変換する。
- f ConvertInterfaceNameToLuidW — インターフェイス名(Unicode)をLUIDに変換する。
- f if_indextoname — インターフェイスインデックスを対応するインターフェイス名に変換する。
- f if_nametoindex — ネットワークインターフェイス名を対応するインターフェイスインデックスに変換する。