ホーム › NetworkManagement.IpHelper › SetInterfaceDnsSettings
SetInterfaceDnsSettings
関数指定したインターフェイスのDNS設定を構成する。
シグネチャ
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR SetInterfaceDnsSettings(
GUID Interface,
const DNS_INTERFACE_SETTINGS* Settings
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| Interface | GUID | in |
| Settings | DNS_INTERFACE_SETTINGS* | in |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR SetInterfaceDnsSettings(
GUID Interface,
const DNS_INTERFACE_SETTINGS* Settings
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint SetInterfaceDnsSettings(
Guid Interface, // GUID
IntPtr Settings // DNS_INTERFACE_SETTINGS*
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function SetInterfaceDnsSettings(
[Interface] As Guid, ' GUID
Settings As IntPtr ' DNS_INTERFACE_SETTINGS*
) As UInteger
End Function' Interface : GUID
' Settings : DNS_INTERFACE_SETTINGS*
Declare PtrSafe Function SetInterfaceDnsSettings 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
SetInterfaceDnsSettings = ctypes.windll.iphlpapi.SetInterfaceDnsSettings
SetInterfaceDnsSettings.restype = wintypes.DWORD
SetInterfaceDnsSettings.argtypes = [
ctypes.c_void_p, # Interface : GUID
ctypes.c_void_p, # Settings : DNS_INTERFACE_SETTINGS*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
SetInterfaceDnsSettings = Fiddle::Function.new(
lib['SetInterfaceDnsSettings'],
[
Fiddle::TYPE_VOIDP, # Interface : GUID
Fiddle::TYPE_VOIDP, # Settings : DNS_INTERFACE_SETTINGS*
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn SetInterfaceDnsSettings(
Interface: GUID, // GUID
Settings: *const DNS_INTERFACE_SETTINGS // DNS_INTERFACE_SETTINGS*
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint SetInterfaceDnsSettings(Guid Interface, IntPtr Settings);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_SetInterfaceDnsSettings' -Namespace Win32 -PassThru
# $api::SetInterfaceDnsSettings(Interface, Settings)#uselib "IPHLPAPI.dll"
#func global SetInterfaceDnsSettings "SetInterfaceDnsSettings" sptr, sptr
; SetInterfaceDnsSettings Interface, varptr(Settings) ; 戻り値は stat
; Interface : GUID -> "sptr"
; Settings : DNS_INTERFACE_SETTINGS* -> "sptr"
; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "IPHLPAPI.dll" #cfunc global SetInterfaceDnsSettings "SetInterfaceDnsSettings" int, var ; res = SetInterfaceDnsSettings(Interface, Settings) ; Interface : GUID -> "int" ; Settings : DNS_INTERFACE_SETTINGS* -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global SetInterfaceDnsSettings "SetInterfaceDnsSettings" int, sptr ; res = SetInterfaceDnsSettings(Interface, varptr(Settings)) ; Interface : GUID -> "int" ; Settings : DNS_INTERFACE_SETTINGS* -> "sptr" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR SetInterfaceDnsSettings(GUID Interface, DNS_INTERFACE_SETTINGS* Settings) #uselib "IPHLPAPI.dll" #cfunc global SetInterfaceDnsSettings "SetInterfaceDnsSettings" int, var ; res = SetInterfaceDnsSettings(Interface, Settings) ; Interface : GUID -> "int" ; Settings : DNS_INTERFACE_SETTINGS* -> "var" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR SetInterfaceDnsSettings(GUID Interface, DNS_INTERFACE_SETTINGS* Settings) #uselib "IPHLPAPI.dll" #cfunc global SetInterfaceDnsSettings "SetInterfaceDnsSettings" int, intptr ; res = SetInterfaceDnsSettings(Interface, varptr(Settings)) ; Interface : GUID -> "int" ; Settings : DNS_INTERFACE_SETTINGS* -> "intptr" ; ※値渡し構造体は直接渡せません。intにパック、または var で構造体変数を渡してください。 ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procSetInterfaceDnsSettings = iphlpapi.NewProc("SetInterfaceDnsSettings")
)
// Interface (GUID), Settings (DNS_INTERFACE_SETTINGS*)
r1, _, err := procSetInterfaceDnsSettings.Call(
uintptr(Interface),
uintptr(Settings),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction SetInterfaceDnsSettings(
Interface: TGUID; // GUID
Settings: Pointer // DNS_INTERFACE_SETTINGS*
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'SetInterfaceDnsSettings';result := DllCall("IPHLPAPI\SetInterfaceDnsSettings"
, "Ptr", Interface ; GUID
, "Ptr", Settings ; DNS_INTERFACE_SETTINGS*
, "UInt") ; return: WIN32_ERROR●SetInterfaceDnsSettings(Interface, Settings) = DLL("IPHLPAPI.dll", "dword SetInterfaceDnsSettings(void*, void*)")
# 呼び出し: SetInterfaceDnsSettings(Interface, Settings)
# Interface : GUID -> "void*"
# Settings : DNS_INTERFACE_SETTINGS* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。