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

DnsQueryConfig

関数
指定アダプターのDNS構成情報を問い合わせて取得する。
DLLDNSAPI.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT DnsQueryConfig(
    DNS_CONFIG_TYPE Config,
    DWORD Flag,
    LPCWSTR pwsAdapterName,   // optional
    void* pReserved,   // optional
    void* pBuffer,   // optional
    DWORD* pBufLen
);

パラメーター

名前方向説明
ConfigDNS_CONFIG_TYPEin取得するDNS構成情報の種類を指定するDNS_CONFIG_TYPE列挙値(検索リスト・プライマリ名等)。
FlagDWORDin取得動作を制御するフラグ。DNS_CONFIG_FLAG_ALLOC等を指定する。
pwsAdapterNameLPCWSTRinoptionalアダプター固有の構成を取得する場合のアダプター名文字列。全体構成ならNULL可。
pReservedvoid*inoptional予約済みパラメーター。NULLを指定する。
pBuffervoid*outoptional取得した構成データを格納する出力バッファへのポインタ。
pBufLenDWORD*inout入力時はpBufferのバイトサイズ、出力時は必要/書き込まれたバイトサイズを示すDWORDへのポインタ。

戻り値の型: 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 方式にも切替可。
出力引数:
; 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 方式にも切替可。
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   // INT
function 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)。
const std = @import("std");

