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