ホーム › System.SystemInformation › GetTickCount64
GetTickCount64
関数システム起動からの経過ミリ秒数を64ビット値で取得する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
ULONGLONG GetTickCount64(void);パラメーターなし。戻り値: ULONGLONG
公式ドキュメント
システムが起動してから経過したミリ秒数を取得します。
戻り値
経過したミリ秒数。
解説(Remarks)
GetTickCount64 関数の分解能は、システムタイマーの分解能に制限されます。これは通常 10 ミリ秒から 16 ミリ秒の範囲です。GetTickCount64 関数の分解能は、 GetSystemTimeAdjustment 関数による調整の影響を受けません。
より高い分解能のタイマーが必要な場合は、 マルチメディアタイマー または 高分解能タイマー を使用してください。
システムが起動してから動作状態 (working state) で費やした時間を取得するには、QueryUnbiasedInterruptTime 関数を使用してください。
注意 QueryUnbiasedInterruptTime 関数は、Windows のデバッグ ("チェック済み") ビルドでは異なる結果を返します。これは、割り込み時間のカウントとティックカウントが約 49 日分進められるためです。これにより、システムが長時間動作するまで発生しないようなバグを特定しやすくなります。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
ULONGLONG GetTickCount64(void);[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern ulong GetTickCount64();<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function GetTickCount64() As ULong
End FunctionDeclare PtrSafe Function GetTickCount64 Lib "kernel32" () As LongLong
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GetTickCount64 = ctypes.windll.kernel32.GetTickCount64
GetTickCount64.restype = ctypes.c_ulonglong
GetTickCount64.argtypes = []require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
GetTickCount64 = Fiddle::Function.new(
lib['GetTickCount64'],
[],
-Fiddle::TYPE_LONG_LONG)#[link(name = "kernel32")]
extern "system" {
fn GetTickCount64() -> u64;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll")]
public static extern ulong GetTickCount64();
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_GetTickCount64' -Namespace Win32 -PassThru
# $api::GetTickCount64()#uselib "KERNEL32.dll"
#func global GetTickCount64 "GetTickCount64"
; GetTickCount64 ; 戻り値は stat
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll"
#cfunc global GetTickCount64 "GetTickCount64"
; res = GetTickCount64(); ULONGLONG GetTickCount64()
#uselib "KERNEL32.dll"
#cfunc global GetTickCount64 "GetTickCount64"
; res = GetTickCount64()import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procGetTickCount64 = kernel32.NewProc("GetTickCount64")
)
r1, _, err := procGetTickCount64.Call()
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // ULONGLONGfunction GetTickCount64: UInt64; stdcall;
external 'KERNEL32.dll' name 'GetTickCount64';result := DllCall("KERNEL32\GetTickCount64", "Int64")●GetTickCount64() = DLL("KERNEL32.dll", "qword GetTickCount64()")
# 呼び出し: GetTickCount64()
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn GetTickCount64() callconv(std.os.windows.WINAPI) u64;proc GetTickCount64(): uint64 {.importc: "GetTickCount64", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
ulong GetTickCount64();ccall((:GetTickCount64, "KERNEL32.dll"), stdcall, UInt64,
(),
)
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint64_t GetTickCount64(void);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.GetTickCount64()
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const GetTickCount64 = lib.func('__stdcall', 'GetTickCount64', 'uint64_t', []);
// GetTickCount64()
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
GetTickCount64: { parameters: [], result: "u64" },
});
// lib.symbols.GetTickCount64()
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint64_t GetTickCount64(void);
C, "KERNEL32.dll");
// $ffi->GetTickCount64();
// 構造体/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);
long GetTickCount64();
}@[Link("kernel32")]
lib LibKERNEL32
fun GetTickCount64 = GetTickCount64() : UInt64
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GetTickCount64Native = Uint64 Function();
typedef GetTickCount64Dart = int Function();
final GetTickCount64 = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<GetTickCount64Native, GetTickCount64Dart>('GetTickCount64');
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GetTickCount64: UInt64; stdcall;
external 'KERNEL32.dll' name 'GetTickCount64';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GetTickCount64"
c_GetTickCount64 :: IO Word64
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gettickcount64 =
foreign "GetTickCount64"
(void @-> returning uint64_t)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("GetTickCount64" get-tick-count64 :convention :stdcall) :uint64)
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GetTickCount64 = Win32::API::More->new('KERNEL32',
'UINT64 GetTickCount64()');
# my $ret = $GetTickCount64->Call();
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
類似 API
- f GetTickCount — システム起動からの経過ミリ秒数を取得する。