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

PdhGetCounterTimeBase

関数
カウンターの時間基準値を取得する。
DLLpdh.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD PdhGetCounterTimeBase(
    PDH_HCOUNTER hCounter,
    LONGLONG* pTimeBase
);

パラメーター

名前方向説明
hCounterPDH_HCOUNTERinカウンターのハンドル。 PdhAddCounter 関数がこのハンドルを返します。
pTimeBaseLONGLONG*outカウンターが 1 秒間にサンプリングするパフォーマンス値の数を指定するタイムベース。

戻り値の型: DWORD

公式ドキュメント

指定したカウンターのタイムベースを返します。

戻り値

関数が成功した場合は ERROR_SUCCESS を返します。

関数が失敗した場合、戻り値は システムエラーコード または PDH エラーコード です。次の値が考えられます。

戻り値 説明
PDH_INVALID_ARGUMENT
指定したカウンターはタイムベースを使用しません。
PDH_INVALID_HANDLE
カウンターハンドルが無効です。

解説(Remarks)

PdhCalculateCounterFromRawValue 関数を呼び出す代わりに

PdhFormatFromRawValue 関数を使用して表示用の値を計算する場合は、タイムベースを取得するために PdhGetCounterTimeBase 関数を呼び出す必要があります。

時間ベースのパフォーマンスデータを返す各カウンターには、タイムベースが定義されています。カウンターのタイムベースとは、そのカウンターが 1 秒間にデータをサンプリングする回数です。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

DWORD PdhGetCounterTimeBase(
    PDH_HCOUNTER hCounter,
    LONGLONG* pTimeBase
);
[DllImport("pdh.dll", ExactSpelling = true)]
static extern uint PdhGetCounterTimeBase(
    IntPtr hCounter,   // PDH_HCOUNTER
    out long pTimeBase   // LONGLONG* out
);
<DllImport("pdh.dll", ExactSpelling:=True)>
Public Shared Function PdhGetCounterTimeBase(
    hCounter As IntPtr,   ' PDH_HCOUNTER
    <Out> ByRef pTimeBase As Long   ' LONGLONG* out
) As UInteger
End Function
' hCounter : PDH_HCOUNTER
' pTimeBase : LONGLONG* out
Declare PtrSafe Function PdhGetCounterTimeBase Lib "pdh" ( _
    ByVal hCounter As LongPtr, _
    ByRef pTimeBase As LongLong) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PdhGetCounterTimeBase = ctypes.windll.pdh.PdhGetCounterTimeBase
PdhGetCounterTimeBase.restype = wintypes.DWORD
PdhGetCounterTimeBase.argtypes = [
    wintypes.HANDLE,  # hCounter : PDH_HCOUNTER
    ctypes.POINTER(ctypes.c_longlong),  # pTimeBase : LONGLONG* out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('pdh.dll')
PdhGetCounterTimeBase = Fiddle::Function.new(
  lib['PdhGetCounterTimeBase'],
  [
    Fiddle::TYPE_VOIDP,  # hCounter : PDH_HCOUNTER
    Fiddle::TYPE_VOIDP,  # pTimeBase : LONGLONG* out
  ],
  -Fiddle::TYPE_INT)
#[link(name = "pdh")]
extern "system" {
    fn PdhGetCounterTimeBase(
        hCounter: *mut core::ffi::c_void,  // PDH_HCOUNTER
        pTimeBase: *mut i64  // LONGLONG* out
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("pdh.dll")]
public static extern uint PdhGetCounterTimeBase(IntPtr hCounter, out long pTimeBase);
"@
$api = Add-Type -MemberDefinition $sig -Name 'pdh_PdhGetCounterTimeBase' -Namespace Win32 -PassThru
# $api::PdhGetCounterTimeBase(hCounter, pTimeBase)
#uselib "pdh.dll"
#func global PdhGetCounterTimeBase "PdhGetCounterTimeBase" sptr, sptr
; PdhGetCounterTimeBase hCounter, varptr(pTimeBase)   ; 戻り値は stat
; hCounter : PDH_HCOUNTER -> "sptr"
; pTimeBase : LONGLONG* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "pdh.dll"
#cfunc global PdhGetCounterTimeBase "PdhGetCounterTimeBase" sptr, var
; res = PdhGetCounterTimeBase(hCounter, pTimeBase)
; hCounter : PDH_HCOUNTER -> "sptr"
; pTimeBase : LONGLONG* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; DWORD PdhGetCounterTimeBase(PDH_HCOUNTER hCounter, LONGLONG* pTimeBase)
#uselib "pdh.dll"
#cfunc global PdhGetCounterTimeBase "PdhGetCounterTimeBase" intptr, var
; res = PdhGetCounterTimeBase(hCounter, pTimeBase)
; hCounter : PDH_HCOUNTER -> "intptr"
; pTimeBase : LONGLONG* out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	pdh = windows.NewLazySystemDLL("pdh.dll")
	procPdhGetCounterTimeBase = pdh.NewProc("PdhGetCounterTimeBase")
)

// hCounter (PDH_HCOUNTER), pTimeBase (LONGLONG* out)
r1, _, err := procPdhGetCounterTimeBase.Call(
	uintptr(hCounter),
	uintptr(pTimeBase),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // DWORD
function PdhGetCounterTimeBase(
  hCounter: THandle;   // PDH_HCOUNTER
  pTimeBase: Pointer   // LONGLONG* out
): DWORD; stdcall;
  external 'pdh.dll' name 'PdhGetCounterTimeBase';
result := DllCall("pdh\PdhGetCounterTimeBase"
    , "Ptr", hCounter   ; PDH_HCOUNTER
    , "Ptr", pTimeBase   ; LONGLONG* out
    , "UInt")   ; return: DWORD
●PdhGetCounterTimeBase(hCounter, pTimeBase) = DLL("pdh.dll", "dword PdhGetCounterTimeBase(void*, void*)")
# 呼び出し: PdhGetCounterTimeBase(hCounter, pTimeBase)
# hCounter : PDH_HCOUNTER -> "void*"
# pTimeBase : LONGLONG* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "pdh" fn PdhGetCounterTimeBase(
    hCounter: ?*anyopaque, // PDH_HCOUNTER
    pTimeBase: [*c]i64 // LONGLONG* out
) callconv(std.os.windows.WINAPI) u32;
proc PdhGetCounterTimeBase(
    hCounter: pointer,  # PDH_HCOUNTER
    pTimeBase: ptr int64  # LONGLONG* out
): uint32 {.importc: "PdhGetCounterTimeBase", stdcall, dynlib: "pdh.dll".}
pragma(lib, "pdh");
extern(Windows)
uint PdhGetCounterTimeBase(
    void* hCounter,   // PDH_HCOUNTER
    long* pTimeBase   // LONGLONG* out
);
ccall((:PdhGetCounterTimeBase, "pdh.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Ptr{Int64}),
      hCounter, pTimeBase)
# hCounter : PDH_HCOUNTER -> Ptr{Cvoid}
# pTimeBase : LONGLONG* out -> Ptr{Int64}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t PdhGetCounterTimeBase(
    void* hCounter,
    int64_t* pTimeBase);
]]
local pdh = ffi.load("pdh")
-- pdh.PdhGetCounterTimeBase(hCounter, pTimeBase)
-- hCounter : PDH_HCOUNTER
-- pTimeBase : LONGLONG* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('pdh.dll');
const PdhGetCounterTimeBase = lib.func('__stdcall', 'PdhGetCounterTimeBase', 'uint32_t', ['void *', 'int64_t *']);
// PdhGetCounterTimeBase(hCounter, pTimeBase)
// hCounter : PDH_HCOUNTER -> 'void *'
// pTimeBase : LONGLONG* out -> 'int64_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("pdh.dll", {
  PdhGetCounterTimeBase: { parameters: ["pointer", "pointer"], result: "u32" },
});
// lib.symbols.PdhGetCounterTimeBase(hCounter, pTimeBase)
// hCounter : PDH_HCOUNTER -> "pointer"
// pTimeBase : LONGLONG* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t PdhGetCounterTimeBase(
    void* hCounter,
    int64_t* pTimeBase);
