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

GetPerformanceInfo

関数
システム全体のパフォーマンス情報を取得する。
DLLPSAPI.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL GetPerformanceInfo(
    PERFORMANCE_INFORMATION* pPerformanceInformation,
    DWORD cb
);

パラメーター

名前方向
pPerformanceInformationPERFORMANCE_INFORMATION*inout
cbDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL GetPerformanceInfo(
    PERFORMANCE_INFORMATION* pPerformanceInformation,
    DWORD cb
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("PSAPI.dll", SetLastError = true, ExactSpelling = true)]
static extern bool GetPerformanceInfo(
    IntPtr pPerformanceInformation,   // PERFORMANCE_INFORMATION* in/out
    uint cb   // DWORD
);
<DllImport("PSAPI.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function GetPerformanceInfo(
    pPerformanceInformation As IntPtr,   ' PERFORMANCE_INFORMATION* in/out
    cb As UInteger   ' DWORD
) As Boolean
End Function
' pPerformanceInformation : PERFORMANCE_INFORMATION* in/out
' cb : DWORD
Declare PtrSafe Function GetPerformanceInfo Lib "psapi" ( _
    ByVal pPerformanceInformation As LongPtr, _
    ByVal cb As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GetPerformanceInfo = ctypes.windll.psapi.GetPerformanceInfo
GetPerformanceInfo.restype = wintypes.BOOL
GetPerformanceInfo.argtypes = [
    ctypes.c_void_p,  # pPerformanceInformation : PERFORMANCE_INFORMATION* in/out
    wintypes.DWORD,  # cb : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	psapi = windows.NewLazySystemDLL("PSAPI.dll")
	procGetPerformanceInfo = psapi.NewProc("GetPerformanceInfo")
)

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