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

GetOwnerModuleFromPidAndInfo

関数
プロセスIDと接続情報から所有モジュール情報を取得する。
DLLIPHLPAPI.dll呼出規約winapi

シグネチャ

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

DWORD GetOwnerModuleFromPidAndInfo(
    DWORD ulPid,
    ULONGLONG* pInfo,
    TCPIP_OWNER_MODULE_INFO_CLASS Class,
    void* pBuffer,
    DWORD* pdwSize
);

パラメーター

名前方向
ulPidDWORDin
pInfoULONGLONG*in
ClassTCPIP_OWNER_MODULE_INFO_CLASSin
pBuffervoid*out
pdwSizeDWORD*inout

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD GetOwnerModuleFromPidAndInfo(
    DWORD ulPid,
    ULONGLONG* pInfo,
    TCPIP_OWNER_MODULE_INFO_CLASS Class,
    void* pBuffer,
    DWORD* pdwSize
);
[DllImport("IPHLPAPI.dll", ExactSpelling = true)]
static extern uint GetOwnerModuleFromPidAndInfo(
    uint ulPid,   // DWORD
    ref ulong pInfo,   // ULONGLONG*
    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 GetOwnerModuleFromPidAndInfo(
    ulPid As UInteger,   ' DWORD
    ByRef pInfo As ULong,   ' ULONGLONG*
    Class As Integer,   ' TCPIP_OWNER_MODULE_INFO_CLASS
    pBuffer As IntPtr,   ' void* out
    ByRef pdwSize As UInteger   ' DWORD* in/out
) As UInteger
End Function
' ulPid : DWORD
' pInfo : ULONGLONG*
' Class : TCPIP_OWNER_MODULE_INFO_CLASS
' pBuffer : void* out
' pdwSize : DWORD* in/out
Declare PtrSafe Function GetOwnerModuleFromPidAndInfo Lib "iphlpapi" ( _
    ByVal ulPid As Long, _
    ByRef pInfo As LongLong, _
    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

GetOwnerModuleFromPidAndInfo = ctypes.windll.iphlpapi.GetOwnerModuleFromPidAndInfo
GetOwnerModuleFromPidAndInfo.restype = wintypes.DWORD
GetOwnerModuleFromPidAndInfo.argtypes = [
    wintypes.DWORD,  # ulPid : DWORD
    ctypes.POINTER(ctypes.c_ulonglong),  # pInfo : ULONGLONG*
    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')
GetOwnerModuleFromPidAndInfo = Fiddle::Function.new(
  lib['GetOwnerModuleFromPidAndInfo'],
  [
    -Fiddle::TYPE_INT,  # ulPid : DWORD
    Fiddle::TYPE_VOIDP,  # pInfo : ULONGLONG*
    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 GetOwnerModuleFromPidAndInfo(
        ulPid: u32,  // DWORD
        pInfo: *mut u64,  // ULONGLONG*
        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 GetOwnerModuleFromPidAndInfo(uint ulPid, ref ulong pInfo, int Class, IntPtr pBuffer, ref uint pdwSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'IPHLPAPI_GetOwnerModuleFromPidAndInfo' -Namespace Win32 -PassThru
# $api::GetOwnerModuleFromPidAndInfo(ulPid, pInfo, Class, pBuffer, pdwSize)
#uselib "IPHLPAPI.dll"
#func global GetOwnerModuleFromPidAndInfo "GetOwnerModuleFromPidAndInfo" sptr, sptr, sptr, sptr, sptr
; GetOwnerModuleFromPidAndInfo ulPid, varptr(pInfo), Class, pBuffer, varptr(pdwSize)   ; 戻り値は stat
; ulPid : DWORD -> "sptr"
; pInfo : ULONGLONG* -> "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 GetOwnerModuleFromPidAndInfo "GetOwnerModuleFromPidAndInfo" int, var, int, sptr, var
; res = GetOwnerModuleFromPidAndInfo(ulPid, pInfo, Class, pBuffer, pdwSize)
; ulPid : DWORD -> "int"
; pInfo : ULONGLONG* -> "var"
; Class : TCPIP_OWNER_MODULE_INFO_CLASS -> "int"
; pBuffer : void* out -> "sptr"
; pdwSize : DWORD* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD GetOwnerModuleFromPidAndInfo(DWORD ulPid, ULONGLONG* pInfo, TCPIP_OWNER_MODULE_INFO_CLASS Class, void* pBuffer, DWORD* pdwSize)
#uselib "IPHLPAPI.dll"
#cfunc global GetOwnerModuleFromPidAndInfo "GetOwnerModuleFromPidAndInfo" int, var, int, intptr, var
; res = GetOwnerModuleFromPidAndInfo(ulPid, pInfo, Class, pBuffer, pdwSize)
; ulPid : DWORD -> "int"
; pInfo : ULONGLONG* -> "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")
	procGetOwnerModuleFromPidAndInfo = iphlpapi.NewProc("GetOwnerModuleFromPidAndInfo")
)

// ulPid (DWORD), pInfo (ULONGLONG*), Class (TCPIP_OWNER_MODULE_INFO_CLASS), pBuffer (void* out), pdwSize (DWORD* in/out)
r1, _, err := procGetOwnerModuleFromPidAndInfo.Call(
	uintptr(ulPid),
	uintptr(pInfo),
	uintptr(Class),
	uintptr(pBuffer),
	uintptr(pdwSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function GetOwnerModuleFromPidAndInfo(
  ulPid: DWORD;   // DWORD
  pInfo: Pointer;   // ULONGLONG*
  Class: Integer;   // TCPIP_OWNER_MODULE_INFO_CLASS
  pBuffer: Pointer;   // void* out
  pdwSize: Pointer   // DWORD* in/out
): DWORD; stdcall;
  external 'IPHLPAPI.dll' name 'GetOwnerModuleFromPidAndInfo';
result := DllCall("IPHLPAPI\GetOwnerModuleFromPidAndInfo"
    , "UInt", ulPid   ; DWORD
    , "Ptr", pInfo   ; ULONGLONG*
    , "Int", Class   ; TCPIP_OWNER_MODULE_INFO_CLASS
    , "Ptr", pBuffer   ; void* out
    , "Ptr", pdwSize   ; DWORD* in/out
    , "UInt")   ; return: DWORD
●GetOwnerModuleFromPidAndInfo(ulPid, pInfo, Class, pBuffer, pdwSize) = DLL("IPHLPAPI.dll", "dword GetOwnerModuleFromPidAndInfo(dword, void*, int, void*, void*)")
# 呼び出し: GetOwnerModuleFromPidAndInfo(ulPid, pInfo, Class, pBuffer, pdwSize)
# ulPid : DWORD -> "dword"
# pInfo : ULONGLONG* -> "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)。