ConvertInterfaceLuidToNameW
関数シグネチャ
// IPHLPAPI.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR ConvertInterfaceLuidToNameW(
const NET_LUID_LH* InterfaceLuid,
LPWSTR InterfaceName,
UINT_PTR Length
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| InterfaceLuid | NET_LUID_LH* | in | ネットワークインターフェイスの NET_LUID へのポインターです。 |
| InterfaceName | LPWSTR | out | 関数が正常に終了したときに、インターフェイス名を含む NULL 終端の Unicode 文字列を格納するバッファーへのポインターです。 |
| Length | UINT_PTR | in | InterfaceName パラメーターが指す配列の文字数です。この値は、インターフェイス名と終端の NULL 文字を格納できるだけの十分な大きさである必要があります。必要となる最大長は NDIS_IF_MAX_STRING_SIZE + 1 です。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
ネットワークインターフェイスのローカル一意識別子 (LUID) を Unicode のインターフェイス名に変換します。
戻り値
成功した場合、 ConvertInterfaceLuidToNameW は NETIO_ERROR_SUCCESS を返します。0 以外の戻り値はすべて失敗を示します。
| エラーコード | 意味 |
|---|---|
| いずれかのパラメーターが無効でした。このエラーは、InterfaceLuid または InterfaceName パラメーターが NULL であった場合、あるいは InterfaceLuid パラメーターが無効であった場合に返されます。 | |
| このコマンドを処理するための十分な記憶領域がありません。このエラーは、InterfaceName パラメーターが指すバッファーのサイズが、Length パラメーターで指定されたインターフェイス名を格納するのに十分な大きさでなかった場合に返されます。 |
解説(Remarks)
ConvertInterfaceLuidToNameW 関数は Windows Vista 以降で使用できます。
ConvertInterfaceLuidToNameW 関数はプロトコルに依存せず、IPv6 と IPv4 の両方のプロトコルのネットワークインターフェイスで動作します。ConvertInterfaceLuidToNameW はネットワークインターフェイスの LUID を Unicode のインターフェイス名に変換します。
ConvertInterfaceLuidToNameA は ANSI のインターフェイス名を LUID に変換します。
終端の 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 (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 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global ConvertInterfaceLuidToNameW "ConvertInterfaceLuidToNameW" sptr, sptr, sptr ; res = ConvertInterfaceLuidToNameW(varptr(InterfaceLuid), varptr(InterfaceName), Length) ; InterfaceLuid : NET_LUID_LH* -> "sptr" ; InterfaceName : LPWSTR out -> "sptr" ; Length : UINT_PTR -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; WIN32_ERROR ConvertInterfaceLuidToNameW(NET_LUID_LH* InterfaceLuid, LPWSTR InterfaceName, UINT_PTR Length) #uselib "IPHLPAPI.dll" #cfunc global ConvertInterfaceLuidToNameW "ConvertInterfaceLuidToNameW" intptr, intptr, intptr ; res = ConvertInterfaceLuidToNameW(varptr(InterfaceLuid), varptr(InterfaceName), Length) ; InterfaceLuid : NET_LUID_LH* -> "intptr" ; InterfaceName : LPWSTR out -> "intptr" ; Length : UINT_PTR -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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_ERRORfunction 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 版の利用を推奨。const std = @import("std");
extern "iphlpapi" fn ConvertInterfaceLuidToNameW(
InterfaceLuid: [*c]NET_LUID_LH, // NET_LUID_LH*
InterfaceName: [*c]u16, // LPWSTR out
Length: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) u32;
// Unicode(-W): UTF-16LE のヌル終端バッファ([*c]const u16)を渡す。proc ConvertInterfaceLuidToNameW(
InterfaceLuid: ptr NET_LUID_LH, # NET_LUID_LH*
InterfaceName: ptr uint16, # LPWSTR out
Length: uint # UINT_PTR
): uint32 {.importc: "ConvertInterfaceLuidToNameW", stdcall, dynlib: "IPHLPAPI.dll".}
# Unicode(-W): WideCString は newWideCString("...") で生成。pragma(lib, "iphlpapi");
extern(Windows)
uint ConvertInterfaceLuidToNameW(
NET_LUID_LH* InterfaceLuid, // NET_LUID_LH*
wchar* InterfaceName, // LPWSTR out
size_t Length // UINT_PTR
);ccall((:ConvertInterfaceLuidToNameW, "IPHLPAPI.dll"), stdcall, UInt32,
(Ptr{NET_LUID_LH}, Ptr{UInt16}, Csize_t),
InterfaceLuid, InterfaceName, Length)
# InterfaceLuid : NET_LUID_LH* -> Ptr{NET_LUID_LH}
# InterfaceName : LPWSTR out -> Ptr{UInt16}
# Length : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
# Unicode(-W): Cwstring には transcode(UInt16, "...") 等で UTF-16 を渡す。local ffi = require("ffi")
ffi.cdef[[
uint32_t ConvertInterfaceLuidToNameW(
void* InterfaceLuid,
uint16_t* InterfaceName,
uintptr_t Length);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.ConvertInterfaceLuidToNameW(InterfaceLuid, InterfaceName, Length)
-- InterfaceLuid : NET_LUID_LH*
-- InterfaceName : LPWSTR out
-- Length : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
-- Unicode(-W): uint16_t* には UTF-16LE のバッファ(ffi.new("uint16_t[?]", ...))を渡す。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const ConvertInterfaceLuidToNameW = lib.func('__stdcall', 'ConvertInterfaceLuidToNameW', 'uint32_t', ['void *', 'uint16_t *', 'uintptr_t']);
// ConvertInterfaceLuidToNameW(InterfaceLuid, InterfaceName, Length)
// InterfaceLuid : NET_LUID_LH* -> 'void *'
// InterfaceName : LPWSTR out -> 'uint16_t *'
// Length : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
ConvertInterfaceLuidToNameW: { parameters: ["pointer", "buffer", "usize"], result: "u32" },
});
// lib.symbols.ConvertInterfaceLuidToNameW(InterfaceLuid, InterfaceName, Length)
// InterfaceLuid : NET_LUID_LH* -> "pointer"
// InterfaceName : LPWSTR out -> "buffer"
// Length : UINT_PTR -> "usize"
// 文字列は "buffer"。Unicode(-W) は new TextEncoder() ではなく UTF-16LE のバイト列(末尾に \x00\x00)を Uint8Array で渡す。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t ConvertInterfaceLuidToNameW(
void* InterfaceLuid,
uint16_t* InterfaceName,
size_t Length);
C, "IPHLPAPI.dll");
// $ffi->ConvertInterfaceLuidToNameW(InterfaceLuid, InterfaceName, Length);
// InterfaceLuid : NET_LUID_LH*
// InterfaceName : LPWSTR 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.UNICODE_OPTIONS);
int ConvertInterfaceLuidToNameW(
Pointer InterfaceLuid, // NET_LUID_LH*
char[] InterfaceName, // LPWSTR out
long Length // UINT_PTR
);
}
// Unicode(-W): WString(入力)/char[](出力)で UTF-16 をマーシャリング。@[Link("iphlpapi")]
lib LibIPHLPAPI
fun ConvertInterfaceLuidToNameW = ConvertInterfaceLuidToNameW(
InterfaceLuid : NET_LUID_LH*, # NET_LUID_LH*
InterfaceName : UInt16*, # LPWSTR 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 ConvertInterfaceLuidToNameWNative = Uint32 Function(Pointer<Void>, Pointer<Utf16>, UintPtr);
typedef ConvertInterfaceLuidToNameWDart = int Function(Pointer<Void>, Pointer<Utf16>, int);
final ConvertInterfaceLuidToNameW = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<ConvertInterfaceLuidToNameWNative, ConvertInterfaceLuidToNameWDart>('ConvertInterfaceLuidToNameW');
// InterfaceLuid : NET_LUID_LH* -> Pointer<Void>
// InterfaceName : LPWSTR out -> Pointer<Utf16>
// Length : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function ConvertInterfaceLuidToNameW(
InterfaceLuid: Pointer; // NET_LUID_LH*
InterfaceName: PWideChar; // LPWSTR out
Length: NativeUInt // UINT_PTR
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'ConvertInterfaceLuidToNameW';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "ConvertInterfaceLuidToNameW"
c_ConvertInterfaceLuidToNameW :: Ptr () -> CWString -> CUIntPtr -> IO Word32
-- InterfaceLuid : NET_LUID_LH* -> Ptr ()
-- InterfaceName : LPWSTR out -> CWString
-- Length : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let convertinterfaceluidtonamew =
foreign "ConvertInterfaceLuidToNameW"
((ptr void) @-> (ptr uint16_t) @-> size_t @-> returning uint32_t)
(* InterfaceLuid : NET_LUID_LH* -> (ptr void) *)
(* InterfaceName : LPWSTR out -> (ptr uint16_t) *)
(* 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 ("ConvertInterfaceLuidToNameW" convert-interface-luid-to-name-w :convention :stdcall) :uint32
(interface-luid :pointer) ; NET_LUID_LH*
(interface-name :pointer) ; LPWSTR out
(length :uint64)) ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $ConvertInterfaceLuidToNameW = Win32::API::More->new('IPHLPAPI',
'DWORD ConvertInterfaceLuidToNameW(LPVOID InterfaceLuid, LPWSTR InterfaceName, WPARAM Length)');
# my $ret = $ConvertInterfaceLuidToNameW->Call($InterfaceLuid, $InterfaceName, $Length);
# InterfaceLuid : NET_LUID_LH* -> LPVOID
# InterfaceName : LPWSTR out -> LPWSTR
# Length : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# Unicode(-W): LPCWSTR/LPWSTR は Win32::API が UTF-16 変換を行う。関連項目
- f ConvertInterfaceLuidToNameA (ANSI版) — インターフェイスLUIDを名前(ANSI)に変換する。