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

ConvertInterfaceLuidToNameW

関数
インターフェイスLUIDを名前(Unicode)に変換する。
DLLIPHLPAPI.dll文字セットUnicode (-W)呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// IPHLPAPI.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR ConvertInterfaceLuidToNameW(
    const NET_LUID_LH* InterfaceLuid,
    LPWSTR InterfaceName,
    UINT_PTR Length
);

パラメーター

名前方向
InterfaceLuidNET_LUID_LH*in
InterfaceNameLPWSTRout
LengthUINT_PTRin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// IPHLPAPI.dll  (Unicode / -W)
#include <windows.h>

WIN32_ERROR ConvertInterfaceLuidToNameW(
    const NET_LUID_LH* InterfaceLuid,
    LPWSTR InterfaceName,
    UINT_PTR Length
);
[DllImport("IPHLPAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint ConvertInterfaceLuidToNameW(
    IntPtr InterfaceLuid,   // NET_LUID_LH*
    [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder InterfaceName,   // LPWSTR out
    UIntPtr Length   // UINT_PTR
);
<DllImport("IPHLPAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function ConvertInterfaceLuidToNameW(
    InterfaceLuid As IntPtr,   ' NET_LUID_LH*
    <MarshalAs(UnmanagedType.LPWStr)> InterfaceName As System.Text.StringBuilder,   ' LPWSTR out
    Length As UIntPtr   ' UINT_PTR
) As UInteger
End Function
' InterfaceLuid : NET_LUID_LH*
' InterfaceName : LPWSTR out
' Length : UINT_PTR
Declare PtrSafe Function ConvertInterfaceLuidToNameW Lib "iphlpapi" ( _
    ByVal InterfaceLuid As LongPtr, _
    ByVal InterfaceName As LongPtr, _
    ByVal Length As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ConvertInterfaceLuidToNameW = ctypes.windll.iphlpapi.ConvertInterfaceLuidToNameW
ConvertInterfaceLuidToNameW.restype = wintypes.DWORD
ConvertInterfaceLuidToNameW.argtypes = [
    ctypes.c_void_p,  # InterfaceLuid : NET_LUID_LH*
    wintypes.LPWSTR,  # InterfaceName : LPWSTR out
    ctypes.c_size_t,  # Length : UINT_PTR
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
ConvertInterfaceLuidToNameW = Fiddle::Function.new(
  lib['ConvertInterfaceLuidToNameW'],
  [
    Fiddle::TYPE_VOIDP,  # InterfaceLuid : NET_LUID_LH*
    Fiddle::TYPE_VOIDP,  # InterfaceName : LPWSTR out
    Fiddle::TYPE_UINTPTR_T,  # Length : UINT_PTR
  ],
  -Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "iphlpapi")]
extern "system" {
    fn ConvertInterfaceLuidToNameW(
        InterfaceLuid: *const NET_LUID_LH,  // NET_LUID_LH*
        InterfaceName: *mut u16,  // LPWSTR out
        Length: usize  // UINT_PTR
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("IPHLPAPI.dll", CharSet = CharSet.Unicode)]
public static extern uint ConvertInterfaceLuidToNameW(IntPtr InterfaceLuid, [MarshalAs(UnmanagedType.LPWStr)] System.Text.StringBuilder InterfaceName, UIntPtr Length);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_ConvertInterfaceLuidToNameW' -Namespace Win32 -PassThru
# $api::ConvertInterfaceLuidToNameW(InterfaceLuid, InterfaceName, Length)
#uselib "IPHLPAPI.dll"
#func global ConvertInterfaceLuidToNameW "ConvertInterfaceLuidToNameW" wptr, wptr, wptr
; ConvertInterfaceLuidToNameW varptr(InterfaceLuid), varptr(InterfaceName), Length   ; 戻り値は stat
; InterfaceLuid : NET_LUID_LH* -> "wptr"
; InterfaceName : LPWSTR out -> "wptr"
; Length : UINT_PTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "IPHLPAPI.dll"
#cfunc global ConvertInterfaceLuidToNameW "ConvertInterfaceLuidToNameW" var, var, sptr
; res = ConvertInterfaceLuidToNameW(InterfaceLuid, InterfaceName, Length)
; InterfaceLuid : NET_LUID_LH* -> "var"
; InterfaceName : LPWSTR out -> "var"
; Length : UINT_PTR -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR ConvertInterfaceLuidToNameW(NET_LUID_LH* InterfaceLuid, LPWSTR InterfaceName, UINT_PTR Length)
#uselib "IPHLPAPI.dll"
#cfunc global ConvertInterfaceLuidToNameW "ConvertInterfaceLuidToNameW" var, var, intptr
; res = ConvertInterfaceLuidToNameW(InterfaceLuid, InterfaceName, Length)
; InterfaceLuid : NET_LUID_LH* -> "var"
; InterfaceName : LPWSTR out -> "var"
; Length : UINT_PTR -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procConvertInterfaceLuidToNameW = iphlpapi.NewProc("ConvertInterfaceLuidToNameW")
)

// InterfaceLuid (NET_LUID_LH*), InterfaceName (LPWSTR out), Length (UINT_PTR)
r1, _, err := procConvertInterfaceLuidToNameW.Call(
	uintptr(InterfaceLuid),
	uintptr(InterfaceName),
	uintptr(Length),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function ConvertInterfaceLuidToNameW(
  InterfaceLuid: Pointer;   // NET_LUID_LH*
  InterfaceName: PWideChar;   // LPWSTR out
  Length: NativeUInt   // UINT_PTR
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'ConvertInterfaceLuidToNameW';
result := DllCall("IPHLPAPI\ConvertInterfaceLuidToNameW"
    , "Ptr", InterfaceLuid   ; NET_LUID_LH*
    , "Ptr", InterfaceName   ; LPWSTR out
    , "UPtr", Length   ; UINT_PTR
    , "UInt")   ; return: WIN32_ERROR
●ConvertInterfaceLuidToNameW(InterfaceLuid, InterfaceName, Length) = DLL("IPHLPAPI.dll", "dword ConvertInterfaceLuidToNameW(void*, char*, int)")
# 呼び出し: ConvertInterfaceLuidToNameW(InterfaceLuid, InterfaceName, Length)
# InterfaceLuid : NET_LUID_LH* -> "void*"
# InterfaceName : LPWSTR out -> "char*"
# Length : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。