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