ホーム › Networking.WinSock › WSAAsyncGetHostByAddr
WSAAsyncGetHostByAddr
関数IPアドレスのホスト情報を非同期で取得する。
シグネチャ
// WS2_32.dll
#include <windows.h>
HANDLE WSAAsyncGetHostByAddr(
HWND hWnd,
DWORD wMsg,
LPCSTR addr,
INT len,
INT type,
LPSTR buf,
INT buflen
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hWnd | HWND | in |
| wMsg | DWORD | in |
| addr | LPCSTR | in |
| len | INT | in |
| type | INT | in |
| buf | LPSTR | out |
| buflen | INT | in |
戻り値の型: HANDLE
各言語での呼び出し定義
// WS2_32.dll
#include <windows.h>
HANDLE WSAAsyncGetHostByAddr(
HWND hWnd,
DWORD wMsg,
LPCSTR addr,
INT len,
INT type,
LPSTR buf,
INT buflen
);[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr WSAAsyncGetHostByAddr(
IntPtr hWnd, // HWND
uint wMsg, // DWORD
[MarshalAs(UnmanagedType.LPStr)] string addr, // LPCSTR
int len, // INT
int type, // INT
[MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder buf, // LPSTR out
int buflen // INT
);<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSAAsyncGetHostByAddr(
hWnd As IntPtr, ' HWND
wMsg As UInteger, ' DWORD
<MarshalAs(UnmanagedType.LPStr)> addr As String, ' LPCSTR
len As Integer, ' INT
type As Integer, ' INT
<MarshalAs(UnmanagedType.LPStr)> buf As System.Text.StringBuilder, ' LPSTR out
buflen As Integer ' INT
) As IntPtr
End Function' hWnd : HWND
' wMsg : DWORD
' addr : LPCSTR
' len : INT
' type : INT
' buf : LPSTR out
' buflen : INT
Declare PtrSafe Function WSAAsyncGetHostByAddr Lib "ws2_32" ( _
ByVal hWnd As LongPtr, _
ByVal wMsg As Long, _
ByVal addr As String, _
ByVal len As Long, _
ByVal type As Long, _
ByVal buf As String, _
ByVal buflen As Long) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WSAAsyncGetHostByAddr = ctypes.windll.ws2_32.WSAAsyncGetHostByAddr
WSAAsyncGetHostByAddr.restype = ctypes.c_void_p
WSAAsyncGetHostByAddr.argtypes = [
wintypes.HANDLE, # hWnd : HWND
wintypes.DWORD, # wMsg : DWORD
wintypes.LPCSTR, # addr : LPCSTR
ctypes.c_int, # len : INT
ctypes.c_int, # type : INT
wintypes.LPSTR, # buf : LPSTR out
ctypes.c_int, # buflen : INT
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WS2_32.dll')
WSAAsyncGetHostByAddr = Fiddle::Function.new(
lib['WSAAsyncGetHostByAddr'],
[
Fiddle::TYPE_VOIDP, # hWnd : HWND
-Fiddle::TYPE_INT, # wMsg : DWORD
Fiddle::TYPE_VOIDP, # addr : LPCSTR
Fiddle::TYPE_INT, # len : INT
Fiddle::TYPE_INT, # type : INT
Fiddle::TYPE_VOIDP, # buf : LPSTR out
Fiddle::TYPE_INT, # buflen : INT
],
Fiddle::TYPE_VOIDP)#[link(name = "ws2_32")]
extern "system" {
fn WSAAsyncGetHostByAddr(
hWnd: *mut core::ffi::c_void, // HWND
wMsg: u32, // DWORD
addr: *const u8, // LPCSTR
len: i32, // INT
type: i32, // INT
buf: *mut u8, // LPSTR out
buflen: i32 // INT
) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WS2_32.dll", SetLastError = true)]
public static extern IntPtr WSAAsyncGetHostByAddr(IntPtr hWnd, uint wMsg, [MarshalAs(UnmanagedType.LPStr)] string addr, int len, int type, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder buf, int buflen);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSAAsyncGetHostByAddr' -Namespace Win32 -PassThru
# $api::WSAAsyncGetHostByAddr(hWnd, wMsg, addr, len, type, buf, buflen)#uselib "WS2_32.dll"
#func global WSAAsyncGetHostByAddr "WSAAsyncGetHostByAddr" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; WSAAsyncGetHostByAddr hWnd, wMsg, addr, len, type, varptr(buf), buflen ; 戻り値は stat
; hWnd : HWND -> "sptr"
; wMsg : DWORD -> "sptr"
; addr : LPCSTR -> "sptr"
; len : INT -> "sptr"
; type : INT -> "sptr"
; buf : LPSTR out -> "sptr"
; buflen : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "WS2_32.dll" #cfunc global WSAAsyncGetHostByAddr "WSAAsyncGetHostByAddr" sptr, int, str, int, int, var, int ; res = WSAAsyncGetHostByAddr(hWnd, wMsg, addr, len, type, buf, buflen) ; hWnd : HWND -> "sptr" ; wMsg : DWORD -> "int" ; addr : LPCSTR -> "str" ; len : INT -> "int" ; type : INT -> "int" ; buf : LPSTR out -> "var" ; buflen : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WS2_32.dll" #cfunc global WSAAsyncGetHostByAddr "WSAAsyncGetHostByAddr" sptr, int, str, int, int, sptr, int ; res = WSAAsyncGetHostByAddr(hWnd, wMsg, addr, len, type, varptr(buf), buflen) ; hWnd : HWND -> "sptr" ; wMsg : DWORD -> "int" ; addr : LPCSTR -> "str" ; len : INT -> "int" ; type : INT -> "int" ; buf : LPSTR out -> "sptr" ; buflen : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; HANDLE WSAAsyncGetHostByAddr(HWND hWnd, DWORD wMsg, LPCSTR addr, INT len, INT type, LPSTR buf, INT buflen) #uselib "WS2_32.dll" #cfunc global WSAAsyncGetHostByAddr "WSAAsyncGetHostByAddr" intptr, int, str, int, int, var, int ; res = WSAAsyncGetHostByAddr(hWnd, wMsg, addr, len, type, buf, buflen) ; hWnd : HWND -> "intptr" ; wMsg : DWORD -> "int" ; addr : LPCSTR -> "str" ; len : INT -> "int" ; type : INT -> "int" ; buf : LPSTR out -> "var" ; buflen : INT -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; HANDLE WSAAsyncGetHostByAddr(HWND hWnd, DWORD wMsg, LPCSTR addr, INT len, INT type, LPSTR buf, INT buflen) #uselib "WS2_32.dll" #cfunc global WSAAsyncGetHostByAddr "WSAAsyncGetHostByAddr" intptr, int, str, int, int, intptr, int ; res = WSAAsyncGetHostByAddr(hWnd, wMsg, addr, len, type, varptr(buf), buflen) ; hWnd : HWND -> "intptr" ; wMsg : DWORD -> "int" ; addr : LPCSTR -> "str" ; len : INT -> "int" ; type : INT -> "int" ; buf : LPSTR out -> "intptr" ; buflen : INT -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
procWSAAsyncGetHostByAddr = ws2_32.NewProc("WSAAsyncGetHostByAddr")
)
// hWnd (HWND), wMsg (DWORD), addr (LPCSTR), len (INT), type (INT), buf (LPSTR out), buflen (INT)
r1, _, err := procWSAAsyncGetHostByAddr.Call(
uintptr(hWnd),
uintptr(wMsg),
uintptr(unsafe.Pointer(windows.BytePtrFromString(addr))),
uintptr(len),
uintptr(type),
uintptr(buf),
uintptr(buflen),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HANDLEfunction WSAAsyncGetHostByAddr(
hWnd: THandle; // HWND
wMsg: DWORD; // DWORD
addr: PAnsiChar; // LPCSTR
len: Integer; // INT
type: Integer; // INT
buf: PAnsiChar; // LPSTR out
buflen: Integer // INT
): THandle; stdcall;
external 'WS2_32.dll' name 'WSAAsyncGetHostByAddr';result := DllCall("WS2_32\WSAAsyncGetHostByAddr"
, "Ptr", hWnd ; HWND
, "UInt", wMsg ; DWORD
, "AStr", addr ; LPCSTR
, "Int", len ; INT
, "Int", type ; INT
, "Ptr", buf ; LPSTR out
, "Int", buflen ; INT
, "Ptr") ; return: HANDLE●WSAAsyncGetHostByAddr(hWnd, wMsg, addr, len, type, buf, buflen) = DLL("WS2_32.dll", "void* WSAAsyncGetHostByAddr(void*, dword, char*, int, int, char*, int)")
# 呼び出し: WSAAsyncGetHostByAddr(hWnd, wMsg, addr, len, type, buf, buflen)
# hWnd : HWND -> "void*"
# wMsg : DWORD -> "dword"
# addr : LPCSTR -> "char*"
# len : INT -> "int"
# type : INT -> "int"
# buf : LPSTR out -> "char*"
# buflen : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。