Win32 API 日本語リファレンス
ホームNetworking.WinSock › WSAAsyncGetProtoByNumber

WSAAsyncGetProtoByNumber

関数
プロトコル番号のプロトコル情報を非同期で取得する。
DLLWS2_32.dll呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

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

HANDLE WSAAsyncGetProtoByNumber(
    HWND hWnd,
    DWORD wMsg,
    INT number,
    LPSTR buf,
    INT buflen
);

パラメーター

名前方向
hWndHWNDin
wMsgDWORDin
numberINTin
bufLPSTRout
buflenINTin

戻り値の型: HANDLE

各言語での呼び出し定義

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

HANDLE WSAAsyncGetProtoByNumber(
    HWND hWnd,
    DWORD wMsg,
    INT number,
    LPSTR buf,
    INT buflen
);
[DllImport("WS2_32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr WSAAsyncGetProtoByNumber(
    IntPtr hWnd,   // HWND
    uint wMsg,   // DWORD
    int number,   // INT
    [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder buf,   // LPSTR out
    int buflen   // INT
);
<DllImport("WS2_32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSAAsyncGetProtoByNumber(
    hWnd As IntPtr,   ' HWND
    wMsg As UInteger,   ' DWORD
    number 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
' number : INT
' buf : LPSTR out
' buflen : INT
Declare PtrSafe Function WSAAsyncGetProtoByNumber Lib "ws2_32" ( _
    ByVal hWnd As LongPtr, _
    ByVal wMsg As Long, _
    ByVal number 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

WSAAsyncGetProtoByNumber = ctypes.windll.ws2_32.WSAAsyncGetProtoByNumber
WSAAsyncGetProtoByNumber.restype = ctypes.c_void_p
WSAAsyncGetProtoByNumber.argtypes = [
    wintypes.HANDLE,  # hWnd : HWND
    wintypes.DWORD,  # wMsg : DWORD
    ctypes.c_int,  # number : 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')
WSAAsyncGetProtoByNumber = Fiddle::Function.new(
  lib['WSAAsyncGetProtoByNumber'],
  [
    Fiddle::TYPE_VOIDP,  # hWnd : HWND
    -Fiddle::TYPE_INT,  # wMsg : DWORD
    Fiddle::TYPE_INT,  # number : INT
    Fiddle::TYPE_VOIDP,  # buf : LPSTR out
    Fiddle::TYPE_INT,  # buflen : INT
  ],
  Fiddle::TYPE_VOIDP)
#[link(name = "ws2_32")]
extern "system" {
    fn WSAAsyncGetProtoByNumber(
        hWnd: *mut core::ffi::c_void,  // HWND
        wMsg: u32,  // DWORD
        number: 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 WSAAsyncGetProtoByNumber(IntPtr hWnd, uint wMsg, int number, [MarshalAs(UnmanagedType.LPStr)] System.Text.StringBuilder buf, int buflen);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSAAsyncGetProtoByNumber' -Namespace Win32 -PassThru
# $api::WSAAsyncGetProtoByNumber(hWnd, wMsg, number, buf, buflen)
#uselib "WS2_32.dll"
#func global WSAAsyncGetProtoByNumber "WSAAsyncGetProtoByNumber" sptr, sptr, sptr, sptr, sptr
; WSAAsyncGetProtoByNumber hWnd, wMsg, number, varptr(buf), buflen   ; 戻り値は stat
; hWnd : HWND -> "sptr"
; wMsg : DWORD -> "sptr"
; number : INT -> "sptr"
; buf : LPSTR out -> "sptr"
; buflen : INT -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WS2_32.dll"
#cfunc global WSAAsyncGetProtoByNumber "WSAAsyncGetProtoByNumber" sptr, int, int, var, int
; res = WSAAsyncGetProtoByNumber(hWnd, wMsg, number, buf, buflen)
; hWnd : HWND -> "sptr"
; wMsg : DWORD -> "int"
; number : INT -> "int"
; buf : LPSTR out -> "var"
; buflen : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE WSAAsyncGetProtoByNumber(HWND hWnd, DWORD wMsg, INT number, LPSTR buf, INT buflen)
#uselib "WS2_32.dll"
#cfunc global WSAAsyncGetProtoByNumber "WSAAsyncGetProtoByNumber" intptr, int, int, var, int
; res = WSAAsyncGetProtoByNumber(hWnd, wMsg, number, buf, buflen)
; hWnd : HWND -> "intptr"
; wMsg : DWORD -> "int"
; number : INT -> "int"
; buf : LPSTR out -> "var"
; buflen : INT -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
	procWSAAsyncGetProtoByNumber = ws2_32.NewProc("WSAAsyncGetProtoByNumber")
)

// hWnd (HWND), wMsg (DWORD), number (INT), buf (LPSTR out), buflen (INT)
r1, _, err := procWSAAsyncGetProtoByNumber.Call(
	uintptr(hWnd),
	uintptr(wMsg),
	uintptr(number),
	uintptr(buf),
	uintptr(buflen),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function WSAAsyncGetProtoByNumber(
  hWnd: THandle;   // HWND
  wMsg: DWORD;   // DWORD
  number: Integer;   // INT
  buf: PAnsiChar;   // LPSTR out
  buflen: Integer   // INT
): THandle; stdcall;
  external 'WS2_32.dll' name 'WSAAsyncGetProtoByNumber';
result := DllCall("WS2_32\WSAAsyncGetProtoByNumber"
    , "Ptr", hWnd   ; HWND
    , "UInt", wMsg   ; DWORD
    , "Int", number   ; INT
    , "Ptr", buf   ; LPSTR out
    , "Int", buflen   ; INT
    , "Ptr")   ; return: HANDLE
●WSAAsyncGetProtoByNumber(hWnd, wMsg, number, buf, buflen) = DLL("WS2_32.dll", "void* WSAAsyncGetProtoByNumber(void*, dword, int, char*, int)")
# 呼び出し: WSAAsyncGetProtoByNumber(hWnd, wMsg, number, buf, buflen)
# hWnd : HWND -> "void*"
# wMsg : DWORD -> "dword"
# number : INT -> "int"
# buf : LPSTR out -> "char*"
# buflen : INT -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。