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

SetSystemTimeAdjustmentPrecise

関数
システム時刻の高精度な周期的調整値を設定する。
DLLapi-ms-win-core-sysinfo-l1-2-4.dll呼出規約winapiSetLastErrorあり対応OSWindows 10 以降

シグネチャ

// api-ms-win-core-sysinfo-l1-2-4.dll
#include <windows.h>

BOOL SetSystemTimeAdjustmentPrecise(
    ULONGLONG dwTimeAdjustment,
    BOOL bTimeAdjustmentDisabled
);

パラメーター

名前方向
dwTimeAdjustmentULONGLONGin
bTimeAdjustmentDisabledBOOLin

戻り値の型: BOOL

各言語での呼び出し定義

// api-ms-win-core-sysinfo-l1-2-4.dll
#include <windows.h>

BOOL SetSystemTimeAdjustmentPrecise(
    ULONGLONG dwTimeAdjustment,
    BOOL bTimeAdjustmentDisabled
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-sysinfo-l1-2-4.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetSystemTimeAdjustmentPrecise(
    ulong dwTimeAdjustment,   // ULONGLONG
    bool bTimeAdjustmentDisabled   // BOOL
);
<DllImport("api-ms-win-core-sysinfo-l1-2-4.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetSystemTimeAdjustmentPrecise(
    dwTimeAdjustment As ULong,   ' ULONGLONG
    bTimeAdjustmentDisabled As Boolean   ' BOOL
) As Boolean
End Function
' dwTimeAdjustment : ULONGLONG
' bTimeAdjustmentDisabled : BOOL
Declare PtrSafe Function SetSystemTimeAdjustmentPrecise Lib "api-ms-win-core-sysinfo-l1-2-4" ( _
    ByVal dwTimeAdjustment As LongLong, _
    ByVal bTimeAdjustmentDisabled As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

SetSystemTimeAdjustmentPrecise = ctypes.windll.LoadLibrary("api-ms-win-core-sysinfo-l1-2-4.dll").SetSystemTimeAdjustmentPrecise
SetSystemTimeAdjustmentPrecise.restype = wintypes.BOOL
SetSystemTimeAdjustmentPrecise.argtypes = [
    ctypes.c_ulonglong,  # dwTimeAdjustment : ULONGLONG
    wintypes.BOOL,  # bTimeAdjustmentDisabled : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('api-ms-win-core-sysinfo-l1-2-4.dll')
SetSystemTimeAdjustmentPrecise = Fiddle::Function.new(
  lib['SetSystemTimeAdjustmentPrecise'],
  [
    -Fiddle::TYPE_LONG_LONG,  # dwTimeAdjustment : ULONGLONG
    Fiddle::TYPE_INT,  # bTimeAdjustmentDisabled : BOOL
  ],
  Fiddle::TYPE_INT)
#[link(name = "api-ms-win-core-sysinfo-l1-2-4")]
extern "system" {
    fn SetSystemTimeAdjustmentPrecise(
        dwTimeAdjustment: u64,  // ULONGLONG
        bTimeAdjustmentDisabled: i32  // BOOL
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("api-ms-win-core-sysinfo-l1-2-4.dll", SetLastError = true)]
public static extern bool SetSystemTimeAdjustmentPrecise(ulong dwTimeAdjustment, bool bTimeAdjustmentDisabled);
"@
$api = Add-Type -MemberDefinition $sig -Name 'api-ms-win-core-sysinfo-l1-2-4_SetSystemTimeAdjustmentPrecise' -Namespace Win32 -PassThru
# $api::SetSystemTimeAdjustmentPrecise(dwTimeAdjustment, bTimeAdjustmentDisabled)
#uselib "api-ms-win-core-sysinfo-l1-2-4.dll"
#func global SetSystemTimeAdjustmentPrecise "SetSystemTimeAdjustmentPrecise" sptr, sptr
; SetSystemTimeAdjustmentPrecise dwTimeAdjustment, bTimeAdjustmentDisabled   ; 戻り値は stat
; dwTimeAdjustment : ULONGLONG -> "sptr"
; bTimeAdjustmentDisabled : BOOL -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "api-ms-win-core-sysinfo-l1-2-4.dll"
#cfunc global SetSystemTimeAdjustmentPrecise "SetSystemTimeAdjustmentPrecise" int64, int
; res = SetSystemTimeAdjustmentPrecise(dwTimeAdjustment, bTimeAdjustmentDisabled)
; dwTimeAdjustment : ULONGLONG -> "int64"
; bTimeAdjustmentDisabled : BOOL -> "int"
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; BOOL SetSystemTimeAdjustmentPrecise(ULONGLONG dwTimeAdjustment, BOOL bTimeAdjustmentDisabled)
#uselib "api-ms-win-core-sysinfo-l1-2-4.dll"
#cfunc global SetSystemTimeAdjustmentPrecise "SetSystemTimeAdjustmentPrecise" int64, int
; res = SetSystemTimeAdjustmentPrecise(dwTimeAdjustment, bTimeAdjustmentDisabled)
; dwTimeAdjustment : ULONGLONG -> "int64"
; bTimeAdjustmentDisabled : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	api_ms_win_core_sysinfo_l1_2_4 = windows.NewLazySystemDLL("api-ms-win-core-sysinfo-l1-2-4.dll")
	procSetSystemTimeAdjustmentPrecise = api_ms_win_core_sysinfo_l1_2_4.NewProc("SetSystemTimeAdjustmentPrecise")
)

// dwTimeAdjustment (ULONGLONG), bTimeAdjustmentDisabled (BOOL)
r1, _, err := procSetSystemTimeAdjustmentPrecise.Call(
	uintptr(dwTimeAdjustment),
	uintptr(bTimeAdjustmentDisabled),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function SetSystemTimeAdjustmentPrecise(
  dwTimeAdjustment: UInt64;   // ULONGLONG
  bTimeAdjustmentDisabled: BOOL   // BOOL
): BOOL; stdcall;
  external 'api-ms-win-core-sysinfo-l1-2-4.dll' name 'SetSystemTimeAdjustmentPrecise';
result := DllCall("api-ms-win-core-sysinfo-l1-2-4\SetSystemTimeAdjustmentPrecise"
    , "Int64", dwTimeAdjustment   ; ULONGLONG
    , "Int", bTimeAdjustmentDisabled   ; BOOL
    , "Int")   ; return: BOOL
●SetSystemTimeAdjustmentPrecise(dwTimeAdjustment, bTimeAdjustmentDisabled) = DLL("api-ms-win-core-sysinfo-l1-2-4.dll", "bool SetSystemTimeAdjustmentPrecise(qword, bool)")
# 呼び出し: SetSystemTimeAdjustmentPrecise(dwTimeAdjustment, bTimeAdjustmentDisabled)
# dwTimeAdjustment : ULONGLONG -> "qword"
# bTimeAdjustmentDisabled : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。