C, "pdh.dll");
// $ffi->PdhGetCounterTimeBase(hCounter, pTimeBase);
// hCounter : PDH_HCOUNTER
// pTimeBase : LONGLONG* 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 Pdh extends StdCallLibrary {
    Pdh INSTANCE = Native.load("pdh", Pdh.class);
    int PdhGetCounterTimeBase(
        Pointer hCounter,   // PDH_HCOUNTER
        LongByReference pTimeBase   // LONGLONG* out
    );
}
@[Link("pdh")]
lib Libpdh
  fun PdhGetCounterTimeBase = PdhGetCounterTimeBase(
    hCounter : Void*,   # PDH_HCOUNTER
    pTimeBase : Int64*   # LONGLONG* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PdhGetCounterTimeBaseNative = Uint32 Function(Pointer<Void>, Pointer<Int64>);
typedef PdhGetCounterTimeBaseDart = int Function(Pointer<Void>, Pointer<Int64>);
final PdhGetCounterTimeBase = DynamicLibrary.open('pdh.dll')
    .lookupFunction<PdhGetCounterTimeBaseNative, PdhGetCounterTimeBaseDart>('PdhGetCounterTimeBase');
// hCounter : PDH_HCOUNTER -> Pointer<Void>
// pTimeBase : LONGLONG* out -> Pointer<Int64>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function PdhGetCounterTimeBase(
  hCounter: THandle;   // PDH_HCOUNTER
  pTimeBase: Pointer   // LONGLONG* out
): DWORD; stdcall;
  external 'pdh.dll' name 'PdhGetCounterTimeBase';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PdhGetCounterTimeBase"
  c_PdhGetCounterTimeBase :: Ptr () -> Ptr Int64 -> IO Word32
-- hCounter : PDH_HCOUNTER -> Ptr ()
-- pTimeBase : LONGLONG* out -> Ptr Int64
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let pdhgetcountertimebase =
  foreign "PdhGetCounterTimeBase"
    ((ptr void) @-> (ptr int64_t) @-> returning uint32_t)
(* hCounter : PDH_HCOUNTER -> (ptr void) *)
(* pTimeBase : LONGLONG* out -> (ptr int64_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library pdh (t "pdh.dll"))
(cffi:use-foreign-library pdh)

(cffi:defcfun ("PdhGetCounterTimeBase" pdh-get-counter-time-base :convention :stdcall) :uint32
  (h-counter :pointer)   ; PDH_HCOUNTER
  (p-time-base :pointer))   ; LONGLONG* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PdhGetCounterTimeBase = Win32::API::More->new('pdh',
    'DWORD PdhGetCounterTimeBase(HANDLE hCounter, LPVOID pTimeBase)');
# my $ret = $PdhGetCounterTimeBase->Call($hCounter, $pTimeBase);
# hCounter : PDH_HCOUNTER -> HANDLE
# pTimeBase : LONGLONG* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目