ホーム › NetworkManagement.IpHelper › GetTcpTable
GetTcpTable
関数現在のTCP接続一覧をMIB_TCPTABLEとして取得する。
シグネチャ
// IPHLPAPI.dll
#include <windows.h>
DWORD GetTcpTable(
MIB_TCPTABLE* TcpTable, // optional
DWORD* SizePointer,
BOOL Order
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| TcpTable | MIB_TCPTABLE* | outoptional |
| SizePointer | DWORD* | inout |
| Order | BOOL | in |
戻り値の型: DWORD
各言語での呼び出し定義
// IPHLPAPI.dll
#include <windows.h>
DWORD GetTcpTable(
MIB_TCPTABLE* TcpTable, // optional
DWORD* SizePointer,
BOOL Order
);[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetTcpTable(
IntPtr TcpTable, // MIB_TCPTABLE* optional, out
ref uint SizePointer, // DWORD* in/out
bool Order // BOOL
);<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetTcpTable(
TcpTable As IntPtr, ' MIB_TCPTABLE* optional, out
ByRef SizePointer As UInteger, ' DWORD* in/out
Order As Boolean ' BOOL
) As UInteger
End Function' TcpTable : MIB_TCPTABLE* optional, out
' SizePointer : DWORD* in/out
' Order : BOOL
Declare PtrSafe Function GetTcpTable Lib "iphlpapi" ( _
ByVal TcpTable As LongPtr, _
ByRef SizePointer As Long, _
ByVal Order As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetTcpTable = ctypes.windll.iphlpapi.GetTcpTable
GetTcpTable.restype = wintypes.DWORD
GetTcpTable.argtypes = [
ctypes.c_void_p, # TcpTable : MIB_TCPTABLE* optional, out
ctypes.POINTER(wintypes.DWORD), # SizePointer : DWORD* in/out
wintypes.BOOL, # Order : BOOL
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('IPHLPAPI.dll')
GetTcpTable = Fiddle::Function.new(
lib['GetTcpTable'],
[
Fiddle::TYPE_VOIDP, # TcpTable : MIB_TCPTABLE* optional, out
Fiddle::TYPE_VOIDP, # SizePointer : DWORD* in/out
Fiddle::TYPE_INT, # Order : BOOL
],
-Fiddle::TYPE_INT)#[link(name = "iphlpapi")]
extern "system" {
fn GetTcpTable(
TcpTable: *mut MIB_TCPTABLE, // MIB_TCPTABLE* optional, out
SizePointer: *mut u32, // DWORD* in/out
Order: i32 // BOOL
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("IPHLPAPI.dll")]
public static extern uint GetTcpTable(IntPtr TcpTable, ref uint SizePointer, bool Order);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetTcpTable' -Namespace Win32 -PassThru
# $api::GetTcpTable(TcpTable, SizePointer, Order)#uselib "IPHLPAPI.dll"
#func global GetTcpTable "GetTcpTable" sptr, sptr, sptr
; GetTcpTable varptr(TcpTable), varptr(SizePointer), Order ; 戻り値は stat
; TcpTable : MIB_TCPTABLE* optional, out -> "sptr"
; SizePointer : DWORD* in/out -> "sptr"
; Order : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "IPHLPAPI.dll" #cfunc global GetTcpTable "GetTcpTable" var, var, int ; res = GetTcpTable(TcpTable, SizePointer, Order) ; TcpTable : MIB_TCPTABLE* optional, out -> "var" ; SizePointer : DWORD* in/out -> "var" ; Order : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "IPHLPAPI.dll" #cfunc global GetTcpTable "GetTcpTable" sptr, sptr, int ; res = GetTcpTable(varptr(TcpTable), varptr(SizePointer), Order) ; TcpTable : MIB_TCPTABLE* optional, out -> "sptr" ; SizePointer : DWORD* in/out -> "sptr" ; Order : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD GetTcpTable(MIB_TCPTABLE* TcpTable, DWORD* SizePointer, BOOL Order) #uselib "IPHLPAPI.dll" #cfunc global GetTcpTable "GetTcpTable" var, var, int ; res = GetTcpTable(TcpTable, SizePointer, Order) ; TcpTable : MIB_TCPTABLE* optional, out -> "var" ; SizePointer : DWORD* in/out -> "var" ; Order : BOOL -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD GetTcpTable(MIB_TCPTABLE* TcpTable, DWORD* SizePointer, BOOL Order) #uselib "IPHLPAPI.dll" #cfunc global GetTcpTable "GetTcpTable" intptr, intptr, int ; res = GetTcpTable(varptr(TcpTable), varptr(SizePointer), Order) ; TcpTable : MIB_TCPTABLE* optional, out -> "intptr" ; SizePointer : DWORD* in/out -> "intptr" ; Order : BOOL -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
procGetTcpTable = iphlpapi.NewProc("GetTcpTable")
)
// TcpTable (MIB_TCPTABLE* optional, out), SizePointer (DWORD* in/out), Order (BOOL)
r1, _, err := procGetTcpTable.Call(
uintptr(TcpTable),
uintptr(SizePointer),
uintptr(Order),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction GetTcpTable(
TcpTable: Pointer; // MIB_TCPTABLE* optional, out
SizePointer: Pointer; // DWORD* in/out
Order: BOOL // BOOL
): DWORD; stdcall;
external 'IPHLPAPI.dll' name 'GetTcpTable';result := DllCall("IPHLPAPI\GetTcpTable"
, "Ptr", TcpTable ; MIB_TCPTABLE* optional, out
, "Ptr", SizePointer ; DWORD* in/out
, "Int", Order ; BOOL
, "UInt") ; return: DWORD●GetTcpTable(TcpTable, SizePointer, Order) = DLL("IPHLPAPI.dll", "dword GetTcpTable(void*, void*, bool)")
# 呼び出し: GetTcpTable(TcpTable, SizePointer, Order)
# TcpTable : MIB_TCPTABLE* optional, out -> "void*"
# SizePointer : DWORD* in/out -> "void*"
# Order : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。