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

DnsGetProxyInformation

関数
指定ホスト名に対するDNSプロキシ情報を取得する。
DLLDNSAPI.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

DWORD DnsGetProxyInformation(
    LPCWSTR hostName,
    DNS_PROXY_INFORMATION* proxyInformation,
    DNS_PROXY_INFORMATION* defaultProxyInformation,   // optional
    DNS_PROXY_COMPLETION_ROUTINE completionRoutine,   // optional
    void* completionContext   // optional
);

パラメーター

名前方向説明
hostNameLPCWSTRinプロキシ情報を取得する対象ホスト名を表すUnicode文字列へのポインタ。
proxyInformationDNS_PROXY_INFORMATION*inout取得したプロキシ情報を受け取るDNS_PROXY_INFORMATION構造体へのポインタ。
defaultProxyInformationDNS_PROXY_INFORMATION*inoutoptional既定プロキシ情報を格納したDNS_PROXY_INFORMATION構造体へのポインタ。NULL可。
completionRoutineDNS_PROXY_COMPLETION_ROUTINEinoptional非同期完了時に呼び出されるDNS_PROXY_COMPLETION_ROUTINEコールバック。同期時はNULL可。
completionContextvoid*inoptional完了コールバックに渡されるユーザー定義コンテキストへのポインタ。NULL可。

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD DnsGetProxyInformation(
    LPCWSTR hostName,
    DNS_PROXY_INFORMATION* proxyInformation,
    DNS_PROXY_INFORMATION* defaultProxyInformation,   // optional
    DNS_PROXY_COMPLETION_ROUTINE completionRoutine,   // optional
    void* completionContext   // optional
);
[DllImport("DNSAPI.dll", ExactSpelling = true)]
static extern uint DnsGetProxyInformation(
    [MarshalAs(UnmanagedType.LPWStr)] string hostName,   // LPCWSTR
    IntPtr proxyInformation,   // DNS_PROXY_INFORMATION* in/out
    IntPtr defaultProxyInformation,   // DNS_PROXY_INFORMATION* optional, in/out
    IntPtr completionRoutine,   // DNS_PROXY_COMPLETION_ROUTINE optional
    IntPtr completionContext   // void* optional
);
<DllImport("DNSAPI.dll", ExactSpelling:=True)>
Public Shared Function DnsGetProxyInformation(
    <MarshalAs(UnmanagedType.LPWStr)> hostName As String,   ' LPCWSTR
    proxyInformation As IntPtr,   ' DNS_PROXY_INFORMATION* in/out
    defaultProxyInformation As IntPtr,   ' DNS_PROXY_INFORMATION* optional, in/out
    completionRoutine As IntPtr,   ' DNS_PROXY_COMPLETION_ROUTINE optional
    completionContext As IntPtr   ' void* optional
) As UInteger
End Function
' hostName : LPCWSTR
' proxyInformation : DNS_PROXY_INFORMATION* in/out
' defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out
' completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional
' completionContext : void* optional
Declare PtrSafe Function DnsGetProxyInformation Lib "dnsapi" ( _
    ByVal hostName As LongPtr, _
    ByVal proxyInformation As LongPtr, _
    ByVal defaultProxyInformation As LongPtr, _
    ByVal completionRoutine As LongPtr, _
    ByVal completionContext As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

DnsGetProxyInformation = ctypes.windll.dnsapi.DnsGetProxyInformation
DnsGetProxyInformation.restype = wintypes.DWORD
DnsGetProxyInformation.argtypes = [
    wintypes.LPCWSTR,  # hostName : LPCWSTR
    ctypes.c_void_p,  # proxyInformation : DNS_PROXY_INFORMATION* in/out
    ctypes.c_void_p,  # defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out
    ctypes.c_void_p,  # completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional
    ctypes.POINTER(None),  # completionContext : void* optional
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('DNSAPI.dll')
DnsGetProxyInformation = Fiddle::Function.new(
  lib['DnsGetProxyInformation'],
  [
    Fiddle::TYPE_VOIDP,  # hostName : LPCWSTR
    Fiddle::TYPE_VOIDP,  # proxyInformation : DNS_PROXY_INFORMATION* in/out
    Fiddle::TYPE_VOIDP,  # defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out
    Fiddle::TYPE_VOIDP,  # completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional
    Fiddle::TYPE_VOIDP,  # completionContext : void* optional
  ],
  -Fiddle::TYPE_INT)
#[link(name = "dnsapi")]
extern "system" {
    fn DnsGetProxyInformation(
        hostName: *const u16,  // LPCWSTR
        proxyInformation: *mut DNS_PROXY_INFORMATION,  // DNS_PROXY_INFORMATION* in/out
        defaultProxyInformation: *mut DNS_PROXY_INFORMATION,  // DNS_PROXY_INFORMATION* optional, in/out
        completionRoutine: *const core::ffi::c_void,  // DNS_PROXY_COMPLETION_ROUTINE optional
        completionContext: *mut ()  // void* optional
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("DNSAPI.dll")]
public static extern uint DnsGetProxyInformation([MarshalAs(UnmanagedType.LPWStr)] string hostName, IntPtr proxyInformation, IntPtr defaultProxyInformation, IntPtr completionRoutine, IntPtr completionContext);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DNSAPI_DnsGetProxyInformation' -Namespace Win32 -PassThru
# $api::DnsGetProxyInformation(hostName, proxyInformation, defaultProxyInformation, completionRoutine, completionContext)
#uselib "DNSAPI.dll"
#func global DnsGetProxyInformation "DnsGetProxyInformation" sptr, sptr, sptr, sptr, sptr
; DnsGetProxyInformation hostName, varptr(proxyInformation), varptr(defaultProxyInformation), completionRoutine, completionContext   ; 戻り値は stat
; hostName : LPCWSTR -> "sptr"
; proxyInformation : DNS_PROXY_INFORMATION* in/out -> "sptr"
; defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out -> "sptr"
; completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional -> "sptr"
; completionContext : void* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "DNSAPI.dll"
#cfunc global DnsGetProxyInformation "DnsGetProxyInformation" wstr, var, var, sptr, sptr
; res = DnsGetProxyInformation(hostName, proxyInformation, defaultProxyInformation, completionRoutine, completionContext)
; hostName : LPCWSTR -> "wstr"
; proxyInformation : DNS_PROXY_INFORMATION* in/out -> "var"
; defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out -> "var"
; completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional -> "sptr"
; completionContext : void* optional -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD DnsGetProxyInformation(LPCWSTR hostName, DNS_PROXY_INFORMATION* proxyInformation, DNS_PROXY_INFORMATION* defaultProxyInformation, DNS_PROXY_COMPLETION_ROUTINE completionRoutine, void* completionContext)
#uselib "DNSAPI.dll"
#cfunc global DnsGetProxyInformation "DnsGetProxyInformation" wstr, var, var, intptr, intptr
; res = DnsGetProxyInformation(hostName, proxyInformation, defaultProxyInformation, completionRoutine, completionContext)
; hostName : LPCWSTR -> "wstr"
; proxyInformation : DNS_PROXY_INFORMATION* in/out -> "var"
; defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out -> "var"
; completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional -> "intptr"
; completionContext : void* optional -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	dnsapi = windows.NewLazySystemDLL("DNSAPI.dll")
	procDnsGetProxyInformation = dnsapi.NewProc("DnsGetProxyInformation")
)

// hostName (LPCWSTR), proxyInformation (DNS_PROXY_INFORMATION* in/out), defaultProxyInformation (DNS_PROXY_INFORMATION* optional, in/out), completionRoutine (DNS_PROXY_COMPLETION_ROUTINE optional), completionContext (void* optional)
r1, _, err := procDnsGetProxyInformation.Call(
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(hostName))),
	uintptr(proxyInformation),
	uintptr(defaultProxyInformation),
	uintptr(completionRoutine),
	uintptr(completionContext),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function DnsGetProxyInformation(
  hostName: PWideChar;   // LPCWSTR
  proxyInformation: Pointer;   // DNS_PROXY_INFORMATION* in/out
  defaultProxyInformation: Pointer;   // DNS_PROXY_INFORMATION* optional, in/out
  completionRoutine: Pointer;   // DNS_PROXY_COMPLETION_ROUTINE optional
  completionContext: Pointer   // void* optional
): DWORD; stdcall;
  external 'DNSAPI.dll' name 'DnsGetProxyInformation';
result := DllCall("DNSAPI\DnsGetProxyInformation"
    , "WStr", hostName   ; LPCWSTR
    , "Ptr", proxyInformation   ; DNS_PROXY_INFORMATION* in/out
    , "Ptr", defaultProxyInformation   ; DNS_PROXY_INFORMATION* optional, in/out
    , "Ptr", completionRoutine   ; DNS_PROXY_COMPLETION_ROUTINE optional
    , "Ptr", completionContext   ; void* optional
    , "UInt")   ; return: DWORD
●DnsGetProxyInformation(hostName, proxyInformation, defaultProxyInformation, completionRoutine, completionContext) = DLL("DNSAPI.dll", "dword DnsGetProxyInformation(char*, void*, void*, void*, void*)")
# 呼び出し: DnsGetProxyInformation(hostName, proxyInformation, defaultProxyInformation, completionRoutine, completionContext)
# hostName : LPCWSTR -> "char*"
# proxyInformation : DNS_PROXY_INFORMATION* in/out -> "void*"
# defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out -> "void*"
# completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional -> "void*"
# completionContext : void* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef DnsGetProxyInformationNative = Uint32 Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef DnsGetProxyInformationDart = int Function(Pointer<Utf16>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final DnsGetProxyInformation = DynamicLibrary.open('DNSAPI.dll')
    .lookupFunction<DnsGetProxyInformationNative, DnsGetProxyInformationDart>('DnsGetProxyInformation');
// hostName : LPCWSTR -> Pointer<Utf16>
// proxyInformation : DNS_PROXY_INFORMATION* in/out -> Pointer<Void>
// defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out -> Pointer<Void>
// completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional -> Pointer<Void>
// completionContext : void* optional -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function DnsGetProxyInformation(
  hostName: PWideChar;   // LPCWSTR
  proxyInformation: Pointer;   // DNS_PROXY_INFORMATION* in/out
  defaultProxyInformation: Pointer;   // DNS_PROXY_INFORMATION* optional, in/out
  completionRoutine: Pointer;   // DNS_PROXY_COMPLETION_ROUTINE optional
  completionContext: Pointer   // void* optional
): DWORD; stdcall;
  external 'DNSAPI.dll' name 'DnsGetProxyInformation';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "DnsGetProxyInformation"
  c_DnsGetProxyInformation :: CWString -> Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO Word32
