WSCEnumProtocols32
関数シグネチャ
// WS2_32.dll
#include <windows.h>
INT WSCEnumProtocols32(
INT* lpiProtocols, // optional
WSAPROTOCOL_INFOW* lpProtocolBuffer,
DWORD* lpdwBufferLength,
INT* lpErrno
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| lpiProtocols | INT* | inoptional | iProtocol 値の null 終端配列です。このパラメーターは省略可能です。lpiProtocols が null の場合、利用可能なすべてのプロトコルに関する情報が返されます。そうでない場合は、配列に列挙されたプロトコルについてのみ情報が取得されます。 |
| lpProtocolBuffer | WSAPROTOCOL_INFOW* | out | WSAPROTOCOL_INFOW 構造体で埋められるバッファーです。 |
| lpdwBufferLength | DWORD* | inout | 入力時には、 WSCEnumProtocols に渡す lpProtocolBuffer バッファーのサイズ(バイト単位)です。出力時には、要求されたすべての情報を取得するために WSCEnumProtocols に渡せる最小バッファーサイズ(バイト単位)です。 |
| lpErrno | INT* | out | エラーコードへのポインターです。 |
戻り値の型: INT
公式ドキュメント
利用可能なトランスポートプロトコルに関する情報を取得します。Note この呼び出しは、64 ビットプラットフォームで使用するための厳密に 32 ビット版の WSCEnumProtocols です。64 ビットプロセスが 32 ビットカタログにアクセスできるようにするために提供されています。
戻り値
エラーが発生しなかった場合、 WSCEnumProtocols32 は報告対象となるプロトコルの数を返します。それ以外の場合は SOCKET_ERROR が返され、lpErrno で具体的なエラーコードを取得できます。
| エラーコード | 意味 |
|---|---|
| 1 つ以上の引数が、ユーザーアドレス空間の有効な部分にありません。 | |
| 指定されたパラメーターの 1 つが無効であることを示します。 | |
| バッファー長が小さすぎて、関連するすべての WSAProtocol_Info 構造体と関連情報を受け取れませんでした。lpdwBufferLength で返された値以上のサイズのバッファーを渡してください。 |
解説(Remarks)
WSCEnumProtocols32 は、厳密に 32 ビット版の WSCEnumProtocols です。64 ビットコンピューターでは、特に 32 ビットでない呼び出し(たとえば末尾が "32" で終わらないすべての関数)は、ネイティブの 64 ビットカタログを操作します。64 ビットコンピューター上で実行されるプロセスは、厳密に 32 ビットのカタログを操作して互換性を維持するために、専用の 32 ビット関数呼び出しを使用する必要があります。専用の 32 ビット呼び出しの定義とセマンティクスは、対応するネイティブ版と同じです。
この関数は、ローカルコンピューターにインストールされているトランスポートプロトコルの集合に関する情報を取得するために使用します。この関数は、API 版の対応関数(WSAEnumProtocols)とは異なり、インストールされているすべてのプロトコルについて WSAPROTOCOL_INFOW 構造体が返されます。これには、サービスプロバイダーが WSAPROTOCOL_INFOW 構造体の dwProviderFlags メンバーに PFL_HIDDEN フラグを設定し、このプロトコルを WSAEnumProtocols 関数が生成する結果バッファーに返さないよう Ws2_32.dll に指示したプロトコルも含まれます。さらに、WSCEnumProtocols32 は、チェーン長が 0 の WSAPROTOCOL_INFOW 構造体(ダミー LSP プロバイダー)のデータも返します。WSAEnumProtocols は、PFL_HIDDEN フラグを持たず、かつプロトコルチェーン長が 0 でない基本プロトコルおよびプロトコルチェーンに関する情報のみを返します。
要求された各プロトコルについて、lpProtocolBuffer が指すバッファー内に WSAPROTOCOL_INFOW 構造体が格納されます。指定したバッファーが十分な大きさでない場合(lpdwBufferLength の入力値で示される)、lpdwBufferLength が指す値が更新され、必要なバッファーサイズが示されます。その場合、Windows Sockets SPI クライアントは十分な大きさのバッファーを取得して、この関数を再度呼び出す必要があります。 WSCEnumProtocols32 関数は複数回の呼び出しにわたって列挙することはできません。関数が成功するには、渡すバッファーが想定されるすべてのエントリを保持できる十分な大きさである必要があります。これにより関数の複雑さが軽減され、また通常コンピューターに読み込まれているプロトコルの数は少ないため、問題にはならないはずです。
バッファー内に WSAPROTOCOL_INFOW 構造体が現れる順序は、サービスプロバイダーが WS2_32.dll にプロトコルエントリを登録した順序、または既定のトランスポートプロバイダーを設定するために提供される Windows Sockets アプレットを通じて後から並べ替えが行われた場合はその順序と一致します。
Examples
次の例は、64 ビットプラットフォームで使用する WSCEnumProtocols32 関数を使用して、ローカルコンピューターの 32 ビットカタログにインストールされているプロトコルの WSAPROTOCOL_INFOW 構造体の配列を取得する方法を示しています。
#ifndef UNICODE
#define UNICODE 1
#endif
#include <winsock2.h>
#include <ws2tcpip.h>
#include <ws2spi.h>
#include <objbase.h>
#include <stdio.h>
// Link with ws2_32.lib and ole32.lib
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "ole32.lib")
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
#define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
// Note: could also use malloc() and free()
int wmain()
{
//-----------------------------------------
// Declare and initialize variables
WSADATA wsaData;
int iResult = 0;
INT iNuminfo = 0;
int i;
// Allocate a 16K buffer to retrieve all the protocol providers
DWORD dwBufferLen = 16384;
LPWSAPROTOCOL_INFOW lpProtocolInfo = NULL;
int iErrno = 0;
// variables needed for converting provider GUID to a string
int iRet = 0;
WCHAR GuidString[40] = { 0 };
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
wprintf(L"WSAStartup failed: %d\n", iResult);
return 1;
}
lpProtocolInfo = (LPWSAPROTOCOL_INFOW) MALLOC(dwBufferLen);
if (lpProtocolInfo == NULL) {
wprintf(L"Memory allocation for providers buffer failed\n");
WSACleanup();
return 1;
}
iNuminfo = WSCEnumProtocols32(NULL, lpProtocolInfo, &dwBufferLen, &iErrno);
if (iNuminfo == SOCKET_ERROR) {
if (iErrno != WSAENOBUFS) {
wprintf(L"WSCEnumProtocols32 failed with error: %d\n", iErrno);
if (lpProtocolInfo) {
FREE(lpProtocolInfo);
lpProtocolInfo = NULL;
}
WSACleanup();
return 1;
} else {
wprintf(L"WSCEnumProtocols32 failed with error: WSAENOBUFS (%d)\n",
iErrno);
wprintf(L" Increasing buffer size to %d\n\n", dwBufferLen);
if (lpProtocolInfo) {
FREE(lpProtocolInfo);
lpProtocolInfo = NULL;
}
lpProtocolInfo = (LPWSAPROTOCOL_INFOW) MALLOC(dwBufferLen);
if (lpProtocolInfo == NULL) {
wprintf(L"Memory allocation increase for buffer failed\n");
WSACleanup();
return 1;
}
iNuminfo =
WSCEnumProtocols32(NULL, lpProtocolInfo, &dwBufferLen, &iErrno);
if (iNuminfo == SOCKET_ERROR) {
wprintf(L"WSCEnumProtocols32 failed with error: %d\n", iErrno);
if (lpProtocolInfo) {
FREE(lpProtocolInfo);
lpProtocolInfo = NULL;
}
WSACleanup();
return 1;
}
}
}
wprintf(L"WSCEnumProtocols32 succeeded with protocol count = %d\n\n",
iNuminfo);
for (i = 0; i < iNuminfo; i++) {
wprintf(L"Winsock Catalog Provider Entry #%d\n", i);
wprintf
(L"----------------------------------------------------------\n");
wprintf(L"Entry type:\t\t\t ");
if (lpProtocolInfo[i].ProtocolChain.ChainLen = 1)
wprintf(L"Base Service Provider\n");
else
wprintf(L"Layered Chain Entry\n");
wprintf(L"Protocol:\t\t\t %ws\n", lpProtocolInfo[i].szProtocol);
iRet =
StringFromGUID2(lpProtocolInfo[i].ProviderId,
(LPOLESTR) & GuidString, 39);
if (iRet == 0)
wprintf(L"StringFromGUID2 failed\n");
else
wprintf(L"Provider ID:\t\t\t %ws\n", GuidString);
wprintf(L"Catalog Entry ID:\t\t %u\n",
lpProtocolInfo[i].dwCatalogEntryId);
wprintf(L"Version:\t\t\t %d\n", lpProtocolInfo[i].iVersion);
wprintf(L"Address Family:\t\t\t %d\n",
lpProtocolInfo[i].iAddressFamily);
wprintf(L"Max Socket Address Length:\t %d\n",
lpProtocolInfo[i].iMaxSockAddr);
wprintf(L"Min Socket Address Length:\t %d\n",
lpProtocolInfo[i].iMinSockAddr);
wprintf(L"Socket Type:\t\t\t %d\n", lpProtocolInfo[i].iSocketType);
wprintf(L"Socket Protocol:\t\t %d\n", lpProtocolInfo[i].iProtocol);
wprintf(L"Socket Protocol Max Offset:\t %d\n",
lpProtocolInfo[i].iProtocolMaxOffset);
wprintf(L"Network Byte Order:\t\t %d\n",
lpProtocolInfo[i].iNetworkByteOrder);
wprintf(L"Security Scheme:\t\t %d\n",
lpProtocolInfo[i].iSecurityScheme);
wprintf(L"Max Message Size:\t\t %u\n", lpProtocolInfo[i].dwMessageSize);
wprintf(L"ServiceFlags1:\t\t\t 0x%x\n",
lpProtocolInfo[i].dwServiceFlags1);
wprintf(L"ServiceFlags2:\t\t\t 0x%x\n",
lpProtocolInfo[i].dwServiceFlags2);
wprintf(L"ServiceFlags3:\t\t\t 0x%x\n",
lpProtocolInfo[i].dwServiceFlags3);
wprintf(L"ServiceFlags4:\t\t\t 0x%x\n",
lpProtocolInfo[i].dwServiceFlags4);
wprintf(L"ProviderFlags:\t\t\t 0x%x\n",
lpProtocolInfo[i].dwProviderFlags);
wprintf(L"Protocol Chain length:\t\t %d\n",
lpProtocolInfo[i].ProtocolChain.ChainLen);
wprintf(L"\n");
}
if (lpProtocolInfo) {
FREE(lpProtocolInfo);
lpProtocolInfo = NULL;
}
WSACleanup();
return 0;
}
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// WS2_32.dll
#include <windows.h>
INT WSCEnumProtocols32(
INT* lpiProtocols, // optional
WSAPROTOCOL_INFOW* lpProtocolBuffer,
DWORD* lpdwBufferLength,
INT* lpErrno
);[DllImport("WS2_32.dll", ExactSpelling = true)]
static extern int WSCEnumProtocols32(
IntPtr lpiProtocols, // INT* optional
IntPtr lpProtocolBuffer, // WSAPROTOCOL_INFOW* out
ref uint lpdwBufferLength, // DWORD* in/out
out int lpErrno // INT* out
);<DllImport("WS2_32.dll", ExactSpelling:=True)>
Public Shared Function WSCEnumProtocols32(
lpiProtocols As IntPtr, ' INT* optional
lpProtocolBuffer As IntPtr, ' WSAPROTOCOL_INFOW* out
ByRef lpdwBufferLength As UInteger, ' DWORD* in/out
<Out> ByRef lpErrno As Integer ' INT* out
) As Integer
End Function' lpiProtocols : INT* optional
' lpProtocolBuffer : WSAPROTOCOL_INFOW* out
' lpdwBufferLength : DWORD* in/out
' lpErrno : INT* out
Declare PtrSafe Function WSCEnumProtocols32 Lib "ws2_32" ( _
ByVal lpiProtocols As LongPtr, _
ByVal lpProtocolBuffer As LongPtr, _
ByRef lpdwBufferLength As Long, _
ByRef lpErrno As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
WSCEnumProtocols32 = ctypes.windll.ws2_32.WSCEnumProtocols32
WSCEnumProtocols32.restype = ctypes.c_int
WSCEnumProtocols32.argtypes = [
ctypes.POINTER(ctypes.c_int), # lpiProtocols : INT* optional
ctypes.c_void_p, # lpProtocolBuffer : WSAPROTOCOL_INFOW* out
ctypes.POINTER(wintypes.DWORD), # lpdwBufferLength : DWORD* in/out
ctypes.POINTER(ctypes.c_int), # lpErrno : INT* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WS2_32.dll')
WSCEnumProtocols32 = Fiddle::Function.new(
lib['WSCEnumProtocols32'],
[
Fiddle::TYPE_VOIDP, # lpiProtocols : INT* optional
Fiddle::TYPE_VOIDP, # lpProtocolBuffer : WSAPROTOCOL_INFOW* out
Fiddle::TYPE_VOIDP, # lpdwBufferLength : DWORD* in/out
Fiddle::TYPE_VOIDP, # lpErrno : INT* out
],
Fiddle::TYPE_INT)#[link(name = "ws2_32")]
extern "system" {
fn WSCEnumProtocols32(
lpiProtocols: *mut i32, // INT* optional
lpProtocolBuffer: *mut WSAPROTOCOL_INFOW, // WSAPROTOCOL_INFOW* out
lpdwBufferLength: *mut u32, // DWORD* in/out
lpErrno: *mut i32 // INT* out
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("WS2_32.dll")]
public static extern int WSCEnumProtocols32(IntPtr lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WS2_32_WSCEnumProtocols32' -Namespace Win32 -PassThru
# $api::WSCEnumProtocols32(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno)#uselib "WS2_32.dll"
#func global WSCEnumProtocols32 "WSCEnumProtocols32" sptr, sptr, sptr, sptr
; WSCEnumProtocols32 varptr(lpiProtocols), varptr(lpProtocolBuffer), varptr(lpdwBufferLength), varptr(lpErrno) ; 戻り値は stat
; lpiProtocols : INT* optional -> "sptr"
; lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> "sptr"
; lpdwBufferLength : DWORD* in/out -> "sptr"
; lpErrno : INT* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WS2_32.dll" #cfunc global WSCEnumProtocols32 "WSCEnumProtocols32" var, var, var, var ; res = WSCEnumProtocols32(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno) ; lpiProtocols : INT* optional -> "var" ; lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> "var" ; lpdwBufferLength : DWORD* in/out -> "var" ; lpErrno : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "WS2_32.dll" #cfunc global WSCEnumProtocols32 "WSCEnumProtocols32" sptr, sptr, sptr, sptr ; res = WSCEnumProtocols32(varptr(lpiProtocols), varptr(lpProtocolBuffer), varptr(lpdwBufferLength), varptr(lpErrno)) ; lpiProtocols : INT* optional -> "sptr" ; lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> "sptr" ; lpdwBufferLength : DWORD* in/out -> "sptr" ; lpErrno : INT* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; INT WSCEnumProtocols32(INT* lpiProtocols, WSAPROTOCOL_INFOW* lpProtocolBuffer, DWORD* lpdwBufferLength, INT* lpErrno) #uselib "WS2_32.dll" #cfunc global WSCEnumProtocols32 "WSCEnumProtocols32" var, var, var, var ; res = WSCEnumProtocols32(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno) ; lpiProtocols : INT* optional -> "var" ; lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> "var" ; lpdwBufferLength : DWORD* in/out -> "var" ; lpErrno : INT* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT WSCEnumProtocols32(INT* lpiProtocols, WSAPROTOCOL_INFOW* lpProtocolBuffer, DWORD* lpdwBufferLength, INT* lpErrno) #uselib "WS2_32.dll" #cfunc global WSCEnumProtocols32 "WSCEnumProtocols32" intptr, intptr, intptr, intptr ; res = WSCEnumProtocols32(varptr(lpiProtocols), varptr(lpProtocolBuffer), varptr(lpdwBufferLength), varptr(lpErrno)) ; lpiProtocols : INT* optional -> "intptr" ; lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> "intptr" ; lpdwBufferLength : DWORD* in/out -> "intptr" ; lpErrno : INT* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
ws2_32 = windows.NewLazySystemDLL("WS2_32.dll")
procWSCEnumProtocols32 = ws2_32.NewProc("WSCEnumProtocols32")
)
// lpiProtocols (INT* optional), lpProtocolBuffer (WSAPROTOCOL_INFOW* out), lpdwBufferLength (DWORD* in/out), lpErrno (INT* out)
r1, _, err := procWSCEnumProtocols32.Call(
uintptr(lpiProtocols),
uintptr(lpProtocolBuffer),
uintptr(lpdwBufferLength),
uintptr(lpErrno),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction WSCEnumProtocols32(
lpiProtocols: Pointer; // INT* optional
lpProtocolBuffer: Pointer; // WSAPROTOCOL_INFOW* out
lpdwBufferLength: Pointer; // DWORD* in/out
lpErrno: Pointer // INT* out
): Integer; stdcall;
external 'WS2_32.dll' name 'WSCEnumProtocols32';result := DllCall("WS2_32\WSCEnumProtocols32"
, "Ptr", lpiProtocols ; INT* optional
, "Ptr", lpProtocolBuffer ; WSAPROTOCOL_INFOW* out
, "Ptr", lpdwBufferLength ; DWORD* in/out
, "Ptr", lpErrno ; INT* out
, "Int") ; return: INT●WSCEnumProtocols32(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno) = DLL("WS2_32.dll", "int WSCEnumProtocols32(void*, void*, void*, void*)")
# 呼び出し: WSCEnumProtocols32(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno)
# lpiProtocols : INT* optional -> "void*"
# lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> "void*"
# lpdwBufferLength : DWORD* in/out -> "void*"
# lpErrno : INT* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "ws2_32" fn WSCEnumProtocols32(
lpiProtocols: [*c]i32, // INT* optional
lpProtocolBuffer: [*c]WSAPROTOCOL_INFOW, // WSAPROTOCOL_INFOW* out
lpdwBufferLength: [*c]u32, // DWORD* in/out
lpErrno: [*c]i32 // INT* out
) callconv(std.os.windows.WINAPI) i32;proc WSCEnumProtocols32(
lpiProtocols: ptr int32, # INT* optional
lpProtocolBuffer: ptr WSAPROTOCOL_INFOW, # WSAPROTOCOL_INFOW* out
lpdwBufferLength: ptr uint32, # DWORD* in/out
lpErrno: ptr int32 # INT* out
): int32 {.importc: "WSCEnumProtocols32", stdcall, dynlib: "WS2_32.dll".}pragma(lib, "ws2_32");
extern(Windows)
int WSCEnumProtocols32(
int* lpiProtocols, // INT* optional
WSAPROTOCOL_INFOW* lpProtocolBuffer, // WSAPROTOCOL_INFOW* out
uint* lpdwBufferLength, // DWORD* in/out
int* lpErrno // INT* out
);ccall((:WSCEnumProtocols32, "WS2_32.dll"), stdcall, Int32,
(Ptr{Int32}, Ptr{WSAPROTOCOL_INFOW}, Ptr{UInt32}, Ptr{Int32}),
lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno)
# lpiProtocols : INT* optional -> Ptr{Int32}
# lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> Ptr{WSAPROTOCOL_INFOW}
# lpdwBufferLength : DWORD* in/out -> Ptr{UInt32}
# lpErrno : INT* out -> Ptr{Int32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t WSCEnumProtocols32(
int32_t* lpiProtocols,
void* lpProtocolBuffer,
uint32_t* lpdwBufferLength,
int32_t* lpErrno);
]]
local ws2_32 = ffi.load("ws2_32")
-- ws2_32.WSCEnumProtocols32(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno)
-- lpiProtocols : INT* optional
-- lpProtocolBuffer : WSAPROTOCOL_INFOW* out
-- lpdwBufferLength : DWORD* in/out
-- lpErrno : INT* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('WS2_32.dll');
const WSCEnumProtocols32 = lib.func('__stdcall', 'WSCEnumProtocols32', 'int32_t', ['int32_t *', 'void *', 'uint32_t *', 'int32_t *']);
// WSCEnumProtocols32(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno)
// lpiProtocols : INT* optional -> 'int32_t *'
// lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> 'void *'
// lpdwBufferLength : DWORD* in/out -> 'uint32_t *'
// lpErrno : INT* out -> 'int32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("WS2_32.dll", {
WSCEnumProtocols32: { parameters: ["pointer", "pointer", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.WSCEnumProtocols32(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno)
// lpiProtocols : INT* optional -> "pointer"
// lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> "pointer"
// lpdwBufferLength : DWORD* in/out -> "pointer"
// lpErrno : INT* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t WSCEnumProtocols32(
int32_t* lpiProtocols,
void* lpProtocolBuffer,
uint32_t* lpdwBufferLength,
int32_t* lpErrno);
C, "WS2_32.dll");
// $ffi->WSCEnumProtocols32(lpiProtocols, lpProtocolBuffer, lpdwBufferLength, lpErrno);
// lpiProtocols : INT* optional
// lpProtocolBuffer : WSAPROTOCOL_INFOW* out
// lpdwBufferLength : DWORD* in/out
// lpErrno : INT* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Ws2_32 extends StdCallLibrary {
Ws2_32 INSTANCE = Native.load("ws2_32", Ws2_32.class);
int WSCEnumProtocols32(
IntByReference lpiProtocols, // INT* optional
Pointer lpProtocolBuffer, // WSAPROTOCOL_INFOW* out
IntByReference lpdwBufferLength, // DWORD* in/out
IntByReference lpErrno // INT* out
);
}@[Link("ws2_32")]
lib LibWS2_32
fun WSCEnumProtocols32 = WSCEnumProtocols32(
lpiProtocols : Int32*, # INT* optional
lpProtocolBuffer : WSAPROTOCOL_INFOW*, # WSAPROTOCOL_INFOW* out
lpdwBufferLength : UInt32*, # DWORD* in/out
lpErrno : Int32* # INT* out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef WSCEnumProtocols32Native = Int32 Function(Pointer<Int32>, Pointer<Void>, Pointer<Uint32>, Pointer<Int32>);
typedef WSCEnumProtocols32Dart = int Function(Pointer<Int32>, Pointer<Void>, Pointer<Uint32>, Pointer<Int32>);
final WSCEnumProtocols32 = DynamicLibrary.open('WS2_32.dll')
.lookupFunction<WSCEnumProtocols32Native, WSCEnumProtocols32Dart>('WSCEnumProtocols32');
// lpiProtocols : INT* optional -> Pointer<Int32>
// lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> Pointer<Void>
// lpdwBufferLength : DWORD* in/out -> Pointer<Uint32>
// lpErrno : INT* out -> Pointer<Int32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function WSCEnumProtocols32(
lpiProtocols: Pointer; // INT* optional
lpProtocolBuffer: Pointer; // WSAPROTOCOL_INFOW* out
lpdwBufferLength: Pointer; // DWORD* in/out
lpErrno: Pointer // INT* out
): Integer; stdcall;
external 'WS2_32.dll' name 'WSCEnumProtocols32';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "WSCEnumProtocols32"
c_WSCEnumProtocols32 :: Ptr Int32 -> Ptr () -> Ptr Word32 -> Ptr Int32 -> IO Int32
-- lpiProtocols : INT* optional -> Ptr Int32
-- lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> Ptr ()
-- lpdwBufferLength : DWORD* in/out -> Ptr Word32
-- lpErrno : INT* out -> Ptr Int32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let wscenumprotocols32 =
foreign "WSCEnumProtocols32"
((ptr int32_t) @-> (ptr void) @-> (ptr uint32_t) @-> (ptr int32_t) @-> returning int32_t)
(* lpiProtocols : INT* optional -> (ptr int32_t) *)
(* lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> (ptr void) *)
(* lpdwBufferLength : DWORD* in/out -> (ptr uint32_t) *)
(* lpErrno : INT* out -> (ptr int32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library ws2_32 (t "WS2_32.dll"))
(cffi:use-foreign-library ws2_32)
(cffi:defcfun ("WSCEnumProtocols32" wscenum-protocols32 :convention :stdcall) :int32
(lpi-protocols :pointer) ; INT* optional
(lp-protocol-buffer :pointer) ; WSAPROTOCOL_INFOW* out
(lpdw-buffer-length :pointer) ; DWORD* in/out
(lp-errno :pointer)) ; INT* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $WSCEnumProtocols32 = Win32::API::More->new('WS2_32',
'int WSCEnumProtocols32(LPVOID lpiProtocols, LPVOID lpProtocolBuffer, LPVOID lpdwBufferLength, LPVOID lpErrno)');
# my $ret = $WSCEnumProtocols32->Call($lpiProtocols, $lpProtocolBuffer, $lpdwBufferLength, $lpErrno);
# lpiProtocols : INT* optional -> LPVOID
# lpProtocolBuffer : WSAPROTOCOL_INFOW* out -> LPVOID
# lpdwBufferLength : DWORD* in/out -> LPVOID
# lpErrno : INT* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f WSCEnumProtocols — インストール済みプロトコル構成を列挙する。
- f WSAEnumProtocolsW — 利用可能なトランスポートプロトコル情報を列挙する。