extern "dnsapi" fn DnsQueryConfig(
    Config: i32, // DNS_CONFIG_TYPE
    Flag: u32, // DWORD
    pwsAdapterName: [*c]const u16, // LPCWSTR optional
    pReserved: ?*anyopaque, // void* optional
    pBuffer: ?*anyopaque, // void* optional, out
    pBufLen: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;
proc DnsQueryConfig(
    Config: int32,  # DNS_CONFIG_TYPE
    Flag: uint32,  # DWORD
    pwsAdapterName: WideCString,  # LPCWSTR optional
    pReserved: pointer,  # void* optional
    pBuffer: pointer,  # void* optional, out
    pBufLen: ptr uint32  # DWORD* in/out
): int32 {.importc: "DnsQueryConfig", stdcall, dynlib: "DNSAPI.dll".}
pragma(lib, "dnsapi");
extern(Windows)
int DnsQueryConfig(
    int Config,   // DNS_CONFIG_TYPE
    uint Flag,   // DWORD
    const(wchar)* pwsAdapterName,   // LPCWSTR optional
    void* pReserved,   // void* optional
    void* pBuffer,   // void* optional, out
    uint* pBufLen   // DWORD* in/out
);
ccall((:DnsQueryConfig, "DNSAPI.dll"), stdcall, Int32,
      (Int32, UInt32, Cwstring, Ptr{Cvoid}, Ptr{Cvoid}, Ptr{UInt32}),
      Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen)
# Config : DNS_CONFIG_TYPE -> Int32
# Flag : DWORD -> UInt32
# pwsAdapterName : LPCWSTR optional -> Cwstring
# pReserved : void* optional -> Ptr{Cvoid}
# pBuffer : void* optional, out -> Ptr{Cvoid}
# pBufLen : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t DnsQueryConfig(
    int32_t Config,
    uint32_t Flag,
    const uint16_t* pwsAdapterName,
    void* pReserved,
    void* pBuffer,
    uint32_t* pBufLen);
]]
local dnsapi = ffi.load("dnsapi")
-- dnsapi.DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen)
-- Config : DNS_CONFIG_TYPE
-- Flag : DWORD
-- pwsAdapterName : LPCWSTR optional
-- pReserved : void* optional
-- pBuffer : void* optional, out
-- pBufLen : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('DNSAPI.dll');
const DnsQueryConfig = lib.func('__stdcall', 'DnsQueryConfig', 'int32_t', ['int32_t', 'uint32_t', 'str16', 'void *', 'void *', 'uint32_t *']);
// DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen)
// Config : DNS_CONFIG_TYPE -> 'int32_t'
// Flag : DWORD -> 'uint32_t'
// pwsAdapterName : LPCWSTR optional -> 'str16'
// pReserved : void* optional -> 'void *'
// pBuffer : void* optional, out -> 'void *'
// pBufLen : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("DNSAPI.dll", {
  DnsQueryConfig: { parameters: ["i32", "u32", "buffer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen)
// Config : DNS_CONFIG_TYPE -> "i32"
// Flag : DWORD -> "u32"
// pwsAdapterName : LPCWSTR optional -> "buffer"
// pReserved : void* optional -> "pointer"
// pBuffer : void* optional, out -> "pointer"
// pBufLen : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t DnsQueryConfig(
    int32_t Config,
    uint32_t Flag,
    const uint16_t* pwsAdapterName,
    void* pReserved,
    void* pBuffer,
    uint32_t* pBufLen);
C, "DNSAPI.dll");
// $ffi->DnsQueryConfig(Config, Flag, pwsAdapterName, pReserved, pBuffer, pBufLen);
// Config : DNS_CONFIG_TYPE
// Flag : DWORD
// pwsAdapterName : LPCWSTR optional
// pReserved : void* optional
// pBuffer : void* optional, out
// pBufLen : DWORD* 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 Dnsapi extends StdCallLibrary {
    Dnsapi INSTANCE = Native.load("dnsapi", Dnsapi.class);
    int DnsQueryConfig(
        int Config,   // DNS_CONFIG_TYPE
        int Flag,   // DWORD
        WString pwsAdapterName,   // LPCWSTR optional
        Pointer pReserved,   // void* optional
        Pointer pBuffer,   // void* optional, out
        IntByReference pBufLen   // DWORD* in/out
    );
}
@[Link("dnsapi")]
lib LibDNSAPI
  fun DnsQueryConfig = DnsQueryConfig(
    Config : Int32,   # DNS_CONFIG_TYPE
    Flag : UInt32,   # DWORD
    pwsAdapterName : UInt16*,   # LPCWSTR optional
    pReserved : Void*,   # void* optional
    pBuffer : Void*,   # void* optional, out
    pBufLen : UInt32*   # DWORD* in/out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef DnsQueryConfigNative = Int32 Function(Int32, Uint32, Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
typedef DnsQueryConfigDart = int Function(int, int, Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
final DnsQueryConfig = DynamicLibrary.open('DNSAPI.dll')
    .lookupFunction<DnsQueryConfigNative, DnsQueryConfigDart>('DnsQueryConfig');
// Config : DNS_CONFIG_TYPE -> Int32
// Flag : DWORD -> Uint32
// pwsAdapterName : LPCWSTR optional -> Pointer<Utf16>
// pReserved : void* optional -> Pointer<Void>
// pBuffer : void* optional, out -> Pointer<Void>
// pBufLen : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function 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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DnsQueryConfig"
  c_DnsQueryConfig :: Int32 -> Word32 -> CWString -> Ptr () -> Ptr () -> Ptr Word32 -> IO Int32
-- Config : DNS_CONFIG_TYPE -> Int32
-- Flag : DWORD -> Word32
-- pwsAdapterName : LPCWSTR optional -> CWString
-- pReserved : void* optional -> Ptr ()
-- pBuffer : void* optional, out -> Ptr ()
-- pBufLen : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dnsqueryconfig =
  foreign "DnsQueryConfig"
    (int32_t @-> uint32_t @-> (ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> returning int32_t)
(* Config : DNS_CONFIG_TYPE -> int32_t *)
(* Flag : DWORD -> uint32_t *)
(* pwsAdapterName : LPCWSTR optional -> (ptr uint16_t) *)
(* pReserved : void* optional -> (ptr void) *)
(* pBuffer : void* optional, out -> (ptr void) *)
(* pBufLen : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dnsapi (t "DNSAPI.dll"))
(cffi:use-foreign-library dnsapi)

(cffi:defcfun ("DnsQueryConfig" dns-query-config :convention :stdcall) :int32
  (config :int32)   ; DNS_CONFIG_TYPE
  (flag :uint32)   ; DWORD
  (pws-adapter-name (:string :encoding :utf-16le))   ; LPCWSTR optional
  (p-reserved :pointer)   ; void* optional
  (p-buffer :pointer)   ; void* optional, out
  (p-buf-len :pointer))   ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DnsQueryConfig = Win32::API::More->new('DNSAPI',
    'int DnsQueryConfig(int Config, DWORD Flag, LPCWSTR pwsAdapterName, LPVOID pReserved, LPVOID pBuffer, LPVOID pBufLen)');
# my $ret = $DnsQueryConfig->Call($Config, $Flag, $pwsAdapterName, $pReserved, $pBuffer, $pBufLen);
# Config : DNS_CONFIG_TYPE -> int
# Flag : DWORD -> DWORD
# pwsAdapterName : LPCWSTR optional -> LPCWSTR
# pReserved : void* optional -> LPVOID
# pBuffer : void* optional, out -> LPVOID
# pBufLen : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型