-- hostName : LPCWSTR -> CWString
-- proxyInformation : DNS_PROXY_INFORMATION* in/out -> Ptr ()
-- defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out -> Ptr ()
-- completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional -> Ptr ()
-- completionContext : void* optional -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let dnsgetproxyinformation =
  foreign "DnsGetProxyInformation"
    ((ptr uint16_t) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning uint32_t)
(* hostName : LPCWSTR -> (ptr uint16_t) *)
(* proxyInformation : DNS_PROXY_INFORMATION* in/out -> (ptr void) *)
(* defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out -> (ptr void) *)
(* completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional -> (ptr void) *)
(* completionContext : void* optional -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library dnsapi (t "DNSAPI.dll"))
(cffi:use-foreign-library dnsapi)

(cffi:defcfun ("DnsGetProxyInformation" dns-get-proxy-information :convention :stdcall) :uint32
  (host-name (:string :encoding :utf-16le))   ; LPCWSTR
  (proxy-information :pointer)   ; DNS_PROXY_INFORMATION* in/out
  (default-proxy-information :pointer)   ; DNS_PROXY_INFORMATION* optional, in/out
  (completion-routine :pointer)   ; DNS_PROXY_COMPLETION_ROUTINE optional
  (completion-context :pointer))   ; void* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $DnsGetProxyInformation = Win32::API::More->new('DNSAPI',
    'DWORD DnsGetProxyInformation(LPCWSTR hostName, LPVOID proxyInformation, LPVOID defaultProxyInformation, LPVOID completionRoutine, LPVOID completionContext)');
# my $ret = $DnsGetProxyInformation->Call($hostName, $proxyInformation, $defaultProxyInformation, $completionRoutine, $completionContext);
# hostName : LPCWSTR -> LPCWSTR
# proxyInformation : DNS_PROXY_INFORMATION* in/out -> LPVOID
# defaultProxyInformation : DNS_PROXY_INFORMATION* optional, in/out -> LPVOID
# completionRoutine : DNS_PROXY_COMPLETION_ROUTINE optional -> LPVOID
# completionContext : void* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。
# コールバック(関数ポインタ)は Perl sub を直接渡せません。Win32::API::Callback を使用してください。

関連項目

使用する型