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

SetDnsSettings

関数
システム全体のDNS設定を構成する。
DLLIPHLPAPI.dll呼出規約winapi

シグネチャ

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

WIN32_ERROR SetDnsSettings(
    const DNS_SETTINGS* Settings
);

パラメーター

名前方向
SettingsDNS_SETTINGS*in

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

WIN32_ERROR SetDnsSettings(
    const DNS_SETTINGS* Settings
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint SetDnsSettings(
    IntPtr Settings   // DNS_SETTINGS*
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function SetDnsSettings(
    Settings As IntPtr   ' DNS_SETTINGS*
) As UInteger
End Function
' Settings : DNS_SETTINGS*
Declare PtrSafe Function SetDnsSettings Lib "iphlpapi" ( _
    ByVal Settings As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetDnsSettings = ctypes.windll.iphlpapi.SetDnsSettings
SetDnsSettings.restype = wintypes.DWORD
SetDnsSettings.argtypes = [
    ctypes.c_void_p,  # Settings : DNS_SETTINGS*
]
require 'fiddle'
require 'fiddle/import'

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

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procSetDnsSettings = iphlpapi.NewProc("SetDnsSettings")
)

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