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

QueryIdleProcessorCycleTime

関数
各プロセッサのアイドルサイクル時間を取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL QueryIdleProcessorCycleTime(
    DWORD* BufferLength,
    ULONGLONG* ProcessorIdleCycleTime   // optional
);

パラメーター

名前方向
BufferLengthDWORD*inout
ProcessorIdleCycleTimeULONGLONG*outoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

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

QueryIdleProcessorCycleTime = ctypes.windll.kernel32.QueryIdleProcessorCycleTime
QueryIdleProcessorCycleTime.restype = wintypes.BOOL
QueryIdleProcessorCycleTime.argtypes = [
    ctypes.POINTER(wintypes.DWORD),  # BufferLength : DWORD* in/out
    ctypes.POINTER(ctypes.c_ulonglong),  # ProcessorIdleCycleTime : ULONGLONG* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
QueryIdleProcessorCycleTime = Fiddle::Function.new(
  lib['QueryIdleProcessorCycleTime'],
  [
    Fiddle::TYPE_VOIDP,  # BufferLength : DWORD* in/out
    Fiddle::TYPE_VOIDP,  # ProcessorIdleCycleTime : ULONGLONG* optional, out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn QueryIdleProcessorCycleTime(
        BufferLength: *mut u32,  // DWORD* in/out
        ProcessorIdleCycleTime: *mut u64  // ULONGLONG* 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 QueryIdleProcessorCycleTime(ref uint BufferLength, IntPtr ProcessorIdleCycleTime);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_QueryIdleProcessorCycleTime' -Namespace Win32 -PassThru
# $api::QueryIdleProcessorCycleTime(BufferLength, ProcessorIdleCycleTime)
#uselib "KERNEL32.dll"
#func global QueryIdleProcessorCycleTime "QueryIdleProcessorCycleTime" sptr, sptr
; QueryIdleProcessorCycleTime varptr(BufferLength), varptr(ProcessorIdleCycleTime)   ; 戻り値は stat
; BufferLength : DWORD* in/out -> "sptr"
; ProcessorIdleCycleTime : ULONGLONG* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global QueryIdleProcessorCycleTime "QueryIdleProcessorCycleTime" var, var
; res = QueryIdleProcessorCycleTime(BufferLength, ProcessorIdleCycleTime)
; BufferLength : DWORD* in/out -> "var"
; ProcessorIdleCycleTime : ULONGLONG* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL QueryIdleProcessorCycleTime(DWORD* BufferLength, ULONGLONG* ProcessorIdleCycleTime)
#uselib "KERNEL32.dll"
#cfunc global QueryIdleProcessorCycleTime "QueryIdleProcessorCycleTime" var, var
; res = QueryIdleProcessorCycleTime(BufferLength, ProcessorIdleCycleTime)
; BufferLength : DWORD* in/out -> "var"
; ProcessorIdleCycleTime : ULONGLONG* optional, out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procQueryIdleProcessorCycleTime = kernel32.NewProc("QueryIdleProcessorCycleTime")
)

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