ホーム › NetworkManagement.IpHelper › GetInterfaceDnsSettings
GetInterfaceDnsSettings
関数指定したインターフェイスのDNS設定を取得する。
シグネチャ
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR GetInterfaceDnsSettings(
GUID Interface,
DNS_INTERFACE_SETTINGS* Settings
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Interface | GUID | in | 設定の対象となる COM インターフェイスの GUID です。 |
| Settings | DNS_INTERFACE_SETTINGS* | inout | GetInterfaceDnsSettings は、この構造体内のすべての設定を設定します。 設定する必要があるのは Version メンバーのみで、Flags フィールドは空でなければなりません。 Version メンバーに DNS_INTERFACE_SETTINGS_VERSION1 を設定する場合、Settings パラメーターは有効な DNS_INTERFACE_SETTINGS 構造体を指している必要があります。 Version メンバーに DNS_INTERFACE_SETTINGS_VERSION2 を設定する場合、Settings パラメーターは有効な DNS_INTERFACE_SETTINGS_EX 構造体を指している必要があります。 Version メンバーに DNS_INTERFACE_SETTINGS_VERSION3 を設定する場合、Settings パラメーターは有効な DNS_INTERFACE_SETTINGS3 構造体を指している必要があります。 |
戻り値の型: WIN32_ERROR
公式ドキュメント
Interface パラメーターで指定されたインターフェイスから DNS 設定を取得します。
戻り値
成功した場合は NO_ERROR を返します。ゼロ以外の戻り値は失敗を示します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR GetInterfaceDnsSettings(
GUID Interface,
DNS_INTERFACE_SETTINGS* Settings
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetInterfaceDnsSettings(
Guid Interface, // GUID
IntPtr Settings // DNS_INTERFACE_SETTINGS* in/out
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetInterfaceDnsSettings(
[Interface] As Guid, ' GUID
Settings As IntPtr ' DNS_INTERFACE_SETTINGS* in/out
) As UInteger
End Function' Interface : GUID
' Settings : DNS_INTERFACE_SETTINGS* in/out
Declare PtrSafe Function GetInterfaceDnsSettings Lib "iphlpapi" ( _
ByVal Interface As LongPtr, _
ByVal Settings As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetInterfaceDnsSettings = ctypes.windll.iphlpapi.GetInterfaceDnsSettings
GetInterfaceDnsSettings.restype = wintypes.DWORD
GetInterfaceDnsSettings.argtypes = [
ctypes.c_void_p, # Interface : GUID
ctypes.c_void_p, # Settings : DNS_INTERFACE_SETTINGS* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
GetInterfaceDnsSettings = Fiddle::Function.new(
lib['GetInterfaceDnsSettings'],
[
Fiddle::TYPE_VOIDP, # Interface : GUID
Fiddle::TYPE_VOIDP, # Settings : DNS_INTERFACE_SETTINGS* in/out
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn GetInterfaceDnsSettings(
Interface: GUID, // GUID
Settings: *mut DNS_INTERFACE_SETTINGS // DNS_INTERFACE_SETTINGS* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint GetInterfaceDnsSettings(Guid Interface, IntPtr Settings);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetInterfaceDnsSettings' -Namespace Win32 -PassThru
# $api::GetInterfaceDnsSettings(Interface, Settings)#uselib "IPHLPAPI.dll"
#func global GetInterfaceDnsSettings "GetInterfaceDnsSettings" sptr, sptr
; GetInterfaceDnsSettings Interface, varptr(Settings) ; 戻り値は stat
; Interface : GUID -> "sptr"
; Settings : DNS_INTERFACE_SETTINGS* in/out -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "IPHLPAPI.dll" #cfunc global GetInterfaceDnsSettings "GetInterfaceDnsSettings" int, var ; res = GetInterfaceDnsSettings(Interface, Settings) ; Interface : GUID -> "int" ; Settings : DNS_INTERFACE_SETTINGS* in/out -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global GetInterfaceDnsSettings "GetInterfaceDnsSettings" int, sptr ; res = GetInterfaceDnsSettings(Interface, varptr(Settings)) ; Interface : GUID -> "int" ; Settings : DNS_INTERFACE_SETTINGS* in/out -> "sptr" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR GetInterfaceDnsSettings(GUID Interface, DNS_INTERFACE_SETTINGS* Settings) #uselib "IPHLPAPI.dll" #cfunc global GetInterfaceDnsSettings "GetInterfaceDnsSettings" int, var ; res = GetInterfaceDnsSettings(Interface, Settings) ; Interface : GUID -> "int" ; Settings : DNS_INTERFACE_SETTINGS* in/out -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR GetInterfaceDnsSettings(GUID Interface, DNS_INTERFACE_SETTINGS* Settings) #uselib "IPHLPAPI.dll" #cfunc global GetInterfaceDnsSettings "GetInterfaceDnsSettings" int, intptr ; res = GetInterfaceDnsSettings(Interface, varptr(Settings)) ; Interface : GUID -> "int" ; Settings : DNS_INTERFACE_SETTINGS* in/out -> "intptr" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procGetInterfaceDnsSettings = iphlpapi.NewProc("GetInterfaceDnsSettings")
)
// Interface (GUID), Settings (DNS_INTERFACE_SETTINGS* in/out)
r1, _, err := procGetInterfaceDnsSettings.Call(
uintptr(Interface),
uintptr(Settings),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction GetInterfaceDnsSettings(
Interface: TGUID; // GUID
Settings: Pointer // DNS_INTERFACE_SETTINGS* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetInterfaceDnsSettings';result := DllCall("IPHLPAPI\GetInterfaceDnsSettings"
, "Ptr", Interface ; GUID
, "Ptr", Settings ; DNS_INTERFACE_SETTINGS* in/out
, "UInt") ; return: WIN32_ERROR●GetInterfaceDnsSettings(Interface, Settings) = DLL("IPHLPAPI.dll", "dword GetInterfaceDnsSettings(void*, void*)")
# 呼び出し: GetInterfaceDnsSettings(Interface, Settings)
# Interface : GUID -> "void*"
# Settings : DNS_INTERFACE_SETTINGS* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "iphlpapi" fn GetInterfaceDnsSettings(
Interface: GUID, // GUID
Settings: [*c]DNS_INTERFACE_SETTINGS // DNS_INTERFACE_SETTINGS* in/out
) callconv(std.os.windows.WINAPI) u32;proc GetInterfaceDnsSettings(
Interface: GUID, # GUID
Settings: ptr DNS_INTERFACE_SETTINGS # DNS_INTERFACE_SETTINGS* in/out
): uint32 {.importc: "GetInterfaceDnsSettings", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint GetInterfaceDnsSettings(
GUID Interface, // GUID
DNS_INTERFACE_SETTINGS* Settings // DNS_INTERFACE_SETTINGS* in/out
);ccall((:GetInterfaceDnsSettings, "IPHLPAPI.dll"), stdcall, UInt32,
(GUID, Ptr{DNS_INTERFACE_SETTINGS}),
Interface, Settings)
# Interface : GUID -> GUID
# Settings : DNS_INTERFACE_SETTINGS* in/out -> Ptr{DNS_INTERFACE_SETTINGS}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetInterfaceDnsSettings(
GUID Interface,
void* Settings);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.GetInterfaceDnsSettings(Interface, Settings)
-- Interface : GUID
-- Settings : DNS_INTERFACE_SETTINGS* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const GetInterfaceDnsSettings = lib.func('__stdcall', 'GetInterfaceDnsSettings', 'uint32_t', ['void *', 'void *']);
// GetInterfaceDnsSettings(Interface, Settings)
// Interface : GUID -> 'void *'
// Settings : DNS_INTERFACE_SETTINGS* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
GetInterfaceDnsSettings: { parameters: ["pointer", "pointer"], result: "u32" },
});
// lib.symbols.GetInterfaceDnsSettings(Interface, Settings)
// Interface : GUID -> "pointer"
// Settings : DNS_INTERFACE_SETTINGS* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetInterfaceDnsSettings(
GUID Interface,
void* Settings);
C, "IPHLPAPI.dll");
// $ffi->GetInterfaceDnsSettings(Interface, Settings);
// Interface : GUID
// Settings : DNS_INTERFACE_SETTINGS* in/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 GetInterfaceDnsSettings(
Pointer Interface, // GUID
Pointer Settings // DNS_INTERFACE_SETTINGS* in/out
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun GetInterfaceDnsSettings = GetInterfaceDnsSettings(
Interface : GUID, # GUID
Settings : DNS_INTERFACE_SETTINGS* # DNS_INTERFACE_SETTINGS* in/out
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetInterfaceDnsSettingsNative = Uint32 Function(Pointer<Void>, Pointer<Void>);
typedef GetInterfaceDnsSettingsDart = int Function(Pointer<Void>, Pointer<Void>);
final GetInterfaceDnsSettings = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<GetInterfaceDnsSettingsNative, GetInterfaceDnsSettingsDart>('GetInterfaceDnsSettings');
// Interface : GUID -> Pointer<Void>
// Settings : DNS_INTERFACE_SETTINGS* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetInterfaceDnsSettings(
Interface: TGUID; // GUID
Settings: Pointer // DNS_INTERFACE_SETTINGS* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetInterfaceDnsSettings';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetInterfaceDnsSettings"
c_GetInterfaceDnsSettings :: Ptr () -> Ptr () -> IO Word32
-- Interface : GUID -> Ptr ()
-- Settings : DNS_INTERFACE_SETTINGS* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
-- ※値渡し構造体は GHC FFI で直接渡せません。Ptr で渡すラッパ(C側)経由にしてください。open Ctypes
open Foreign
let getinterfacednssettings =
foreign "GetInterfaceDnsSettings"
((ptr void) @-> (ptr void) @-> returning uint32_t)
(* Interface : GUID -> (ptr void) *)
(* Settings : DNS_INTERFACE_SETTINGS* in/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 ("GetInterfaceDnsSettings" get-interface-dns-settings :convention :stdcall) :uint32
(interface :pointer) ; GUID
(settings :pointer)) ; DNS_INTERFACE_SETTINGS* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetInterfaceDnsSettings = Win32::API::More->new('IPHLPAPI',
'DWORD GetInterfaceDnsSettings(LPVOID Interface, LPVOID Settings)');
# my $ret = $GetInterfaceDnsSettings->Call($Interface, $Settings);
# Interface : GUID -> LPVOID
# Settings : DNS_INTERFACE_SETTINGS* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。