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入力時はProcessorIdleCycleTimeバッファのサイズ(バイト)、出力時は必要/書込済サイズを返す。
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 <MarshalAs(UnmanagedType.Bool)> 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)。
const std = @import("std");

extern "kernel32" fn QueryIdleProcessorCycleTime(
    BufferLength: [*c]u32, // DWORD* in/out
    ProcessorIdleCycleTime: [*c]u64 // ULONGLONG* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc QueryIdleProcessorCycleTime(
    BufferLength: ptr uint32,  # DWORD* in/out
    ProcessorIdleCycleTime: ptr uint64  # ULONGLONG* optional, out
): int32 {.importc: "QueryIdleProcessorCycleTime", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int QueryIdleProcessorCycleTime(
    uint* BufferLength,   // DWORD* in/out
    ulong* ProcessorIdleCycleTime   // ULONGLONG* optional, out
);
ccall((:QueryIdleProcessorCycleTime, "KERNEL32.dll"), stdcall, Int32,
      (Ptr{UInt32}, Ptr{UInt64}),
      BufferLength, ProcessorIdleCycleTime)
# BufferLength : DWORD* in/out -> Ptr{UInt32}
# ProcessorIdleCycleTime : ULONGLONG* optional, out -> Ptr{UInt64}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t QueryIdleProcessorCycleTime(
    uint32_t* BufferLength,
    uint64_t* ProcessorIdleCycleTime);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.QueryIdleProcessorCycleTime(BufferLength, ProcessorIdleCycleTime)
-- BufferLength : DWORD* in/out
-- ProcessorIdleCycleTime : ULONGLONG* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const QueryIdleProcessorCycleTime = lib.func('__stdcall', 'QueryIdleProcessorCycleTime', 'int32_t', ['uint32_t *', 'uint64_t *']);
// QueryIdleProcessorCycleTime(BufferLength, ProcessorIdleCycleTime)
// BufferLength : DWORD* in/out -> 'uint32_t *'
// ProcessorIdleCycleTime : ULONGLONG* optional, out -> 'uint64_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  QueryIdleProcessorCycleTime: { parameters: ["pointer", "pointer"], result: "i32" },
});
// lib.symbols.QueryIdleProcessorCycleTime(BufferLength, ProcessorIdleCycleTime)
// BufferLength : DWORD* in/out -> "pointer"
// ProcessorIdleCycleTime : ULONGLONG* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t QueryIdleProcessorCycleTime(
    uint32_t* BufferLength,
    uint64_t* ProcessorIdleCycleTime);
C, "KERNEL32.dll");
// $ffi->QueryIdleProcessorCycleTime(BufferLength, ProcessorIdleCycleTime);
// BufferLength : DWORD* in/out
// ProcessorIdleCycleTime : ULONGLONG* optional, out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Kernel32 extends StdCallLibrary {
    Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
    boolean QueryIdleProcessorCycleTime(
        IntByReference BufferLength,   // DWORD* in/out
        LongByReference ProcessorIdleCycleTime   // ULONGLONG* optional, out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun QueryIdleProcessorCycleTime = QueryIdleProcessorCycleTime(
    BufferLength : UInt32*,   # DWORD* in/out
    ProcessorIdleCycleTime : UInt64*   # ULONGLONG* optional, out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef QueryIdleProcessorCycleTimeNative = Int32 Function(Pointer<Uint32>, Pointer<Uint64>);
typedef QueryIdleProcessorCycleTimeDart = int Function(Pointer<Uint32>, Pointer<Uint64>);
final QueryIdleProcessorCycleTime = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<QueryIdleProcessorCycleTimeNative, QueryIdleProcessorCycleTimeDart>('QueryIdleProcessorCycleTime');
// BufferLength : DWORD* in/out -> Pointer<Uint32>
// ProcessorIdleCycleTime : ULONGLONG* optional, out -> Pointer<Uint64>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function QueryIdleProcessorCycleTime(
  BufferLength: Pointer;   // DWORD* in/out
  ProcessorIdleCycleTime: Pointer   // ULONGLONG* optional, out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'QueryIdleProcessorCycleTime';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "QueryIdleProcessorCycleTime"
  c_QueryIdleProcessorCycleTime :: Ptr Word32 -> Ptr Word64 -> IO CInt
-- BufferLength : DWORD* in/out -> Ptr Word32
-- ProcessorIdleCycleTime : ULONGLONG* optional, out -> Ptr Word64
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let queryidleprocessorcycletime =
  foreign "QueryIdleProcessorCycleTime"
    ((ptr uint32_t) @-> (ptr uint64_t) @-> returning int32_t)
(* BufferLength : DWORD* in/out -> (ptr uint32_t) *)
(* ProcessorIdleCycleTime : ULONGLONG* optional, out -> (ptr uint64_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("QueryIdleProcessorCycleTime" query-idle-processor-cycle-time :convention :stdcall) :int32
  (buffer-length :pointer)   ; DWORD* in/out
  (processor-idle-cycle-time :pointer))   ; ULONGLONG* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $QueryIdleProcessorCycleTime = Win32::API::More->new('KERNEL32',
    'BOOL QueryIdleProcessorCycleTime(LPVOID BufferLength, LPVOID ProcessorIdleCycleTime)');
# my $ret = $QueryIdleProcessorCycleTime->Call($BufferLength, $ProcessorIdleCycleTime);
# BufferLength : DWORD* in/out -> LPVOID
# ProcessorIdleCycleTime : ULONGLONG* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API