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このインターフェイスの NET_LUID へのポインター。

戻り値の型: WIN32_ERROR

公式ドキュメント

ネットワークインターフェイスのローカルインデックスを、そのインターフェイスのローカル一意識別子 (LUID) に変換します。

戻り値

成功した場合、 ConvertInterfaceIndexToLuidNO_ERROR を返します。0 以外の戻り値はすべて失敗を示し、InterfaceLuid パラメーターには NULL が返されます。

エラーコード 意味
ERROR_FILE_NOT_FOUND
指定されたファイルが見つかりません。このエラーは、InterfaceIndex パラメーターで指定されたネットワークインターフェイスがローカルマシン上の値ではなかった場合に返されます。
ERROR_INVALID_PARAMETER
パラメーターのいずれかが無効でした。このエラーは、InterfaceLuid パラメーターが NULL であった場合、または InterfaceIndex パラメーターが無効であった場合に返されます。

解説(Remarks)

ConvertInterfaceIndexToLuid 関数は Windows Vista 以降で使用できます。

ConvertInterfaceIndexToLuid 関数はプロトコルに依存せず、IPv6 と IPv4 の両方のプロトコルのネットワークインターフェイスで機能します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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)。
const std = @import("std");

extern "iphlpapi" fn ConvertInterfaceIndexToLuid(
    InterfaceIndex: u32, // DWORD
    InterfaceLuid: [*c]NET_LUID_LH // NET_LUID_LH* out
) callconv(std.os.windows.WINAPI) u32;
proc ConvertInterfaceIndexToLuid(
    InterfaceIndex: uint32,  # DWORD
    InterfaceLuid: ptr NET_LUID_LH  # NET_LUID_LH* out
): uint32 {.importc: "ConvertInterfaceIndexToLuid", stdcall, dynlib: "IPHLPAPI.dll".}
pragma(lib, "iphlpapi");
extern(Windows)
uint ConvertInterfaceIndexToLuid(
    uint InterfaceIndex,   // DWORD
    NET_LUID_LH* InterfaceLuid   // NET_LUID_LH* out
);
ccall((:ConvertInterfaceIndexToLuid, "IPHLPAPI.dll"), stdcall, UInt32,
      (UInt32, Ptr{NET_LUID_LH}),
      InterfaceIndex, InterfaceLuid)
# InterfaceIndex : DWORD -> UInt32
# InterfaceLuid : NET_LUID_LH* out -> Ptr{NET_LUID_LH}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t ConvertInterfaceIndexToLuid(
    uint32_t InterfaceIndex,
    void* InterfaceLuid);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.ConvertInterfaceIndexToLuid(InterfaceIndex, InterfaceLuid)
-- InterfaceIndex : DWORD
-- InterfaceLuid : NET_LUID_LH* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const ConvertInterfaceIndexToLuid = lib.func('__stdcall', 'ConvertInterfaceIndexToLuid', 'uint32_t', ['uint32_t', 'void *']);
// ConvertInterfaceIndexToLuid(InterfaceIndex, InterfaceLuid)
// InterfaceIndex : DWORD -> 'uint32_t'
// InterfaceLuid : NET_LUID_LH* out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("IPHLPAPI.dll", {
  ConvertInterfaceIndexToLuid: { parameters: ["u32", "pointer"], result: "u32" },
});
// lib.symbols.ConvertInterfaceIndexToLuid(InterfaceIndex, InterfaceLuid)
// InterfaceIndex : DWORD -> "u32"
// InterfaceLuid : NET_LUID_LH* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t ConvertInterfaceIndexToLuid(
    uint32_t InterfaceIndex,
    void* InterfaceLuid);
C, "IPHLPAPI.dll");
// $ffi->ConvertInterfaceIndexToLuid(InterfaceIndex, InterfaceLuid);
// InterfaceIndex : DWORD
// InterfaceLuid : NET_LUID_LH* 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 ConvertInterfaceIndexToLuid(
        int InterfaceIndex,   // DWORD
        Pointer InterfaceLuid   // NET_LUID_LH* out
    );
}
@[Link("iphlpapi")]
lib LibIPHLPAPI
  fun ConvertInterfaceIndexToLuid = ConvertInterfaceIndexToLuid(
    InterfaceIndex : UInt32,   # DWORD
    InterfaceLuid : NET_LUID_LH*   # NET_LUID_LH* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef ConvertInterfaceIndexToLuidNative = Uint32 Function(Uint32, Pointer<Void>);
typedef ConvertInterfaceIndexToLuidDart = int Function(int, Pointer<Void>);
final ConvertInterfaceIndexToLuid = DynamicLibrary.open('IPHLPAPI.dll')
    .lookupFunction<ConvertInterfaceIndexToLuidNative, ConvertInterfaceIndexToLuidDart>('ConvertInterfaceIndexToLuid');
// InterfaceIndex : DWORD -> Uint32
// InterfaceLuid : NET_LUID_LH* out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function ConvertInterfaceIndexToLuid(
  InterfaceIndex: DWORD;   // DWORD
  InterfaceLuid: Pointer   // NET_LUID_LH* out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'ConvertInterfaceIndexToLuid';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "ConvertInterfaceIndexToLuid"
  c_ConvertInterfaceIndexToLuid :: Word32 -> Ptr () -> IO Word32
-- InterfaceIndex : DWORD -> Word32
-- InterfaceLuid : NET_LUID_LH* out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let convertinterfaceindextoluid =
  foreign "ConvertInterfaceIndexToLuid"
    (uint32_t @-> (ptr void) @-> returning uint32_t)
(* InterfaceIndex : DWORD -> uint32_t *)
(* InterfaceLuid : NET_LUID_LH* out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)

(cffi:defcfun ("ConvertInterfaceIndexToLuid" convert-interface-index-to-luid :convention :stdcall) :uint32
  (interface-index :uint32)   ; DWORD
  (interface-luid :pointer))   ; NET_LUID_LH* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ConvertInterfaceIndexToLuid = Win32::API::More->new('IPHLPAPI',
    'DWORD ConvertInterfaceIndexToLuid(DWORD InterfaceIndex, LPVOID InterfaceLuid)');
# my $ret = $ConvertInterfaceIndexToLuid->Call($InterfaceIndex, $InterfaceLuid);
# InterfaceIndex : DWORD -> DWORD
# InterfaceLuid : NET_LUID_LH* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目
使用する型