ホーム › Networking.WinSock › GetAddrInfoW
GetAddrInfoW
関数ホスト名やサービス名からアドレス情報を解決する。
シグネチャ
// WS2_32.dll
#include <windows.h>
INT GetAddrInfoW(
LPCWSTR pNodeName, // optional
LPCWSTR pServiceName, // optional
const ADDRINFOW* pHints, // optional
ADDRINFOW** ppResult
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| pNodeName | LPCWSTR | inoptional |
| pServiceName | LPCWSTR | inoptional |
| pHints | ADDRINFOW* | inoptional |
| ppResult | ADDRINFOW** | out |
戻り値の型: INT
各言語での呼び出し定義
// WS2_32.dll
#include <windows.h>
INT GetAddrInfoW(
LPCWSTR pNodeName, // optional
LPCWSTR pServiceName, // optional
const ADDRINFOW* pHints, // optional
ADDRINFOW** ppResult
);[DllImport("WS2_32.dll", ExactSpelling = true)]
static extern int GetAddrInfoW(
[MarshalAs(UnmanagedType.LPWStr)] string pNodeName, // LPCWSTR optional
[MarshalAs(UnmanagedType.LPWStr)] string pServiceName, // LPCWSTR optional
IntPtr pHints, // ADDRINFOW* optional
IntPtr ppResult // ADDRINFOW** out
);<DllImport("WS2_32.dll", ExactSpelling:=True)>
Public Shared Function GetAddrInfoW(
<MarshalAs(UnmanagedType.LPWStr)> pNodeName As String, ' LPCWSTR optional
<MarshalAs(UnmanagedType.LPWStr)> pServiceName As String, ' LPCWSTR optional
pHints As IntPtr, ' ADDRINFOW* optional
ppResult As IntPtr ' ADDRINFOW** out
) As Integer
End Function' pNodeName : LPCWSTR optional
' pServiceName : LPCWSTR optional
' pHints : ADDRINFOW* optional
' ppResult : ADDRINFOW** out
Declare PtrSafe Function GetAddrInfoW Lib "ws2_32" ( _
ByVal pNodeName As LongPtr, _
ByVal pServiceName As LongPtr, _
ByVal pHints As LongPtr, _
ByVal ppResult As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetAddrInfoW = ctypes.windll.ws2_32.GetAddrInfoW
GetAddrInfoW.restype = ctypes.c_int
GetAddrInfoW.argtypes = [
wintypes.LPCWSTR, # pNodeName : LPCWSTR optional
wintypes.LPCWSTR, # pServiceName : LPCWSTR optional
ctypes.c_void_p, # pHints : ADDRINFOW* optional
ctypes.c_void_p, # ppResult : ADDRINFOW** out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WS2_32.dll')
GetAddrInfoW = Fiddle::Function.new(
lib['GetAddrInfoW'],
[
Fiddle::TYPE_VOIDP, # pNodeName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pServiceName : LPCWSTR optional
Fiddle::TYPE_VOIDP, # pHints : ADDRINFOW* optional
Fiddle::TYPE_VOIDP, # ppResult : ADDRINFOW** out
],
Fiddle::TYPE_INT)#[link(name = "ws2_32")]
extern "system" {
fn GetAddrInfoW(
pNodeName: *const u16, // LPCWSTR optional
pServiceName: *const u16, // LPCWSTR optional
pHints: *const ADDRINFOW, // ADDRINFOW* optional
ppResult: *mut *mut ADDRINFOW // ADDRINFOW** out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WS2_32.dll")]
public static extern int GetAddrInfoW([MarshalAs(UnmanagedType.LPWStr)] string pNodeName, [MarshalAs(UnmanagedType.LPWStr)] string pServiceName, IntPtr pHints, IntPtr ppResult);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_GetAddrInfoW' -Namespace Win32 -PassThru
# $api::GetAddrInfoW(pNodeName, pServiceName, pHints, ppResult)#uselib "WS2_32.dll"
#func global GetAddrInfoW "GetAddrInfoW" sptr, sptr, sptr, sptr
; GetAddrInfoW pNodeName, pServiceName, varptr(pHints), varptr(ppResult) ; 戻り値は stat
; pNodeName : LPCWSTR optional -> "sptr"
; pServiceName : LPCWSTR optional -> "sptr"
; pHints : ADDRINFOW* optional -> "sptr"
; ppResult : ADDRINFOW** out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WS2_32.dll" #cfunc global GetAddrInfoW "GetAddrInfoW" wstr, wstr, var, var ; res = GetAddrInfoW(pNodeName, pServiceName, pHints, ppResult) ; pNodeName : LPCWSTR optional -> "wstr" ; pServiceName : LPCWSTR optional -> "wstr" ; pHints : ADDRINFOW* optional -> "var" ; ppResult : ADDRINFOW** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WS2_32.dll" #cfunc global GetAddrInfoW "GetAddrInfoW" wstr, wstr, sptr, sptr ; res = GetAddrInfoW(pNodeName, pServiceName, varptr(pHints), varptr(ppResult)) ; pNodeName : LPCWSTR optional -> "wstr" ; pServiceName : LPCWSTR optional -> "wstr" ; pHints : ADDRINFOW* optional -> "sptr" ; ppResult : ADDRINFOW** out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT GetAddrInfoW(LPCWSTR pNodeName, LPCWSTR pServiceName, ADDRINFOW* pHints, ADDRINFOW** ppResult) #uselib "WS2_32.dll" #cfunc global GetAddrInfoW "GetAddrInfoW" wstr, wstr, var, var ; res = GetAddrInfoW(pNodeName, pServiceName, pHints, ppResult) ; pNodeName : LPCWSTR optional -> "wstr" ; pServiceName : LPCWSTR optional -> "wstr" ; pHints : ADDRINFOW* optional -> "var" ; ppResult : ADDRINFOW** out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT GetAddrInfoW(LPCWSTR pNodeName, LPCWSTR pServiceName, ADDRINFOW* pHints, ADDRINFOW** ppResult) #uselib "WS2_32.dll" #cfunc global GetAddrInfoW "GetAddrInfoW" wstr, wstr, intptr, intptr ; res = GetAddrInfoW(pNodeName, pServiceName, varptr(pHints), varptr(ppResult)) ; pNodeName : LPCWSTR optional -> "wstr" ; pServiceName : LPCWSTR optional -> "wstr" ; pHints : ADDRINFOW* optional -> "intptr" ; ppResult : ADDRINFOW** out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
procGetAddrInfoW = ws2_32.NewProc("GetAddrInfoW")
)
// pNodeName (LPCWSTR optional), pServiceName (LPCWSTR optional), pHints (ADDRINFOW* optional), ppResult (ADDRINFOW** out)
r1, _, err := procGetAddrInfoW.Call(
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pNodeName))),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(pServiceName))),
uintptr(pHints),
uintptr(ppResult),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction GetAddrInfoW(
pNodeName: PWideChar; // LPCWSTR optional
pServiceName: PWideChar; // LPCWSTR optional
pHints: Pointer; // ADDRINFOW* optional
ppResult: Pointer // ADDRINFOW** out
): Integer; stdcall;
external 'WS2_32.dll' name 'GetAddrInfoW';result := DllCall("WS2_32\GetAddrInfoW"
, "WStr", pNodeName ; LPCWSTR optional
, "WStr", pServiceName ; LPCWSTR optional
, "Ptr", pHints ; ADDRINFOW* optional
, "Ptr", ppResult ; ADDRINFOW** out
, "Int") ; return: INT●GetAddrInfoW(pNodeName, pServiceName, pHints, ppResult) = DLL("WS2_32.dll", "int GetAddrInfoW(char*, char*, void*, void*)")
# 呼び出し: GetAddrInfoW(pNodeName, pServiceName, pHints, ppResult)
# pNodeName : LPCWSTR optional -> "char*"
# pServiceName : LPCWSTR optional -> "char*"
# pHints : ADDRINFOW* optional -> "void*"
# ppResult : ADDRINFOW** out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。