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

QueryIdleProcessorCycleTimeEx

関数
指定プロセッサグループのアイドルサイクル時間を取得する。
DLLKERNEL32.dll呼出規約winapi対応OSWindows 7 以降

シグネチャ

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

BOOL QueryIdleProcessorCycleTimeEx(
    WORD Group,
    DWORD* BufferLength,
    ULONGLONG* ProcessorIdleCycleTime   // optional
);

パラメーター

名前方向説明
GroupWORDin対象のプロセッサグループ番号。
BufferLengthDWORD*inout入力時はバッファサイズ(バイト)、出力時は必要/書込済サイズを返す。
ProcessorIdleCycleTimeULONGLONG*outoptional指定グループ内各プロセッサのアイドルサイクル数を格納する配列へのポインタ。

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL QueryIdleProcessorCycleTimeEx(
    WORD Group,
    DWORD* BufferLength,
    ULONGLONG* ProcessorIdleCycleTime   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern bool QueryIdleProcessorCycleTimeEx(
    ushort Group,   // WORD
    ref uint BufferLength,   // DWORD* in/out
    IntPtr ProcessorIdleCycleTime   // ULONGLONG* optional, out
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function QueryIdleProcessorCycleTimeEx(
    Group As UShort,   ' WORD
    ByRef BufferLength As UInteger,   ' DWORD* in/out
    ProcessorIdleCycleTime As IntPtr   ' ULONGLONG* optional, out
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' Group : WORD
' BufferLength : DWORD* in/out
' ProcessorIdleCycleTime : ULONGLONG* optional, out
Declare PtrSafe Function QueryIdleProcessorCycleTimeEx Lib "kernel32" ( _
    ByVal Group As Integer, _
    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

QueryIdleProcessorCycleTimeEx = ctypes.windll.kernel32.QueryIdleProcessorCycleTimeEx
QueryIdleProcessorCycleTimeEx.restype = wintypes.BOOL
QueryIdleProcessorCycleTimeEx.argtypes = [
    ctypes.c_ushort,  # Group : WORD
    ctypes.POINTER(wintypes.DWORD),  # BufferLength : DWORD* in/out
    ctypes.POINTER(ctypes.c_ulonglong),  # ProcessorIdleCycleTime : ULONGLONG* optional, out
]
require 'fiddle'
require 'fiddle/import'

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

// Group (WORD), BufferLength (DWORD* in/out), ProcessorIdleCycleTime (ULONGLONG* optional, out)
r1, _, err := procQueryIdleProcessorCycleTimeEx.Call(
	uintptr(Group),
	uintptr(BufferLength),
	uintptr(ProcessorIdleCycleTime),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function QueryIdleProcessorCycleTimeEx(
  Group: Word;   // WORD
  BufferLength: Pointer;   // DWORD* in/out
  ProcessorIdleCycleTime: Pointer   // ULONGLONG* optional, out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'QueryIdleProcessorCycleTimeEx';
result := DllCall("KERNEL32\QueryIdleProcessorCycleTimeEx"
    , "UShort", Group   ; WORD
    , "Ptr", BufferLength   ; DWORD* in/out
    , "Ptr", ProcessorIdleCycleTime   ; ULONGLONG* optional, out
    , "Int")   ; return: BOOL
●QueryIdleProcessorCycleTimeEx(Group, BufferLength, ProcessorIdleCycleTime) = DLL("KERNEL32.dll", "bool QueryIdleProcessorCycleTimeEx(int, void*, void*)")
# 呼び出し: QueryIdleProcessorCycleTimeEx(Group, BufferLength, ProcessorIdleCycleTime)
# Group : WORD -> "int"
# 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 QueryIdleProcessorCycleTimeEx(
    Group: u16, // WORD
    BufferLength: [*c]u32, // DWORD* in/out
    ProcessorIdleCycleTime: [*c]u64 // ULONGLONG* optional, out
) callconv(std.os.windows.WINAPI) i32;
proc QueryIdleProcessorCycleTimeEx(
    Group: uint16,  # WORD
    BufferLength: ptr uint32,  # DWORD* in/out
    ProcessorIdleCycleTime: ptr uint64  # ULONGLONG* optional, out
): int32 {.importc: "QueryIdleProcessorCycleTimeEx", stdcall, dynlib: "KERNEL32.dll".}
pragma(lib, "kernel32");
extern(Windows)
int QueryIdleProcessorCycleTimeEx(
    ushort Group,   // WORD
    uint* BufferLength,   // DWORD* in/out
    ulong* ProcessorIdleCycleTime   // ULONGLONG* optional, out
);
ccall((:QueryIdleProcessorCycleTimeEx, "KERNEL32.dll"), stdcall, Int32,
      (UInt16, Ptr{UInt32}, Ptr{UInt64}),
      Group, BufferLength, ProcessorIdleCycleTime)
# Group : WORD -> UInt16
# BufferLength : DWORD* in/out -> Ptr{UInt32}
# ProcessorIdleCycleTime : ULONGLONG* optional, out -> Ptr{UInt64}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t QueryIdleProcessorCycleTimeEx(
    uint16_t Group,
    uint32_t* BufferLength,
    uint64_t* ProcessorIdleCycleTime);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.QueryIdleProcessorCycleTimeEx(Group, BufferLength, ProcessorIdleCycleTime)
-- Group : WORD
-- 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 QueryIdleProcessorCycleTimeEx = lib.func('__stdcall', 'QueryIdleProcessorCycleTimeEx', 'int32_t', ['uint16_t', 'uint32_t *', 'uint64_t *']);
// QueryIdleProcessorCycleTimeEx(Group, BufferLength, ProcessorIdleCycleTime)
// Group : WORD -> 'uint16_t'
// BufferLength : DWORD* in/out -> 'uint32_t *'
// ProcessorIdleCycleTime : ULONGLONG* optional, out -> 'uint64_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("KERNEL32.dll", {
  QueryIdleProcessorCycleTimeEx: { parameters: ["u16", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.QueryIdleProcessorCycleTimeEx(Group, BufferLength, ProcessorIdleCycleTime)
// Group : WORD -> "u16"
// BufferLength : DWORD* in/out -> "pointer"
// ProcessorIdleCycleTime : ULONGLONG* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t QueryIdleProcessorCycleTimeEx(
    uint16_t Group,
    uint32_t* BufferLength,
    uint64_t* ProcessorIdleCycleTime);
C, "KERNEL32.dll");
// $ffi->QueryIdleProcessorCycleTimeEx(Group, BufferLength, ProcessorIdleCycleTime);
// Group : WORD
// 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 QueryIdleProcessorCycleTimeEx(
        short Group,   // WORD
        IntByReference BufferLength,   // DWORD* in/out
        LongByReference ProcessorIdleCycleTime   // ULONGLONG* optional, out
    );
}
@[Link("kernel32")]
lib LibKERNEL32
  fun QueryIdleProcessorCycleTimeEx = QueryIdleProcessorCycleTimeEx(
    Group : UInt16,   # WORD
    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 QueryIdleProcessorCycleTimeExNative = Int32 Function(Uint16, Pointer<Uint32>, Pointer<Uint64>);
typedef QueryIdleProcessorCycleTimeExDart = int Function(int, Pointer<Uint32>, Pointer<Uint64>);
final QueryIdleProcessorCycleTimeEx = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<QueryIdleProcessorCycleTimeExNative, QueryIdleProcessorCycleTimeExDart>('QueryIdleProcessorCycleTimeEx');
// Group : WORD -> Uint16
// BufferLength : DWORD* in/out -> Pointer<Uint32>
// ProcessorIdleCycleTime : ULONGLONG* optional, out -> Pointer<Uint64>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function QueryIdleProcessorCycleTimeEx(
  Group: Word;   // WORD
  BufferLength: Pointer;   // DWORD* in/out
  ProcessorIdleCycleTime: Pointer   // ULONGLONG* optional, out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'QueryIdleProcessorCycleTimeEx';
import Foreign
import Foreign.C.Types
import Foreign.C.String

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

let queryidleprocessorcycletimeex =
  foreign "QueryIdleProcessorCycleTimeEx"
    (uint16_t @-> (ptr uint32_t) @-> (ptr uint64_t) @-> returning int32_t)
(* Group : WORD -> uint16_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 ("QueryIdleProcessorCycleTimeEx" query-idle-processor-cycle-time-ex :convention :stdcall) :int32
  (group :uint16)   ; WORD
  (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 $QueryIdleProcessorCycleTimeEx = Win32::API::More->new('KERNEL32',
    'BOOL QueryIdleProcessorCycleTimeEx(WORD Group, LPVOID BufferLength, LPVOID ProcessorIdleCycleTime)');
# my $ret = $QueryIdleProcessorCycleTimeEx->Call($Group, $BufferLength, $ProcessorIdleCycleTime);
# Group : WORD -> WORD
# BufferLength : DWORD* in/out -> LPVOID
# ProcessorIdleCycleTime : ULONGLONG* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API