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