Win32 API 日本語リファレンス
ホームNetworkManagement.IpHelper › GetOwnerModuleFromTcpEntry

GetOwnerModuleFromTcpEntry

関数
指定TCP接続を所有するプロセスのモジュール情報を取得する。
DLLIPHLPAPI.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

DWORD GetOwnerModuleFromTcpEntry(
    MIB_TCPROW_OWNER_MODULE* pTcpEntry,
    TCPIP_OWNER_MODULE_INFO_CLASS Class,
    void* pBuffer,
    DWORD* pdwSize
);

パラメーター

名前方向
pTcpEntryMIB_TCPROW_OWNER_MODULE*in
ClassTCPIP_OWNER_MODULE_INFO_CLASSin
pBuffervoid*out
pdwSizeDWORD*inout

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetOwnerModuleFromTcpEntry(
    MIB_TCPROW_OWNER_MODULE* pTcpEntry,
    TCPIP_OWNER_MODULE_INFO_CLASS Class,
    void* pBuffer,
    DWORD* pdwSize
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetOwnerModuleFromTcpEntry(
    IntPtr pTcpEntry,   // MIB_TCPROW_OWNER_MODULE*
    int Class,   // TCPIP_OWNER_MODULE_INFO_CLASS
    IntPtr pBuffer,   // void* out
    ref uint pdwSize   // DWORD* in/out
);
<DllImport("IPHLPAPI.dll", ExactSpelling:=True)>
Public Shared Function GetOwnerModuleFromTcpEntry(
    pTcpEntry As IntPtr,   ' MIB_TCPROW_OWNER_MODULE*
    Class As Integer,   ' TCPIP_OWNER_MODULE_INFO_CLASS
    pBuffer As IntPtr,   ' void* out
    ByRef pdwSize As UInteger   ' DWORD* in/out
) As UInteger
End Function
' pTcpEntry : MIB_TCPROW_OWNER_MODULE*
' Class : TCPIP_OWNER_MODULE_INFO_CLASS
' pBuffer : void* out
' pdwSize : DWORD* in/out
Declare PtrSafe Function GetOwnerModuleFromTcpEntry Lib "iphlpapi" ( _
    ByVal pTcpEntry As LongPtr, _
    ByVal Class As Long, _
    ByVal pBuffer As LongPtr, _
    ByRef pdwSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetOwnerModuleFromTcpEntry = ctypes.windll.iphlpapi.GetOwnerModuleFromTcpEntry
GetOwnerModuleFromTcpEntry.restype = wintypes.DWORD
GetOwnerModuleFromTcpEntry.argtypes = [
    ctypes.c_void_p,  # pTcpEntry : MIB_TCPROW_OWNER_MODULE*
    ctypes.c_int,  # Class : TCPIP_OWNER_MODULE_INFO_CLASS
    ctypes.POINTER(None),  # pBuffer : void* out
    ctypes.POINTER(wintypes.DWORD),  # pdwSize : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	iphlpapi = windows.NewLazySystemDLL("IPHLPAPI.dll")
	procGetOwnerModuleFromTcpEntry = iphlpapi.NewProc("GetOwnerModuleFromTcpEntry")
)

// pTcpEntry (MIB_TCPROW_OWNER_MODULE*), Class (TCPIP_OWNER_MODULE_INFO_CLASS), pBuffer (void* out), pdwSize (DWORD* in/out)
r1, _, err := procGetOwnerModuleFromTcpEntry.Call(
	uintptr(pTcpEntry),
	uintptr(Class),
	uintptr(pBuffer),
	uintptr(pdwSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetOwnerModuleFromTcpEntry(
  pTcpEntry: Pointer;   // MIB_TCPROW_OWNER_MODULE*
  Class: Integer;   // TCPIP_OWNER_MODULE_INFO_CLASS
  pBuffer: Pointer;   // void* out
  pdwSize: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'GetOwnerModuleFromTcpEntry';
result := DllCall("IPHLPAPI\GetOwnerModuleFromTcpEntry"
    , "Ptr", pTcpEntry   ; MIB_TCPROW_OWNER_MODULE*
    , "Int", Class   ; TCPIP_OWNER_MODULE_INFO_CLASS
    , "Ptr", pBuffer   ; void* out
    , "Ptr", pdwSize   ; DWORD* in/out
    , "UInt")   ; return: DWORD
●GetOwnerModuleFromTcpEntry(pTcpEntry, Class, pBuffer, pdwSize) = DLL("IPHLPAPI.dll", "dword GetOwnerModuleFromTcpEntry(void*, int, void*, void*)")
# 呼び出し: GetOwnerModuleFromTcpEntry(pTcpEntry, Class, pBuffer, pdwSize)
# pTcpEntry : MIB_TCPROW_OWNER_MODULE* -> "void*"
# Class : TCPIP_OWNER_MODULE_INFO_CLASS -> "int"
# pBuffer : void* out -> "void*"
# pdwSize : DWORD* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。