ホーム › NetworkManagement.IpHelper › GetDnsSettings
GetDnsSettings
関数システム全体のDNS設定を取得する。
シグネチャ
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR GetDnsSettings(
DNS_SETTINGS* Settings
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| Settings | DNS_SETTINGS* | inout | コンピュータ全体のDNS設定を受け取るDNS_SETTINGS構造体への出力先。使用後はFreeDnsSettingsで解放する。 |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
WIN32_ERROR GetDnsSettings(
DNS_SETTINGS* Settings
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetDnsSettings(
IntPtr Settings // DNS_SETTINGS* in/out
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetDnsSettings(
Settings As IntPtr ' DNS_SETTINGS* in/out
) As UInteger
End Function' Settings : DNS_SETTINGS* in/out
Declare PtrSafe Function GetDnsSettings 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
GetDnsSettings = ctypes.windll.iphlpapi.GetDnsSettings
GetDnsSettings.restype = wintypes.DWORD
GetDnsSettings.argtypes = [
ctypes.c_void_p, # Settings : DNS_SETTINGS* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
GetDnsSettings = Fiddle::Function.new(
lib['GetDnsSettings'],
[
Fiddle::TYPE_VOIDP, # Settings : DNS_SETTINGS* in/out
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn GetDnsSettings(
Settings: *mut DNS_SETTINGS // DNS_SETTINGS* in/out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint GetDnsSettings(IntPtr Settings);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetDnsSettings' -Namespace Win32 -PassThru
# $api::GetDnsSettings(Settings)#uselib "IPHLPAPI.dll"
#func global GetDnsSettings "GetDnsSettings" sptr
; GetDnsSettings varptr(Settings) ; 戻り値は stat
; Settings : DNS_SETTINGS* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "IPHLPAPI.dll" #cfunc global GetDnsSettings "GetDnsSettings" var ; res = GetDnsSettings(Settings) ; Settings : DNS_SETTINGS* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global GetDnsSettings "GetDnsSettings" sptr ; res = GetDnsSettings(varptr(Settings)) ; Settings : DNS_SETTINGS* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR GetDnsSettings(DNS_SETTINGS* Settings) #uselib "IPHLPAPI.dll" #cfunc global GetDnsSettings "GetDnsSettings" var ; res = GetDnsSettings(Settings) ; Settings : DNS_SETTINGS* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR GetDnsSettings(DNS_SETTINGS* Settings) #uselib "IPHLPAPI.dll" #cfunc global GetDnsSettings "GetDnsSettings" intptr ; res = GetDnsSettings(varptr(Settings)) ; Settings : DNS_SETTINGS* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procGetDnsSettings = iphlpapi.NewProc("GetDnsSettings")
)
// Settings (DNS_SETTINGS* in/out)
r1, _, err := procGetDnsSettings.Call(
uintptr(Settings),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction GetDnsSettings(
Settings: Pointer // DNS_SETTINGS* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetDnsSettings';result := DllCall("IPHLPAPI\GetDnsSettings"
, "Ptr", Settings ; DNS_SETTINGS* in/out
, "UInt") ; return: WIN32_ERROR●GetDnsSettings(Settings) = DLL("IPHLPAPI.dll", "dword GetDnsSettings(void*)")
# 呼び出し: GetDnsSettings(Settings)
# Settings : DNS_SETTINGS* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "iphlpapi" fn GetDnsSettings(
Settings: [*c]DNS_SETTINGS // DNS_SETTINGS* in/out
) callconv(std.os.windows.WINAPI) u32;proc GetDnsSettings(
Settings: ptr DNS_SETTINGS # DNS_SETTINGS* in/out
): uint32 {.importc: "GetDnsSettings", stdcall, dynlib: "IPHLPAPI.dll".}pragma(lib, "iphlpapi");
extern(Windows)
uint GetDnsSettings(
DNS_SETTINGS* Settings // DNS_SETTINGS* in/out
);ccall((:GetDnsSettings, "IPHLPAPI.dll"), stdcall, UInt32,
(Ptr{DNS_SETTINGS},),
Settings)
# Settings : DNS_SETTINGS* in/out -> Ptr{DNS_SETTINGS}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t GetDnsSettings(
void* Settings);
]]
local iphlpapi = ffi.load("iphlpapi")
-- iphlpapi.GetDnsSettings(Settings)
-- Settings : DNS_SETTINGS* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('IPHLPAPI.dll');
const GetDnsSettings = lib.func('__stdcall', 'GetDnsSettings', 'uint32_t', ['void *']);
// GetDnsSettings(Settings)
// Settings : DNS_SETTINGS* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("IPHLPAPI.dll", {
GetDnsSettings: { parameters: ["pointer"], result: "u32" },
});
// lib.symbols.GetDnsSettings(Settings)
// Settings : DNS_SETTINGS* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t GetDnsSettings(
void* Settings);
C, "IPHLPAPI.dll");
// $ffi->GetDnsSettings(Settings);
// Settings : DNS_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 GetDnsSettings(
Pointer Settings // DNS_SETTINGS* in/out
);
}@[Link("iphlpapi")]
lib LibIPHLPAPI
fun GetDnsSettings = GetDnsSettings(
Settings : DNS_SETTINGS* # DNS_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 GetDnsSettingsNative = Uint32 Function(Pointer<Void>);
typedef GetDnsSettingsDart = int Function(Pointer<Void>);
final GetDnsSettings = DynamicLibrary.open('IPHLPAPI.dll')
.lookupFunction<GetDnsSettingsNative, GetDnsSettingsDart>('GetDnsSettings');
// Settings : DNS_SETTINGS* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetDnsSettings(
Settings: Pointer // DNS_SETTINGS* in/out
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetDnsSettings';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetDnsSettings"
c_GetDnsSettings :: Ptr () -> IO Word32
-- Settings : DNS_SETTINGS* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let getdnssettings =
foreign "GetDnsSettings"
((ptr void) @-> returning uint32_t)
(* Settings : DNS_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 ("GetDnsSettings" get-dns-settings :convention :stdcall) :uint32
(settings :pointer)) ; DNS_SETTINGS* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetDnsSettings = Win32::API::More->new('IPHLPAPI',
'DWORD GetDnsSettings(LPVOID Settings)');
# my $ret = $GetDnsSettings->Call($Settings);
# Settings : DNS_SETTINGS* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。