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

WSAEnumProtocolsW

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

シグネチャ

// WS2_32.dll  (Unicode / -W)
#include <windows.h>

INT WSAEnumProtocolsW(
    INT* lpiProtocols,   // optional
    WSAPROTOCOL_INFOW* lpProtocolBuffer,   // optional
    DWORD* lpdwBufferLength
);

パラメーター

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

戻り値の型: INT

各言語での呼び出し定義

// WS2_32.dll  (Unicode / -W)
#include <windows.h>

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

WSAEnumProtocolsW = ctypes.windll.ws2_32.WSAEnumProtocolsW
WSAEnumProtocolsW.restype = ctypes.c_int
WSAEnumProtocolsW.argtypes = [
    ctypes.POINTER(ctypes.c_int),  # lpiProtocols : INT* optional
    ctypes.c_void_p,  # lpProtocolBuffer : WSAPROTOCOL_INFOW* 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')
WSAEnumProtocolsW = Fiddle::Function.new(
  lib['WSAEnumProtocolsW'],
  [
    Fiddle::TYPE_VOIDP,  # lpiProtocols : INT* optional
    Fiddle::TYPE_VOIDP,  # lpProtocolBuffer : WSAPROTOCOL_INFOW* optional, out
    Fiddle::TYPE_VOIDP,  # lpdwBufferLength : DWORD* in/out
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "ws2_32")]
extern "system" {
    fn WSAEnumProtocolsW(
        lpiProtocols: *mut i32,  // INT* optional
        lpProtocolBuffer: *mut WSAPROTOCOL_INFOW,  // WSAPROTOCOL_INFOW* 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.Unicode, SetLastError = true)]
public static extern int WSAEnumProtocolsW(IntPtr lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSAEnumProtocolsW' -Namespace Win32 -PassThru
# $api::WSAEnumProtocolsW(lpiProtocols, lpProtocolBuffer, lpdwBufferLength)
#uselib "WS2_32.dll"
#func global WSAEnumProtocolsW "WSAEnumProtocolsW" wptr, wptr, wptr
; WSAEnumProtocolsW varptr(lpiProtocols), varptr(lpProtocolBuffer), varptr(lpdwBufferLength)   ; 戻り値は stat
; lpiProtocols : INT* optional -> "wptr"
; lpProtocolBuffer : WSAPROTOCOL_INFOW* optional, out -> "wptr"
; lpdwBufferLength : DWORD* in/out -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WS2_32.dll"
#cfunc global WSAEnumProtocolsW "WSAEnumProtocolsW" var, var, var
; res = WSAEnumProtocolsW(lpiProtocols, lpProtocolBuffer, lpdwBufferLength)
; lpiProtocols : INT* optional -> "var"
; lpProtocolBuffer : WSAPROTOCOL_INFOW* optional, out -> "var"
; lpdwBufferLength : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT WSAEnumProtocolsW(INT* lpiProtocols, WSAPROTOCOL_INFOW* lpProtocolBuffer, DWORD* lpdwBufferLength)
#uselib "WS2_32.dll"
#cfunc global WSAEnumProtocolsW "WSAEnumProtocolsW" var, var, var
; res = WSAEnumProtocolsW(lpiProtocols, lpProtocolBuffer, lpdwBufferLength)
; lpiProtocols : INT* optional -> "var"
; lpProtocolBuffer : WSAPROTOCOL_INFOW* 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")
	procWSAEnumProtocolsW = ws2_32.NewProc("WSAEnumProtocolsW")
)

// lpiProtocols (INT* optional), lpProtocolBuffer (WSAPROTOCOL_INFOW* optional, out), lpdwBufferLength (DWORD* in/out)
r1, _, err := procWSAEnumProtocolsW.Call(
	uintptr(lpiProtocols),
	uintptr(lpProtocolBuffer),
	uintptr(lpdwBufferLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function WSAEnumProtocolsW(
  lpiProtocols: Pointer;   // INT* optional
  lpProtocolBuffer: Pointer;   // WSAPROTOCOL_INFOW* optional, out
  lpdwBufferLength: Pointer   // DWORD* in/out
): Integer; stdcall;
  external 'WS2_32.dll' name 'WSAEnumProtocolsW';
result := DllCall("WS2_32\WSAEnumProtocolsW"
    , "Ptr", lpiProtocols   ; INT* optional
    , "Ptr", lpProtocolBuffer   ; WSAPROTOCOL_INFOW* optional, out
    , "Ptr", lpdwBufferLength   ; DWORD* in/out
    , "Int")   ; return: INT
●WSAEnumProtocolsW(lpiProtocols, lpProtocolBuffer, lpdwBufferLength) = DLL("WS2_32.dll", "int WSAEnumProtocolsW(void*, void*, void*)")
# 呼び出し: WSAEnumProtocolsW(lpiProtocols, lpProtocolBuffer, lpdwBufferLength)
# lpiProtocols : INT* optional -> "void*"
# lpProtocolBuffer : WSAPROTOCOL_INFOW* optional, out -> "void*"
# lpdwBufferLength : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。