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

DnsGetApplicationSettings

関数
アプリケーション用のDNS設定とカスタムサーバーを取得する。
DLLDNSAPI.dll呼出規約winapi

シグネチャ

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

DWORD DnsGetApplicationSettings(
    DWORD* pcServers,
    DNS_CUSTOM_SERVER** ppDefaultServers,
    DNS_APPLICATION_SETTINGS* pSettings   // optional
);

パラメーター

名前方向説明
pcServersDWORD*out取得した既定サーバー配列の要素数を受け取るDWORDへのポインタ。
ppDefaultServersDNS_CUSTOM_SERVER**out既定のカスタムDNSサーバー配列を受け取るポインタのアドレス。DnsFreeCustomServersで解放する。
pSettingsDNS_APPLICATION_SETTINGS*outoptionalアプリ固有のDNS設定を受け取るDNS_APPLICATION_SETTINGS構造体へのポインタ。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DnsGetApplicationSettings(
    DWORD* pcServers,
    DNS_CUSTOM_SERVER** ppDefaultServers,
    DNS_APPLICATION_SETTINGS* pSettings   // optional
);
[DllImport("DNSAPI.dll", ExactSpelling = true)]
static extern uint DnsGetApplicationSettings(
    out uint pcServers,   // DWORD* out
    IntPtr ppDefaultServers,   // DNS_CUSTOM_SERVER** out
    IntPtr pSettings   // DNS_APPLICATION_SETTINGS* optional, out
);
<DllImport("DNSAPI.dll", ExactSpelling:=True)>
Public Shared Function DnsGetApplicationSettings(
    <Out> ByRef pcServers As UInteger,   ' DWORD* out
    ppDefaultServers As IntPtr,   ' DNS_CUSTOM_SERVER** out
    pSettings As IntPtr   ' DNS_APPLICATION_SETTINGS* optional, out
) As UInteger
End Function
' pcServers : DWORD* out
' ppDefaultServers : DNS_CUSTOM_SERVER** out
' pSettings : DNS_APPLICATION_SETTINGS* optional, out
Declare PtrSafe Function DnsGetApplicationSettings Lib "dnsapi" ( _
    ByRef pcServers As Long, _
    ByVal ppDefaultServers As LongPtr, _
    ByVal pSettings As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DnsGetApplicationSettings = ctypes.windll.dnsapi.DnsGetApplicationSettings
DnsGetApplicationSettings.restype = wintypes.DWORD
DnsGetApplicationSettings.argtypes = [
    ctypes.POINTER(wintypes.DWORD),  # pcServers : DWORD* out
    ctypes.c_void_p,  # ppDefaultServers : DNS_CUSTOM_SERVER** out
    ctypes.c_void_p,  # pSettings : DNS_APPLICATION_SETTINGS* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	dnsapi = windows.NewLazySystemDLL("DNSAPI.dll")
	procDnsGetApplicationSettings = dnsapi.NewProc("DnsGetApplicationSettings")
)

// pcServers (DWORD* out), ppDefaultServers (DNS_CUSTOM_SERVER** out), pSettings (DNS_APPLICATION_SETTINGS* optional, out)
r1, _, err := procDnsGetApplicationSettings.Call(
	uintptr(pcServers),
	uintptr(ppDefaultServers),
	uintptr(pSettings),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DnsGetApplicationSettings(
  pcServers: Pointer;   // DWORD* out
  ppDefaultServers: Pointer;   // DNS_CUSTOM_SERVER** out
  pSettings: Pointer   // DNS_APPLICATION_SETTINGS* optional, out
): DWORD; stdcall;
  external 'DNSAPI.dll' name 'DnsGetApplicationSettings';
result := DllCall("DNSAPI\DnsGetApplicationSettings"
    , "Ptr", pcServers   ; DWORD* out
    , "Ptr", ppDefaultServers   ; DNS_CUSTOM_SERVER** out
    , "Ptr", pSettings   ; DNS_APPLICATION_SETTINGS* optional, out
    , "UInt")   ; return: DWORD
●DnsGetApplicationSettings(pcServers, ppDefaultServers, pSettings) = DLL("DNSAPI.dll", "dword DnsGetApplicationSettings(void*, void*, void*)")
# 呼び出し: DnsGetApplicationSettings(pcServers, ppDefaultServers, pSettings)
# pcServers : DWORD* out -> "void*"
# ppDefaultServers : DNS_CUSTOM_SERVER** out -> "void*"
# pSettings : DNS_APPLICATION_SETTINGS* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef DnsGetApplicationSettingsNative = Uint32 Function(Pointer<Uint32>, Pointer<Void>, Pointer<Void>);
typedef DnsGetApplicationSettingsDart = int Function(Pointer<Uint32>, Pointer<Void>, Pointer<Void>);
final DnsGetApplicationSettings = DynamicLibrary.open('DNSAPI.dll')
    .lookupFunction<DnsGetApplicationSettingsNative, DnsGetApplicationSettingsDart>('DnsGetApplicationSettings');
// pcServers : DWORD* out -> Pointer<Uint32>
// ppDefaultServers : DNS_CUSTOM_SERVER** out -> Pointer<Void>
// pSettings : DNS_APPLICATION_SETTINGS* optional, out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DnsGetApplicationSettings(
  pcServers: Pointer;   // DWORD* out
  ppDefaultServers: Pointer;   // DNS_CUSTOM_SERVER** out
  pSettings: Pointer   // DNS_APPLICATION_SETTINGS* optional, out
): DWORD; stdcall;
  external 'DNSAPI.dll' name 'DnsGetApplicationSettings';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DnsGetApplicationSettings"
  c_DnsGetApplicationSettings :: Ptr Word32 -> Ptr () -> Ptr () -> IO Word32
-- pcServers : DWORD* out -> Ptr Word32
-- ppDefaultServers : DNS_CUSTOM_SERVER** out -> Ptr ()
-- pSettings : DNS_APPLICATION_SETTINGS* optional, out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dnsgetapplicationsettings =
  foreign "DnsGetApplicationSettings"
    ((ptr uint32_t) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* pcServers : DWORD* out -> (ptr uint32_t) *)
(* ppDefaultServers : DNS_CUSTOM_SERVER** out -> (ptr void) *)
(* pSettings : DNS_APPLICATION_SETTINGS* optional, out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dnsapi (t "DNSAPI.dll"))
(cffi:use-foreign-library dnsapi)

(cffi:defcfun ("DnsGetApplicationSettings" dns-get-application-settings :convention :stdcall) :uint32
  (pc-servers :pointer)   ; DWORD* out
  (pp-default-servers :pointer)   ; DNS_CUSTOM_SERVER** out
  (p-settings :pointer))   ; DNS_APPLICATION_SETTINGS* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DnsGetApplicationSettings = Win32::API::More->new('DNSAPI',
    'DWORD DnsGetApplicationSettings(LPVOID pcServers, LPVOID ppDefaultServers, LPVOID pSettings)');
# my $ret = $DnsGetApplicationSettings->Call($pcServers, $ppDefaultServers, $pSettings);
# pcServers : DWORD* out -> LPVOID
# ppDefaultServers : DNS_CUSTOM_SERVER** out -> LPVOID
# pSettings : DNS_APPLICATION_SETTINGS* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型