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

ConvertInterfaceLuidToGuid

関数
インターフェイスLUIDをGUIDに変換する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// IPHLPAPI.dll
#include <windows.h>

WIN32_ERROR ConvertInterfaceLuidToGuid(
    const NET_LUID_LH* InterfaceLuid,
    GUID* InterfaceGuid
);

パラメーター

名前方向説明
InterfaceLuidNET_LUID_LH*inネットワークインターフェイスの NET_LUID へのポインターです。
InterfaceGuidGUID*outこのインターフェイスの GUID へのポインターです。

戻り値の型: WIN32_ERROR

公式ドキュメント

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

戻り値

成功した場合、 ConvertInterfaceLuidToGuidNO_ERROR を返します。0 以外の戻り値はいずれも失敗を示し、InterfaceGuid パラメーターには NULL が返されます。

エラーコード 意味
ERROR_INVALID_PARAMETER
パラメーターのいずれかが無効でした。このエラーは、InterfaceLuid または InterfaceGuid パラメーターが NULL であった場合、または InterfaceLuid パラメーターが無効であった場合に返されます。

解説(Remarks)

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

ConvertInterfaceLuidToGuid 関数はプロトコルに依存せず、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 ConvertInterfaceLuidToGuid(
    const NET_LUID_LH* InterfaceLuid,
    GUID* InterfaceGuid
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint ConvertInterfaceLuidToGuid(
    IntPtr InterfaceLuid,   // NET_LUID_LH*
    out Guid InterfaceGuid   // GUID* out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function ConvertInterfaceLuidToGuid(
    InterfaceLuid As IntPtr,   ' NET_LUID_LH*
    <Out> ByRef InterfaceGuid As Guid   ' GUID* out
) As UInteger
End Function
' InterfaceLuid : NET_LUID_LH*
' InterfaceGuid : GUID* out
Declare PtrSafe Function ConvertInterfaceLuidToGuid Lib "iphlpapi" ( _
    ByVal InterfaceLuid As LongPtr, _
    ByVal InterfaceGuid As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

ConvertInterfaceLuidToGuid = ctypes.windll.iphlpapi.ConvertInterfaceLuidToGuid
ConvertInterfaceLuidToGuid.restype = wintypes.DWORD
ConvertInterfaceLuidToGuid.argtypes = [
    ctypes.c_void_p,  # InterfaceLuid : NET_LUID_LH*
    ctypes.c_void_p,  # InterfaceGuid : GUID* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('IPHLPAPI.dll')
ConvertInterfaceLuidToGuid = Fiddle::Function.new(
  lib['ConvertInterfaceLuidToGuid'],
  [
    Fiddle::TYPE_VOIDP,  # InterfaceLuid : NET_LUID_LH*
    Fiddle::TYPE_VOIDP,  # InterfaceGuid : GUID* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "iphlpapi")]
extern "system" {
    fn ConvertInterfaceLuidToGuid(
        InterfaceLuid: *const NET_LUID_LH,  // NET_LUID_LH*
        InterfaceGuid: *mut GUID  // GUID* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint ConvertInterfaceLuidToGuid(IntPtr InterfaceLuid, out Guid InterfaceGuid);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_ConvertInterfaceLuidToGuid' -Namespace Win32 -PassThru
# $api::ConvertInterfaceLuidToGuid(InterfaceLuid, InterfaceGuid)
#uselib "IPHLPAPI.dll"
#func global ConvertInterfaceLuidToGuid "ConvertInterfaceLuidToGuid" sptr, sptr
; ConvertInterfaceLuidToGuid varptr(InterfaceLuid), varptr(InterfaceGuid)   ; 戻り値は stat
; InterfaceLuid : NET_LUID_LH* -> "sptr"
; InterfaceGuid : GUID* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "IPHLPAPI.dll"
#cfunc global ConvertInterfaceLuidToGuid "ConvertInterfaceLuidToGuid" var, var
; res = ConvertInterfaceLuidToGuid(InterfaceLuid, InterfaceGuid)
; InterfaceLuid : NET_LUID_LH* -> "var"
; InterfaceGuid : GUID* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR ConvertInterfaceLuidToGuid(NET_LUID_LH* InterfaceLuid, GUID* InterfaceGuid)
#uselib "IPHLPAPI.dll"
#cfunc global ConvertInterfaceLuidToGuid "ConvertInterfaceLuidToGuid" var, var
; res = ConvertInterfaceLuidToGuid(InterfaceLuid, InterfaceGuid)
; InterfaceLuid : NET_LUID_LH* -> "var"
; InterfaceGuid : GUID* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procConvertInterfaceLuidToGuid = iphlpapi.NewProc("ConvertInterfaceLuidToGuid")
)

// InterfaceLuid (NET_LUID_LH*), InterfaceGuid (GUID* out)
r1, _, err := procConvertInterfaceLuidToGuid.Call(
	uintptr(InterfaceLuid),
	uintptr(InterfaceGuid),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function ConvertInterfaceLuidToGuid(
  InterfaceLuid: Pointer;   // NET_LUID_LH*
  InterfaceGuid: PGUID   // GUID* out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'ConvertInterfaceLuidToGuid';
result := DllCall("IPHLPAPI\ConvertInterfaceLuidToGuid"
    , "Ptr", InterfaceLuid   ; NET_LUID_LH*
    , "Ptr", InterfaceGuid   ; GUID* out
    , "UInt")   ; return: WIN32_ERROR
●ConvertInterfaceLuidToGuid(InterfaceLuid, InterfaceGuid) = DLL("IPHLPAPI.dll", "dword ConvertInterfaceLuidToGuid(void*, void*)")
# 呼び出し: ConvertInterfaceLuidToGuid(InterfaceLuid, InterfaceGuid)
# InterfaceLuid : NET_LUID_LH* -> "void*"
# InterfaceGuid : GUID* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

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

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

let convertinterfaceluidtoguid =
  foreign "ConvertInterfaceLuidToGuid"
    ((ptr void) @-> (ptr void) @-> returning uint32_t)
(* InterfaceLuid : NET_LUID_LH* -> (ptr void) *)
(* InterfaceGuid : GUID* 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 ("ConvertInterfaceLuidToGuid" convert-interface-luid-to-guid :convention :stdcall) :uint32
  (interface-luid :pointer)   ; NET_LUID_LH*
  (interface-guid :pointer))   ; GUID* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $ConvertInterfaceLuidToGuid = Win32::API::More->new('IPHLPAPI',
    'DWORD ConvertInterfaceLuidToGuid(LPVOID InterfaceLuid, LPVOID InterfaceGuid)');
# my $ret = $ConvertInterfaceLuidToGuid->Call($InterfaceLuid, $InterfaceGuid);
# InterfaceLuid : NET_LUID_LH* -> LPVOID
# InterfaceGuid : GUID* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

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