ホーム › NetworkManagement.Dns › DnsQueryConfig
DnsQueryConfig
関数指定アダプターのDNS構成情報を問い合わせて取得する。
シグネチャ
// DNSAPI.dll
#include <windows.h>
INT DnsQueryConfig(
DNS_CONFIG_TYPE Config,
DWORD Flag,
LPCWSTR pwsAdapterName, // optional
void* pReserved, // optional
void* pBuffer, // optional
DWORD* pBufLen
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| Config | DNS_CONFIG_TYPE | in |
| Flag | DWORD | in |
| pwsAdapterName | LPCWSTR | inoptional |
| pReserved | void* | inoptional |
| pBuffer | void* | outoptional |
| pBufLen | DWORD* | inout |
戻り値の型: INT
各言語での呼び出し定義
// DNSAPI.dll
#include <windows.h>
INT DnsQueryConfig(
DNS_CONFIG_TYPE Config,
DWORD Flag,
LPCWSTR pwsAdapterName, // optional
void* pReserved, // optional
void* pBuffer, // optional
DWORD* pBufLen
);[DllImport("DNSAPI.dll", ExactSpelling = true)]
static extern int DnsQueryConfig(
int Config, // DNS_CONFIG_TYPE
uint Flag, // DWORD
[MarshalAs(UnmanagedType.LPWStr)] string pwsAdapterName, // LPCWSTR optional
IntPtr pReserved, // void* optional
IntPtr pBuffer, // void* optional, out
ref uint pBufLen // DWORD* in/out
);<DllImport("DNSAPI.dll", ExactSpelling:=True)>
Public Shared Function DnsQueryConfig(
Config As Integer, ' DNS_CONFIG_TYPE
Flag As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPWStr)> pwsAdapterName As String, ' LPCWSTR optional
pReserved As IntPtr, ' void* optional
pBuffer As IntPtr, ' void* optional, out
ByRef pBufLen As UInteger ' DWORD* in/out
) As Integer
End Function' Config : DNS_CONFIG_TYPE
' Flag : DWORD
' pwsAdapterName : LPCWSTR optional
' pReserved : void* optional
' pBuffer : void* optional, out
' pBufLen : DWORD* in/out
Declare PtrSafe Function DnsQueryConfig Lib "dnsapi" ( _
ByVal Config As Long, _
ByVal Flag As Long, _
ByVal pwsAdapterName As LongPtr, _
ByVal pReserved As LongPtr, _
ByVal pBuffer As LongPtr, _
ByRef pBufLen As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DnsQueryConfig = ctypes.windll.dnsapi.DnsQueryConfig
DnsQueryConfig.restype = ctypes.c_int
DnsQueryConfig.argtypes = [
ctypes.c_int, # Config : DNS_CONFIG_TYPE
wintypes.DWORD, # Flag : DWORD
wintypes.LPCWSTR, # pwsAdapterName : LPCWSTR optional
ctypes.POINTER(None), # pReserved : void* optional
ctypes.POINTER(None), # pBuffer : void* optional, out
ctypes.POINTER(wintypes.DWORD), # pBufLen : DWORD* in/out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('DNSAPI.dll')
DnsQueryConfig = Fiddle::Function.new(
lib['DnsQueryConfig'],
[
Fiddle::TYPE_INT, # Config : DNS_CONFIG_TYPE
-Fiddle::TYPE_INT, # Flag : DWORD
Fiddle::TYPE_VOIDP, # pwsAdapterName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pReserved : void* optional
Fiddle::TYPE_VOIDP, # pBuffer : void* optional, out
Fiddle::TYPE_VOIDP, # pBufLen : DWORD* in/out
],
Fiddle::TYPE_INT)#[link(name = "dnsapi")]
extern "system" {
fn DnsQueryConfig(
Config: i32, // DNS_CONFIG_TYPE
Flag: u32, // DWORD
pwsAdapterName: *const u16, // LPCWSTR optional
pReserved: *mut (), // void* optional
pBuffer: *mut (), // void* optional, out
pBufLen: *mut u32 // DWORD* in/out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("DNSAPI.dll")]
public static extern int DnsQueryConfig(int Config, uint Flag, [MarshalAs(UnmanagedType.LPWStr)] string pwsAdapterName, IntPtr pReserved, IntPtr pBuffer, ref uint pBufLen);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DNSAPI_DnsQueryConfig' -Namespace Win32 -PassThru
# $api::DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen)#uselib "DNSAPI.dll"
#func global DnsQueryConfig "DnsQueryConfig" sptr, sptr, sptr, sptr, sptr, sptr
; DnsQueryConfig Config, Flag, pwsAdapterName, pReserved, pBuffer, varptr(pBufLen) ; 戻り値は stat
; Config : DNS_CONFIG_TYPE -> "sptr"
; Flag : DWORD -> "sptr"
; pwsAdapterName : LPCWSTR optional -> "sptr"
; pReserved : void* optional -> "sptr"
; pBuffer : void* optional, out -> "sptr"
; pBufLen : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "DNSAPI.dll" #cfunc global DnsQueryConfig "DnsQueryConfig" int, int, wstr, sptr, sptr, var ; res = DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen) ; Config : DNS_CONFIG_TYPE -> "int" ; Flag : DWORD -> "int" ; pwsAdapterName : LPCWSTR optional -> "wstr" ; pReserved : void* optional -> "sptr" ; pBuffer : void* optional, out -> "sptr" ; pBufLen : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DNSAPI.dll" #cfunc global DnsQueryConfig "DnsQueryConfig" int, int, wstr, sptr, sptr, sptr ; res = DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, varptr(pBufLen)) ; Config : DNS_CONFIG_TYPE -> "int" ; Flag : DWORD -> "int" ; pwsAdapterName : LPCWSTR optional -> "wstr" ; pReserved : void* optional -> "sptr" ; pBuffer : void* optional, out -> "sptr" ; pBufLen : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT DnsQueryConfig(DNS_CONFIG_TYPE Config, DWORD Flag, LPCWSTR pwsAdapterName, void* pReserved, void* pBuffer, DWORD* pBufLen) #uselib "DNSAPI.dll" #cfunc global DnsQueryConfig "DnsQueryConfig" int, int, wstr, intptr, intptr, var ; res = DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen) ; Config : DNS_CONFIG_TYPE -> "int" ; Flag : DWORD -> "int" ; pwsAdapterName : LPCWSTR optional -> "wstr" ; pReserved : void* optional -> "intptr" ; pBuffer : void* optional, out -> "intptr" ; pBufLen : DWORD* in/out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT DnsQueryConfig(DNS_CONFIG_TYPE Config, DWORD Flag, LPCWSTR pwsAdapterName, void* pReserved, void* pBuffer, DWORD* pBufLen) #uselib "DNSAPI.dll" #cfunc global DnsQueryConfig "DnsQueryConfig" int, int, wstr, intptr, intptr, intptr ; res = DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, varptr(pBufLen)) ; Config : DNS_CONFIG_TYPE -> "int" ; Flag : DWORD -> "int" ; pwsAdapterName : LPCWSTR optional -> "wstr" ; pReserved : void* optional -> "intptr" ; pBuffer : void* optional, out -> "intptr" ; pBufLen : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dnsapi = windows.NewLazySystemDLL("DNSAPI.dll")
procDnsQueryConfig = dnsapi.NewProc("DnsQueryConfig")
)
// Config (DNS_CONFIG_TYPE), Flag (DWORD), pwsAdapterName (LPCWSTR optional), pReserved (void* optional), pBuffer (void* optional, out), pBufLen (DWORD* in/out)
r1, _, err := procDnsQueryConfig.Call(
uintptr(Config),
uintptr(Flag),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pwsAdapterName))),
uintptr(pReserved),
uintptr(pBuffer),
uintptr(pBufLen),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction DnsQueryConfig(
Config: Integer; // DNS_CONFIG_TYPE
Flag: DWORD; // DWORD
pwsAdapterName: PWideChar; // LPCWSTR optional
pReserved: Pointer; // void* optional
pBuffer: Pointer; // void* optional, out
pBufLen: Pointer // DWORD* in/out
): Integer; stdcall;
external 'DNSAPI.dll' name 'DnsQueryConfig';result := DllCall("DNSAPI\DnsQueryConfig"
, "Int", Config ; DNS_CONFIG_TYPE
, "UInt", Flag ; DWORD
, "WStr", pwsAdapterName ; LPCWSTR optional
, "Ptr", pReserved ; void* optional
, "Ptr", pBuffer ; void* optional, out
, "Ptr", pBufLen ; DWORD* in/out
, "Int") ; return: INT●DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen) = DLL("DNSAPI.dll", "int DnsQueryConfig(int, dword, char*, void*, void*, void*)")
# 呼び出し: DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen)
# Config : DNS_CONFIG_TYPE -> "int"
# Flag : DWORD -> "dword"
# pwsAdapterName : LPCWSTR optional -> "char*"
# pReserved : void* optional -> "void*"
# pBuffer : void* optional, out -> "void*"
# pBufLen : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。