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