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

WSAEnumProtocolsA

関数
利用可能なトランスポートプロトコル情報を列挙する。
DLLWS2_32.dll文字セットANSI (-A)呼出規約winapiSetLastErrorあり対応OSWindows 8.1 以降

シグネチャ

// WS2_32.dll  (ANSI / -A)
#include <windows.h>

INT WSAEnumProtocolsA(
    INT* lpiProtocols,   // optional
    WSAPROTOCOL_INFOA* lpProtocolBuffer,   // optional
    DWORD* lpdwBufferLength
);

パラメーター

名前方向
lpiProtocolsINT*inoptional
lpProtocolBufferWSAPROTOCOL_INFOA*outoptional
lpdwBufferLengthDWORD*inout

戻り値の型: INT

各言語での呼び出し定義

// WS2_32.dll  (ANSI / -A)
#include <windows.h>

INT WSAEnumProtocolsA(
    INT* lpiProtocols,   // optional
    WSAPROTOCOL_INFOA* lpProtocolBuffer,   // optional
    DWORD* lpdwBufferLength
);
[DllImport("WS2_32.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern int WSAEnumProtocolsA(
    IntPtr lpiProtocols,   // INT* optional
    IntPtr lpProtocolBuffer,   // WSAPROTOCOL_INFOA* optional, out
    ref uint lpdwBufferLength   // DWORD* in/out
);
<DllImport("WS2_32.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WSAEnumProtocolsA(
    lpiProtocols As IntPtr,   ' INT* optional
    lpProtocolBuffer As IntPtr,   ' WSAPROTOCOL_INFOA* optional, out
    ByRef lpdwBufferLength As UInteger   ' DWORD* in/out
) As Integer
End Function
' lpiProtocols : INT* optional
' lpProtocolBuffer : WSAPROTOCOL_INFOA* optional, out
' lpdwBufferLength : DWORD* in/out
Declare PtrSafe Function WSAEnumProtocolsA Lib "ws2_32" ( _
    ByVal lpiProtocols As LongPtr, _
    ByVal lpProtocolBuffer As LongPtr, _
    ByRef lpdwBufferLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WSAEnumProtocolsA = ctypes.windll.ws2_32.WSAEnumProtocolsA
WSAEnumProtocolsA.restype = ctypes.c_int
WSAEnumProtocolsA.argtypes = [
    ctypes.POINTER(ctypes.c_int),  # lpiProtocols : INT* optional
    ctypes.c_void_p,  # lpProtocolBuffer : WSAPROTOCOL_INFOA* optional, out
    ctypes.POINTER(wintypes.DWORD),  # lpdwBufferLength : DWORD* in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WS2_32.dll')
WSAEnumProtocolsA = Fiddle::Function.new(
  lib['WSAEnumProtocolsA'],
  [
    Fiddle::TYPE_VOIDP,  # lpiProtocols : INT* optional
    Fiddle::TYPE_VOIDP,  # lpProtocolBuffer : WSAPROTOCOL_INFOA* optional, out
    Fiddle::TYPE_VOIDP,  # lpdwBufferLength : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "ws2_32")]
extern "system" {
    fn WSAEnumProtocolsA(
        lpiProtocols: *mut i32,  // INT* optional
        lpProtocolBuffer: *mut WSAPROTOCOL_INFOA,  // WSAPROTOCOL_INFOA* optional, out
        lpdwBufferLength: *mut u32  // DWORD* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WS2_32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int WSAEnumProtocolsA(IntPtr lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSAEnumProtocolsA' -Namespace Win32 -PassThru
# $api::WSAEnumProtocolsA(lpiProtocols, lpProtocolBuffer, lpdwBufferLength)
#uselib "WS2_32.dll"
#func global WSAEnumProtocolsA "WSAEnumProtocolsA" sptr, sptr, sptr
; WSAEnumProtocolsA varptr(lpiProtocols), varptr(lpProtocolBuffer), varptr(lpdwBufferLength)   ; 戻り値は stat
; lpiProtocols : INT* optional -> "sptr"
; lpProtocolBuffer : WSAPROTOCOL_INFOA* optional, out -> "sptr"
; lpdwBufferLength : DWORD* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WS2_32.dll"
#cfunc global WSAEnumProtocolsA "WSAEnumProtocolsA" var, var, var
; res = WSAEnumProtocolsA(lpiProtocols, lpProtocolBuffer, lpdwBufferLength)
; lpiProtocols : INT* optional -> "var"
; lpProtocolBuffer : WSAPROTOCOL_INFOA* optional, out -> "var"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT WSAEnumProtocolsA(INT* lpiProtocols, WSAPROTOCOL_INFOA* lpProtocolBuffer, DWORD* lpdwBufferLength)
#uselib "WS2_32.dll"
#cfunc global WSAEnumProtocolsA "WSAEnumProtocolsA" var, var, var
; res = WSAEnumProtocolsA(lpiProtocols, lpProtocolBuffer, lpdwBufferLength)
; lpiProtocols : INT* optional -> "var"
; lpProtocolBuffer : WSAPROTOCOL_INFOA* optional, out -> "var"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
	procWSAEnumProtocolsA = ws2_32.NewProc("WSAEnumProtocolsA")
)

// lpiProtocols (INT* optional), lpProtocolBuffer (WSAPROTOCOL_INFOA* optional, out), lpdwBufferLength (DWORD* in/out)
r1, _, err := procWSAEnumProtocolsA.Call(
	uintptr(lpiProtocols),
	uintptr(lpProtocolBuffer),
	uintptr(lpdwBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function WSAEnumProtocolsA(
  lpiProtocols: Pointer;   // INT* optional
  lpProtocolBuffer: Pointer;   // WSAPROTOCOL_INFOA* optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'WS2_32.dll' name 'WSAEnumProtocolsA';
result := DllCall("WS2_32\WSAEnumProtocolsA"
    , "Ptr", lpiProtocols   ; INT* optional
    , "Ptr", lpProtocolBuffer   ; WSAPROTOCOL_INFOA* optional, out
    , "Ptr", lpdwBufferLength   ; DWORD* in/out
    , "Int")   ; return: INT
●WSAEnumProtocolsA(lpiProtocols, lpProtocolBuffer, lpdwBufferLength) = DLL("WS2_32.dll", "int WSAEnumProtocolsA(void*, void*, void*)")
# 呼び出し: WSAEnumProtocolsA(lpiProtocols, lpProtocolBuffer, lpdwBufferLength)
# lpiProtocols : INT* optional -> "void*"
# lpProtocolBuffer : WSAPROTOCOL_INFOA* optional, out -> "void*"
# lpdwBufferLength : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。