ホーム › NetworkManagement.Dns › DnsQuery_W
DnsQuery_W
関数Unicode文字列名でDNS問い合わせを実行しレコードを取得する。
シグネチャ
// DNSAPI.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR DnsQuery_W(
LPCWSTR pszName,
WORD wType,
DNS_QUERY_OPTIONS Options,
void* pExtra, // optional
DNS_RECORDA** ppQueryResults,
void** pReserved // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pszName | LPCWSTR | in |
| wType | WORD | in |
| Options | DNS_QUERY_OPTIONS | in |
| pExtra | void* | inoutoptional |
| ppQueryResults | DNS_RECORDA** | out |
| pReserved | void** | outoptional |
戻り値の型: WIN32_ERROR
各言語での呼び出し定義
// DNSAPI.dll (Unicode / -W)
#include <windows.h>
WIN32_ERROR DnsQuery_W(
LPCWSTR pszName,
WORD wType,
DNS_QUERY_OPTIONS Options,
void* pExtra, // optional
DNS_RECORDA** ppQueryResults,
void** pReserved // optional
);[DllImport("DNSAPI.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern uint DnsQuery_W(
[MarshalAs(UnmanagedType.LPWStr)] string pszName, // LPCWSTR
ushort wType, // WORD
uint Options, // DNS_QUERY_OPTIONS
IntPtr pExtra, // void* optional, in/out
IntPtr ppQueryResults, // DNS_RECORDA** out
IntPtr pReserved // void** optional, out
);<DllImport("DNSAPI.dll", CharSet:=CharSet.Unicode, ExactSpelling:=True)>
Public Shared Function DnsQuery_W(
<MarshalAs(UnmanagedType.LPWStr)> pszName As String, ' LPCWSTR
wType As UShort, ' WORD
Options As UInteger, ' DNS_QUERY_OPTIONS
pExtra As IntPtr, ' void* optional, in/out
ppQueryResults As IntPtr, ' DNS_RECORDA** out
pReserved As IntPtr ' void** optional, out
) As UInteger
End Function' pszName : LPCWSTR
' wType : WORD
' Options : DNS_QUERY_OPTIONS
' pExtra : void* optional, in/out
' ppQueryResults : DNS_RECORDA** out
' pReserved : void** optional, out
Declare PtrSafe Function DnsQuery_W Lib "dnsapi" ( _
ByVal pszName As LongPtr, _
ByVal wType As Integer, _
ByVal Options As Long, _
ByVal pExtra As LongPtr, _
ByVal ppQueryResults As LongPtr, _
ByVal pReserved As LongPtr) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
DnsQuery_W = ctypes.windll.dnsapi.DnsQuery_W
DnsQuery_W.restype = wintypes.DWORD
DnsQuery_W.argtypes = [
wintypes.LPCWSTR, # pszName : LPCWSTR
ctypes.c_ushort, # wType : WORD
wintypes.DWORD, # Options : DNS_QUERY_OPTIONS
ctypes.POINTER(None), # pExtra : void* optional, in/out
ctypes.c_void_p, # ppQueryResults : DNS_RECORDA** out
ctypes.c_void_p, # pReserved : void** optional, out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('DNSAPI.dll')
DnsQuery_W = Fiddle::Function.new(
lib['DnsQuery_W'],
[
Fiddle::TYPE_VOIDP, # pszName : LPCWSTR
-Fiddle::TYPE_SHORT, # wType : WORD
-Fiddle::TYPE_INT, # Options : DNS_QUERY_OPTIONS
Fiddle::TYPE_VOIDP, # pExtra : void* optional, in/out
Fiddle::TYPE_VOIDP, # ppQueryResults : DNS_RECORDA** out
Fiddle::TYPE_VOIDP, # pReserved : void** optional, out
],
-Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "dnsapi")]
extern "system" {
fn DnsQuery_W(
pszName: *const u16, // LPCWSTR
wType: u16, // WORD
Options: u32, // DNS_QUERY_OPTIONS
pExtra: *mut (), // void* optional, in/out
ppQueryResults: *mut *mut DNS_RECORDA, // DNS_RECORDA** out
pReserved: *mut *mut () // void** optional, out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("DNSAPI.dll", CharSet = CharSet.Unicode)]
public static extern uint DnsQuery_W([MarshalAs(UnmanagedType.LPWStr)] string pszName, ushort wType, uint Options, IntPtr pExtra, IntPtr ppQueryResults, IntPtr pReserved);
"@
$api = Add-Type -MemberDefinition $sig -Name 'DNSAPI_DnsQuery_W' -Namespace Win32 -PassThru
# $api::DnsQuery_W(pszName, wType, Options, pExtra, ppQueryResults, pReserved)#uselib "DNSAPI.dll"
#func global DnsQuery_W "DnsQuery_W" wptr, wptr, wptr, wptr, wptr, wptr
; DnsQuery_W pszName, wType, Options, pExtra, varptr(ppQueryResults), pReserved ; 戻り値は stat
; pszName : LPCWSTR -> "wptr"
; wType : WORD -> "wptr"
; Options : DNS_QUERY_OPTIONS -> "wptr"
; pExtra : void* optional, in/out -> "wptr"
; ppQueryResults : DNS_RECORDA** out -> "wptr"
; pReserved : void** optional, out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "DNSAPI.dll" #cfunc global DnsQuery_W "DnsQuery_W" wstr, int, int, sptr, var, sptr ; res = DnsQuery_W(pszName, wType, Options, pExtra, ppQueryResults, pReserved) ; pszName : LPCWSTR -> "wstr" ; wType : WORD -> "int" ; Options : DNS_QUERY_OPTIONS -> "int" ; pExtra : void* optional, in/out -> "sptr" ; ppQueryResults : DNS_RECORDA** out -> "var" ; pReserved : void** optional, out -> "sptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "DNSAPI.dll" #cfunc global DnsQuery_W "DnsQuery_W" wstr, int, int, sptr, sptr, sptr ; res = DnsQuery_W(pszName, wType, Options, pExtra, varptr(ppQueryResults), pReserved) ; pszName : LPCWSTR -> "wstr" ; wType : WORD -> "int" ; Options : DNS_QUERY_OPTIONS -> "int" ; pExtra : void* optional, in/out -> "sptr" ; ppQueryResults : DNS_RECORDA** out -> "sptr" ; pReserved : void** optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; WIN32_ERROR DnsQuery_W(LPCWSTR pszName, WORD wType, DNS_QUERY_OPTIONS Options, void* pExtra, DNS_RECORDA** ppQueryResults, void** pReserved) #uselib "DNSAPI.dll" #cfunc global DnsQuery_W "DnsQuery_W" wstr, int, int, intptr, var, intptr ; res = DnsQuery_W(pszName, wType, Options, pExtra, ppQueryResults, pReserved) ; pszName : LPCWSTR -> "wstr" ; wType : WORD -> "int" ; Options : DNS_QUERY_OPTIONS -> "int" ; pExtra : void* optional, in/out -> "intptr" ; ppQueryResults : DNS_RECORDA** out -> "var" ; pReserved : void** optional, out -> "intptr" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; WIN32_ERROR DnsQuery_W(LPCWSTR pszName, WORD wType, DNS_QUERY_OPTIONS Options, void* pExtra, DNS_RECORDA** ppQueryResults, void** pReserved) #uselib "DNSAPI.dll" #cfunc global DnsQuery_W "DnsQuery_W" wstr, int, int, intptr, intptr, intptr ; res = DnsQuery_W(pszName, wType, Options, pExtra, varptr(ppQueryResults), pReserved) ; pszName : LPCWSTR -> "wstr" ; wType : WORD -> "int" ; Options : DNS_QUERY_OPTIONS -> "int" ; pExtra : void* optional, in/out -> "intptr" ; ppQueryResults : DNS_RECORDA** out -> "intptr" ; pReserved : void** optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
dnsapi = windows.NewLazySystemDLL("DNSAPI.dll")
procDnsQuery_W = dnsapi.NewProc("DnsQuery_W")
)
// pszName (LPCWSTR), wType (WORD), Options (DNS_QUERY_OPTIONS), pExtra (void* optional, in/out), ppQueryResults (DNS_RECORDA** out), pReserved (void** optional, out)
r1, _, err := procDnsQuery_W.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pszName))),
uintptr(wType),
uintptr(Options),
uintptr(pExtra),
uintptr(ppQueryResults),
uintptr(pReserved),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // WIN32_ERRORfunction DnsQuery_W(
pszName: PWideChar; // LPCWSTR
wType: Word; // WORD
Options: DWORD; // DNS_QUERY_OPTIONS
pExtra: Pointer; // void* optional, in/out
ppQueryResults: Pointer; // DNS_RECORDA** out
pReserved: Pointer // void** optional, out
): DWORD; stdcall;
external 'DNSAPI.dll' name 'DnsQuery_W';result := DllCall("DNSAPI\DnsQuery_W"
, "WStr", pszName ; LPCWSTR
, "UShort", wType ; WORD
, "UInt", Options ; DNS_QUERY_OPTIONS
, "Ptr", pExtra ; void* optional, in/out
, "Ptr", ppQueryResults ; DNS_RECORDA** out
, "Ptr", pReserved ; void** optional, out
, "UInt") ; return: WIN32_ERROR●DnsQuery_W(pszName, wType, Options, pExtra, ppQueryResults, pReserved) = DLL("DNSAPI.dll", "dword DnsQuery_W(char*, int, dword, void*, void*, void*)")
# 呼び出し: DnsQuery_W(pszName, wType, Options, pExtra, ppQueryResults, pReserved)
# pszName : LPCWSTR -> "char*"
# wType : WORD -> "int"
# Options : DNS_QUERY_OPTIONS -> "dword"
# pExtra : void* optional, in/out -> "void*"
# ppQueryResults : DNS_RECORDA** out -> "void*"
# pReserved : void** optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。