Win32 API 日本語リファレンス
ホームSystem.Threading › GetProcessInformation

GetProcessInformation

関数
指定プロセスの情報をクラス指定で取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSwindows8.0

シグネチャ

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

BOOL GetProcessInformation(
    HANDLE hProcess,
    PROCESS_INFORMATION_CLASS ProcessInformationClass,
    void* ProcessInformation,
    DWORD ProcessInformationSize
);

パラメーター

名前方向
hProcessHANDLEin
ProcessInformationClassPROCESS_INFORMATION_CLASSin
ProcessInformationvoid*out
ProcessInformationSizeDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetProcessInformation(
    HANDLE hProcess,
    PROCESS_INFORMATION_CLASS ProcessInformationClass,
    void* ProcessInformation,
    DWORD ProcessInformationSize
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetProcessInformation(
    IntPtr hProcess,   // HANDLE
    int ProcessInformationClass,   // PROCESS_INFORMATION_CLASS
    IntPtr ProcessInformation,   // void* out
    uint ProcessInformationSize   // DWORD
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetProcessInformation(
    hProcess As IntPtr,   ' HANDLE
    ProcessInformationClass As Integer,   ' PROCESS_INFORMATION_CLASS
    ProcessInformation As IntPtr,   ' void* out
    ProcessInformationSize As UInteger   ' DWORD
) As Boolean
End Function
' hProcess : HANDLE
' ProcessInformationClass : PROCESS_INFORMATION_CLASS
' ProcessInformation : void* out
' ProcessInformationSize : DWORD
Declare PtrSafe Function GetProcessInformation Lib "kernel32" ( _
    ByVal hProcess As LongPtr, _
    ByVal ProcessInformationClass As Long, _
    ByVal ProcessInformation As LongPtr, _
    ByVal ProcessInformationSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetProcessInformation = ctypes.windll.kernel32.GetProcessInformation
GetProcessInformation.restype = wintypes.BOOL
GetProcessInformation.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE
    ctypes.c_int,  # ProcessInformationClass : PROCESS_INFORMATION_CLASS
    ctypes.POINTER(None),  # ProcessInformation : void* out
    wintypes.DWORD,  # ProcessInformationSize : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
GetProcessInformation = Fiddle::Function.new(
  lib['GetProcessInformation'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE
    Fiddle::TYPE_INT,  # ProcessInformationClass : PROCESS_INFORMATION_CLASS
    Fiddle::TYPE_VOIDP,  # ProcessInformation : void* out
    -Fiddle::TYPE_INT,  # ProcessInformationSize : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn GetProcessInformation(
        hProcess: *mut core::ffi::c_void,  // HANDLE
        ProcessInformationClass: i32,  // PROCESS_INFORMATION_CLASS
        ProcessInformation: *mut (),  // void* out
        ProcessInformationSize: u32  // DWORD
    ) -> 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 GetProcessInformation(IntPtr hProcess, int ProcessInformationClass, IntPtr ProcessInformation, uint ProcessInformationSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetProcessInformation' -Namespace Win32 -PassThru
# $api::GetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize)
#uselib "KERNEL32.dll"
#func global GetProcessInformation "GetProcessInformation" sptr, sptr, sptr, sptr
; GetProcessInformation hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize   ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; ProcessInformationClass : PROCESS_INFORMATION_CLASS -> "sptr"
; ProcessInformation : void* out -> "sptr"
; ProcessInformationSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global GetProcessInformation "GetProcessInformation" sptr, int, sptr, int
; res = GetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize)
; hProcess : HANDLE -> "sptr"
; ProcessInformationClass : PROCESS_INFORMATION_CLASS -> "int"
; ProcessInformation : void* out -> "sptr"
; ProcessInformationSize : DWORD -> "int"
; BOOL GetProcessInformation(HANDLE hProcess, PROCESS_INFORMATION_CLASS ProcessInformationClass, void* ProcessInformation, DWORD ProcessInformationSize)
#uselib "KERNEL32.dll"
#cfunc global GetProcessInformation "GetProcessInformation" intptr, int, intptr, int
; res = GetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize)
; hProcess : HANDLE -> "intptr"
; ProcessInformationClass : PROCESS_INFORMATION_CLASS -> "int"
; ProcessInformation : void* out -> "intptr"
; ProcessInformationSize : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetProcessInformation = kernel32.NewProc("GetProcessInformation")
)

// hProcess (HANDLE), ProcessInformationClass (PROCESS_INFORMATION_CLASS), ProcessInformation (void* out), ProcessInformationSize (DWORD)
r1, _, err := procGetProcessInformation.Call(
	uintptr(hProcess),
	uintptr(ProcessInformationClass),
	uintptr(ProcessInformation),
	uintptr(ProcessInformationSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function GetProcessInformation(
  hProcess: THandle;   // HANDLE
  ProcessInformationClass: Integer;   // PROCESS_INFORMATION_CLASS
  ProcessInformation: Pointer;   // void* out
  ProcessInformationSize: DWORD   // DWORD
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'GetProcessInformation';
result := DllCall("KERNEL32\GetProcessInformation"
    , "Ptr", hProcess   ; HANDLE
    , "Int", ProcessInformationClass   ; PROCESS_INFORMATION_CLASS
    , "Ptr", ProcessInformation   ; void* out
    , "UInt", ProcessInformationSize   ; DWORD
    , "Int")   ; return: BOOL
●GetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize) = DLL("KERNEL32.dll", "bool GetProcessInformation(void*, int, void*, dword)")
# 呼び出し: GetProcessInformation(hProcess, ProcessInformationClass, ProcessInformation, ProcessInformationSize)
# hProcess : HANDLE -> "void*"
# ProcessInformationClass : PROCESS_INFORMATION_CLASS -> "int"
# ProcessInformation : void* out -> "void*"
# ProcessInformationSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。