ConvertInterfaceLuidToNameA
関数シグネチャ
// IPHLPAPI.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR ConvertInterfaceLuidToNameA(
const NET_LUID_LH* InterfaceLuid,
LPSTR InterfaceName,
UINT_PTR Length
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| InterfaceLuid | NET_LUID_LH* | in | ネットワークインターフェイスの NET_LUID へのポインター。 |
| InterfaceName | LPSTR | out | 関数が正常に返ったときに、インターフェイス名を含む NULL 終端の ANSI 文字列を格納するバッファーへのポインター。 |
| Length | UINT_PTR | in | InterfaceName パラメーターが指すバッファーの長さ (バイト単位)。この値は、インターフェイス名と終端の null 文字を格納できる十分な大きさである必要があります。必要となる最大の長さは NDIS_IF_MAX_STRING_SIZE + 1 です。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
ネットワークインターフェイスのローカル一意識別子 (LUID) を ANSI のインターフェイス名に変換します。
戻り値
成功した場合、 ConvertInterfaceLuidToNameA は NETIO_ERROR_SUCCESS を返します。0 以外の戻り値はいずれも失敗を示します。
| エラーコード | 意味 |
|---|---|
| パラメーターのいずれかが無効でした。このエラーは、InterfaceLuid または InterfaceName パラメーターが NULL であった場合、あるいは InterfaceLuid パラメーターが無効であった場合に返されます。 | |
| このコマンドを処理するために十分な記憶域がありません。このエラーは、InterfaceName パラメーターが指すバッファーのサイズが、Length パラメーターで指定されたとおりにインターフェイス名を格納するには十分な大きさでなかった場合に返されます。 |
解説(Remarks)
ConvertInterfaceLuidToNameA 関数は Windows Vista 以降で使用できます。
ConvertInterfaceLuidToNameA 関数はプロトコルに依存せず、IPv6 と IPv4 の両方のプロトコルのネットワークインターフェイスで動作します。ConvertInterfaceLuidToNameA は、ネットワークインターフェイスの LUID を ANSI のインターフェイス名に変換します。
ConvertInterfaceLuidToNameW は、ネットワークインターフェイスの LUID を Unicode のインターフェイス名に変換します。
終端の NULL を含まないインターフェイス名の最大長 NDIS_IF_MAX_STRING_SIZE は、Ntddndis.h ヘッダーファイルで宣言されています。NDIS_IF_MAX_STRING_SIZE は、Ifdef.h ヘッダーファイルで定義されている IF_MAX_STRING_SIZE 定数として定義されています。Ntddndis.h および Ifdef.h ヘッダーファイルは Netioapi.h ヘッダーファイルに自動的にインクルードされ、Netioapi.h は Iphlpapi.h ヘッダーファイルに自動的にインクルードされます。Ntddndis.h、Ifdef.h、および Netioapi.h ヘッダーファイルを直接使用することは決してしないでください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// IPHLPAPI.dll (ANSI / -A)
#include <windows.h>
WIN32_ERROR ConvertInterfaceLuidToNameA(
const NET_LUID_LH* InterfaceLuid,
LPSTR InterfaceName,
UINT_PTR Length
);[DllImport("IPHLPAPI.dll", CharSet = CharSet.Ansi, ExactSpelling = true)]
static extern uint ConvertInterfaceLuidToNameA(
IntPtr InterfaceLuid, // NET_LUID_LH*
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder InterfaceName, // LPSTR out
UIntPtr Length // UINT_PTR
);<DllImport("IPHLPAPI.dll", CharSet:=CharSet.Ansi, ExactSpelling:=True)>
Public Shared Function ConvertInterfaceLuidToNameA(
InterfaceLuid As IntPtr, ' NET_LUID_LH*
<MarshalAs(UnmanagedType.LPStr)> InterfaceName As System.Text.StringBuilder, ' LPSTR out
Length As UIntPtr ' UINT_PTR
) As UInteger
End Function' InterfaceLuid : NET_LUID_LH*
' InterfaceName : LPSTR out
' Length : UINT_PTR
Declare PtrSafe Function ConvertInterfaceLuidToNameA Lib "iphlpapi" ( _
ByVal InterfaceLuid As LongPtr, _
ByVal InterfaceName As String, _
ByVal Length As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
ConvertInterfaceLuidToNameA = ctypes.windll.iphlpapi.ConvertInterfaceLuidToNameA
ConvertInterfaceLuidToNameA.restype = wintypes.DWORD
ConvertInterfaceLuidToNameA.argtypes = [
ctypes.c_void_p, # InterfaceLuid : NET_LUID_LH*
wintypes.LPSTR, # InterfaceName : LPSTR out
ctypes.c_size_t, # Length : UINT_PTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
ConvertInterfaceLuidToNameA = Fiddle::Function.new(
lib['ConvertInterfaceLuidToNameA'],
[
Fiddle::TYPE_VOIDP, # InterfaceLuid : NET_LUID_LH*
Fiddle::TYPE_VOIDP, # InterfaceName : LPSTR out
Fiddle::TYPE_UINTPTR_T, # Length : UINT_PTR
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn ConvertInterfaceLuidToNameA(
InterfaceLuid: *const NET_LUID_LH, // NET_LUID_LH*
InterfaceName: *mut u8, // LPSTR out
Length: usize // UINT_PTR
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll", CharSet = CharSet.Ansi)]
public static extern uint ConvertInterfaceLuidToNameA(IntPtr InterfaceLuid, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder InterfaceName, UIntPtr Length);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_ConvertInterfaceLuidToNameA' -Namespace Win32 -PassThru
# $api::ConvertInterfaceLuidToNameA(InterfaceLuid, InterfaceName, Length)#uselib "IPHLPAPI.dll"
#func global ConvertInterfaceLuidToNameA "ConvertInterfaceLuidToNameA" sptr, sptr, sptr
; ConvertInterfaceLuidToNameA varptr(InterfaceLuid), varptr(InterfaceName), Length ; 戻り値は stat
; InterfaceLuid : NET_LUID_LH* -> "sptr"
; InterfaceName : LPSTR out -> "sptr"
; Length : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "IPHLPAPI.dll" #cfunc global ConvertInterfaceLuidToNameA "ConvertInterfaceLuidToNameA" var, var, sptr ; res = ConvertInterfaceLuidToNameA(InterfaceLuid, InterfaceName, Length) ; InterfaceLuid : NET_LUID_LH* -> "var" ; InterfaceName : LPSTR out -> "var" ; Length : UINT_PTR -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global ConvertInterfaceLuidToNameA "ConvertInterfaceLuidToNameA" sptr, sptr, sptr ; res = ConvertInterfaceLuidToNameA(varptr(InterfaceLuid), varptr(InterfaceName), Length) ; InterfaceLuid : NET_LUID_LH* -> "sptr" ; InterfaceName : LPSTR out -> "sptr" ; Length : UINT_PTR -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; WIN32_ERROR ConvertInterfaceLuidToNameA(NET_LUID_LH* InterfaceLuid, LPSTR InterfaceName, UINT_PTR Length) #uselib "IPHLPAPI.dll" #cfunc global ConvertInterfaceLuidToNameA "ConvertInterfaceLuidToNameA" var, var, intptr ; res = ConvertInterfaceLuidToNameA(InterfaceLuid, InterfaceName, Length) ; InterfaceLuid : NET_LUID_LH* -> "var" ; InterfaceName : LPSTR out -> "var" ; Length : UINT_PTR -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR ConvertInterfaceLuidToNameA(NET_LUID_LH* InterfaceLuid, LPSTR InterfaceName, UINT_PTR Length) #uselib "IPHLPAPI.dll" #cfunc global ConvertInterfaceLuidToNameA "ConvertInterfaceLuidToNameA" intptr, intptr, intptr ; res = ConvertInterfaceLuidToNameA(varptr(InterfaceLuid), varptr(InterfaceName), Length) ; InterfaceLuid : NET_LUID_LH* -> "intptr" ; InterfaceName : LPSTR out -> "intptr" ; Length : UINT_PTR -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procConvertInterfaceLuidToNameA = iphlpapi.NewProc("ConvertInterfaceLuidToNameA")
)
// InterfaceLuid (NET_LUID_LH*), InterfaceName (LPSTR out), Length (UINT_PTR)
r1, _, err := procConvertInterfaceLuidToNameA.Call(
uintptr(InterfaceLuid),
uintptr(InterfaceName),
uintptr(Length),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction ConvertInterfaceLuidToNameA(
InterfaceLuid: Pointer; // NET_LUID_LH*
InterfaceName: PAnsiChar; // LPSTR out
Length: NativeUInt // UINT_PTR
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'ConvertInterfaceLuidToNameA';result := DllCall("IPHLPAPI\ConvertInterfaceLuidToNameA"
, "Ptr", InterfaceLuid ; NET_LUID_LH*
, "Ptr", InterfaceName ; LPSTR out
, "UPtr", Length ; UINT_PTR
, "UInt") ; return: WIN32_ERROR●ConvertInterfaceLuidToNameA(InterfaceLuid, InterfaceName, Length) = DLL("IPHLPAPI.dll", "dword ConvertInterfaceLuidToNameA(void*, char*, int)")
# 呼び出し: ConvertInterfaceLuidToNameA(InterfaceLuid, InterfaceName, Length)
# InterfaceLuid : NET_LUID_LH* -> "void*"
# InterfaceName : LPSTR out -> "char*"
# Length : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "iphlpapi" fn ConvertInterfaceLuidToNameA(
InterfaceLuid: [*c]NET_LUID_LH, // NET_LUID_LH*
InterfaceName: [*c]u8, // LPSTR out
Length: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) u32;proc ConvertInterfaceLuidToNameA(
InterfaceLuid: ptr NET_LUID_LH, # NET_LUID_LH*
InterfaceName: ptr char, # LPSTR out
Length: uint # UINT_PTR
): uint32 {.importc: "ConvertInterfaceLuidToNameA", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint ConvertInterfaceLuidToNameA(
NET_LUID_LH* InterfaceLuid, // NET_LUID_LH*
char* InterfaceName, // LPSTR out
size_t Length // UINT_PTR
);ccall((:ConvertInterfaceLuidToNameA, "IPHLPAPI.dll"), stdcall, UInt32,
(Ptr{NET_LUID_LH}, Ptr{UInt8}, Csize_t),
InterfaceLuid, InterfaceName, Length)
# InterfaceLuid : NET_LUID_LH* -> Ptr{NET_LUID_LH}
# InterfaceName : LPSTR out -> Ptr{UInt8}
# Length : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t ConvertInterfaceLuidToNameA(
void* InterfaceLuid,
char* InterfaceName,
uintptr_t Length);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.ConvertInterfaceLuidToNameA(InterfaceLuid, InterfaceName, Length)
-- InterfaceLuid : NET_LUID_LH*
-- InterfaceName : LPSTR out
-- Length : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const ConvertInterfaceLuidToNameA = lib.func('__stdcall', 'ConvertInterfaceLuidToNameA', 'uint32_t', ['void *', 'char *', 'uintptr_t']);
// ConvertInterfaceLuidToNameA(InterfaceLuid, InterfaceName, Length)
// InterfaceLuid : NET_LUID_LH* -> 'void *'
// InterfaceName : LPSTR out -> 'char *'
// Length : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
ConvertInterfaceLuidToNameA: { parameters: ["pointer", "buffer", "usize"], result: "u32" },
});
// lib.symbols.ConvertInterfaceLuidToNameA(InterfaceLuid, InterfaceName, Length)
// InterfaceLuid : NET_LUID_LH* -> "pointer"
// InterfaceName : LPSTR out -> "buffer"
// Length : UINT_PTR -> "usize"
// 文字列は "buffer"。ANSI(-A) は new TextEncoder() で UTF-8/ANSI バイト列(末尾に \x00)を渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t ConvertInterfaceLuidToNameA(
void* InterfaceLuid,
char* InterfaceName,
size_t Length);
C, "IPHLPAPI.dll");
// $ffi->ConvertInterfaceLuidToNameA(InterfaceLuid, InterfaceName, Length);
// InterfaceLuid : NET_LUID_LH*
// InterfaceName : LPSTR out
// Length : UINT_PTR
// 構造体/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, W32APIOptions.ASCII_OPTIONS);
int ConvertInterfaceLuidToNameA(
Pointer InterfaceLuid, // NET_LUID_LH*
byte[] InterfaceName, // LPSTR out
long Length // UINT_PTR
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun ConvertInterfaceLuidToNameA = ConvertInterfaceLuidToNameA(
InterfaceLuid : NET_LUID_LH*, # NET_LUID_LH*
InterfaceName : UInt8*, # LPSTR out
Length : LibC::SizeT # UINT_PTR
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef ConvertInterfaceLuidToNameANative = Uint32 Function(Pointer<Void>, Pointer<Utf8>, UintPtr);
typedef ConvertInterfaceLuidToNameADart = int Function(Pointer<Void>, Pointer<Utf8>, int);
final ConvertInterfaceLuidToNameA = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<ConvertInterfaceLuidToNameANative, ConvertInterfaceLuidToNameADart>('ConvertInterfaceLuidToNameA');
// InterfaceLuid : NET_LUID_LH* -> Pointer<Void>
// InterfaceName : LPSTR out -> Pointer<Utf8>
// Length : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ConvertInterfaceLuidToNameA(
InterfaceLuid: Pointer; // NET_LUID_LH*
InterfaceName: PAnsiChar; // LPSTR out
Length: NativeUInt // UINT_PTR
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'ConvertInterfaceLuidToNameA';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ConvertInterfaceLuidToNameA"
c_ConvertInterfaceLuidToNameA :: Ptr () -> CString -> CUIntPtr -> IO Word32
-- InterfaceLuid : NET_LUID_LH* -> Ptr ()
-- InterfaceName : LPSTR out -> CString
-- Length : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let convertinterfaceluidtonamea =
foreign "ConvertInterfaceLuidToNameA"
((ptr void) @-> string @-> size_t @-> returning uint32_t)
(* InterfaceLuid : NET_LUID_LH* -> (ptr void) *)
(* InterfaceName : LPSTR out -> string *)
(* Length : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library iphlpapi (t "IPHLPAPI.dll"))
(cffi:use-foreign-library iphlpapi)
(cffi:defcfun ("ConvertInterfaceLuidToNameA" convert-interface-luid-to-name-a :convention :stdcall) :uint32
(interface-luid :pointer) ; NET_LUID_LH*
(interface-name :pointer) ; LPSTR out
(length :uint64)) ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ConvertInterfaceLuidToNameA = Win32::API::More->new('IPHLPAPI',
'DWORD ConvertInterfaceLuidToNameA(LPVOID InterfaceLuid, LPSTR InterfaceName, WPARAM Length)');
# my $ret = $ConvertInterfaceLuidToNameA->Call($InterfaceLuid, $InterfaceName, $Length);
# InterfaceLuid : NET_LUID_LH* -> LPVOID
# InterfaceName : LPSTR out -> LPSTR
# Length : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f ConvertInterfaceLuidToNameW (Unicode版) — インターフェイスLUIDを名前(Unicode)に変換する。
- f ConvertInterfaceAliasToLuid — インターフェイスのエイリアス(別名)をLUIDに変換する。
- f ConvertInterfaceGuidToLuid — インターフェイスGUIDをLUIDに変換する。
- f ConvertInterfaceIndexToLuid — インターフェイス索引をLUIDに変換する。
- f ConvertInterfaceLuidToAlias — インターフェイスLUIDをエイリアス(別名)に変換する。
- f ConvertInterfaceLuidToGuid — インターフェイスLUIDをGUIDに変換する。
- f ConvertInterfaceLuidToIndex — インターフェイスLUIDをインターフェイス索引に変換する。
- f ConvertInterfaceNameToLuidA — インターフェイス名(ANSI)をLUIDに変換する。
- f if_indextoname — インターフェイスインデックスを対応するインターフェイス名に変換する。
- f if_nametoindex — ネットワークインターフェイス名を対応するインターフェイスインデックスに変換する。