ホーム › System.Threading › SetWaitableTimerEx
SetWaitableTimerEx
関数完了ルーチンと許容遅延付きで待機可能タイマーを設定する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL SetWaitableTimerEx(
HANDLE hTimer,
const LONGLONG* lpDueTime,
INT lPeriod,
PTIMERAPCROUTINE pfnCompletionRoutine, // optional
void* lpArgToCompletionRoutine, // optional
REASON_CONTEXT* WakeContext, // optional
DWORD TolerableDelay
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hTimer | HANDLE | in |
| lpDueTime | LONGLONG* | in |
| lPeriod | INT | in |
| pfnCompletionRoutine | PTIMERAPCROUTINE | inoptional |
| lpArgToCompletionRoutine | void* | inoptional |
| WakeContext | REASON_CONTEXT* | inoptional |
| TolerableDelay | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL SetWaitableTimerEx(
HANDLE hTimer,
const LONGLONG* lpDueTime,
INT lPeriod,
PTIMERAPCROUTINE pfnCompletionRoutine, // optional
void* lpArgToCompletionRoutine, // optional
REASON_CONTEXT* WakeContext, // optional
DWORD TolerableDelay
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetWaitableTimerEx(
IntPtr hTimer, // HANDLE
ref long lpDueTime, // LONGLONG*
int lPeriod, // INT
IntPtr pfnCompletionRoutine, // PTIMERAPCROUTINE optional
IntPtr lpArgToCompletionRoutine, // void* optional
IntPtr WakeContext, // REASON_CONTEXT* optional
uint TolerableDelay // DWORD
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetWaitableTimerEx(
hTimer As IntPtr, ' HANDLE
ByRef lpDueTime As Long, ' LONGLONG*
lPeriod As Integer, ' INT
pfnCompletionRoutine As IntPtr, ' PTIMERAPCROUTINE optional
lpArgToCompletionRoutine As IntPtr, ' void* optional
WakeContext As IntPtr, ' REASON_CONTEXT* optional
TolerableDelay As UInteger ' DWORD
) As Boolean
End Function' hTimer : HANDLE
' lpDueTime : LONGLONG*
' lPeriod : INT
' pfnCompletionRoutine : PTIMERAPCROUTINE optional
' lpArgToCompletionRoutine : void* optional
' WakeContext : REASON_CONTEXT* optional
' TolerableDelay : DWORD
Declare PtrSafe Function SetWaitableTimerEx Lib "kernel32" ( _
ByVal hTimer As LongPtr, _
ByRef lpDueTime As LongLong, _
ByVal lPeriod As Long, _
ByVal pfnCompletionRoutine As LongPtr, _
ByVal lpArgToCompletionRoutine As LongPtr, _
ByVal WakeContext As LongPtr, _
ByVal TolerableDelay As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetWaitableTimerEx = ctypes.windll.kernel32.SetWaitableTimerEx
SetWaitableTimerEx.restype = wintypes.BOOL
SetWaitableTimerEx.argtypes = [
wintypes.HANDLE, # hTimer : HANDLE
ctypes.POINTER(ctypes.c_longlong), # lpDueTime : LONGLONG*
ctypes.c_int, # lPeriod : INT
ctypes.c_void_p, # pfnCompletionRoutine : PTIMERAPCROUTINE optional
ctypes.POINTER(None), # lpArgToCompletionRoutine : void* optional
ctypes.c_void_p, # WakeContext : REASON_CONTEXT* optional
wintypes.DWORD, # TolerableDelay : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetWaitableTimerEx = Fiddle::Function.new(
lib['SetWaitableTimerEx'],
[
Fiddle::TYPE_VOIDP, # hTimer : HANDLE
Fiddle::TYPE_VOIDP, # lpDueTime : LONGLONG*
Fiddle::TYPE_INT, # lPeriod : INT
Fiddle::TYPE_VOIDP, # pfnCompletionRoutine : PTIMERAPCROUTINE optional
Fiddle::TYPE_VOIDP, # lpArgToCompletionRoutine : void* optional
Fiddle::TYPE_VOIDP, # WakeContext : REASON_CONTEXT* optional
-Fiddle::TYPE_INT, # TolerableDelay : DWORD
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn SetWaitableTimerEx(
hTimer: *mut core::ffi::c_void, // HANDLE
lpDueTime: *const i64, // LONGLONG*
lPeriod: i32, // INT
pfnCompletionRoutine: *const core::ffi::c_void, // PTIMERAPCROUTINE optional
lpArgToCompletionRoutine: *mut (), // void* optional
WakeContext: *mut REASON_CONTEXT, // REASON_CONTEXT* optional
TolerableDelay: u32 // DWORD
) -> 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 SetWaitableTimerEx(IntPtr hTimer, ref long lpDueTime, int lPeriod, IntPtr pfnCompletionRoutine, IntPtr lpArgToCompletionRoutine, IntPtr WakeContext, uint TolerableDelay);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetWaitableTimerEx' -Namespace Win32 -PassThru
# $api::SetWaitableTimerEx(hTimer, lpDueTime, lPeriod, pfnCompletionRoutine, lpArgToCompletionRoutine, WakeContext, TolerableDelay)#uselib "KERNEL32.dll"
#func global SetWaitableTimerEx "SetWaitableTimerEx" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetWaitableTimerEx hTimer, varptr(lpDueTime), lPeriod, pfnCompletionRoutine, lpArgToCompletionRoutine, varptr(WakeContext), TolerableDelay ; 戻り値は stat
; hTimer : HANDLE -> "sptr"
; lpDueTime : LONGLONG* -> "sptr"
; lPeriod : INT -> "sptr"
; pfnCompletionRoutine : PTIMERAPCROUTINE optional -> "sptr"
; lpArgToCompletionRoutine : void* optional -> "sptr"
; WakeContext : REASON_CONTEXT* optional -> "sptr"
; TolerableDelay : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global SetWaitableTimerEx "SetWaitableTimerEx" sptr, var, int, sptr, sptr, var, int ; res = SetWaitableTimerEx(hTimer, lpDueTime, lPeriod, pfnCompletionRoutine, lpArgToCompletionRoutine, WakeContext, TolerableDelay) ; hTimer : HANDLE -> "sptr" ; lpDueTime : LONGLONG* -> "var" ; lPeriod : INT -> "int" ; pfnCompletionRoutine : PTIMERAPCROUTINE optional -> "sptr" ; lpArgToCompletionRoutine : void* optional -> "sptr" ; WakeContext : REASON_CONTEXT* optional -> "var" ; TolerableDelay : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global SetWaitableTimerEx "SetWaitableTimerEx" sptr, sptr, int, sptr, sptr, sptr, int ; res = SetWaitableTimerEx(hTimer, varptr(lpDueTime), lPeriod, pfnCompletionRoutine, lpArgToCompletionRoutine, varptr(WakeContext), TolerableDelay) ; hTimer : HANDLE -> "sptr" ; lpDueTime : LONGLONG* -> "sptr" ; lPeriod : INT -> "int" ; pfnCompletionRoutine : PTIMERAPCROUTINE optional -> "sptr" ; lpArgToCompletionRoutine : void* optional -> "sptr" ; WakeContext : REASON_CONTEXT* optional -> "sptr" ; TolerableDelay : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetWaitableTimerEx(HANDLE hTimer, LONGLONG* lpDueTime, INT lPeriod, PTIMERAPCROUTINE pfnCompletionRoutine, void* lpArgToCompletionRoutine, REASON_CONTEXT* WakeContext, DWORD TolerableDelay) #uselib "KERNEL32.dll" #cfunc global SetWaitableTimerEx "SetWaitableTimerEx" intptr, var, int, intptr, intptr, var, int ; res = SetWaitableTimerEx(hTimer, lpDueTime, lPeriod, pfnCompletionRoutine, lpArgToCompletionRoutine, WakeContext, TolerableDelay) ; hTimer : HANDLE -> "intptr" ; lpDueTime : LONGLONG* -> "var" ; lPeriod : INT -> "int" ; pfnCompletionRoutine : PTIMERAPCROUTINE optional -> "intptr" ; lpArgToCompletionRoutine : void* optional -> "intptr" ; WakeContext : REASON_CONTEXT* optional -> "var" ; TolerableDelay : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetWaitableTimerEx(HANDLE hTimer, LONGLONG* lpDueTime, INT lPeriod, PTIMERAPCROUTINE pfnCompletionRoutine, void* lpArgToCompletionRoutine, REASON_CONTEXT* WakeContext, DWORD TolerableDelay) #uselib "KERNEL32.dll" #cfunc global SetWaitableTimerEx "SetWaitableTimerEx" intptr, intptr, int, intptr, intptr, intptr, int ; res = SetWaitableTimerEx(hTimer, varptr(lpDueTime), lPeriod, pfnCompletionRoutine, lpArgToCompletionRoutine, varptr(WakeContext), TolerableDelay) ; hTimer : HANDLE -> "intptr" ; lpDueTime : LONGLONG* -> "intptr" ; lPeriod : INT -> "int" ; pfnCompletionRoutine : PTIMERAPCROUTINE optional -> "intptr" ; lpArgToCompletionRoutine : void* optional -> "intptr" ; WakeContext : REASON_CONTEXT* optional -> "intptr" ; TolerableDelay : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetWaitableTimerEx = kernel32.NewProc("SetWaitableTimerEx")
)
// hTimer (HANDLE), lpDueTime (LONGLONG*), lPeriod (INT), pfnCompletionRoutine (PTIMERAPCROUTINE optional), lpArgToCompletionRoutine (void* optional), WakeContext (REASON_CONTEXT* optional), TolerableDelay (DWORD)
r1, _, err := procSetWaitableTimerEx.Call(
uintptr(hTimer),
uintptr(lpDueTime),
uintptr(lPeriod),
uintptr(pfnCompletionRoutine),
uintptr(lpArgToCompletionRoutine),
uintptr(WakeContext),
uintptr(TolerableDelay),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetWaitableTimerEx(
hTimer: THandle; // HANDLE
lpDueTime: Pointer; // LONGLONG*
lPeriod: Integer; // INT
pfnCompletionRoutine: Pointer; // PTIMERAPCROUTINE optional
lpArgToCompletionRoutine: Pointer; // void* optional
WakeContext: Pointer; // REASON_CONTEXT* optional
TolerableDelay: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetWaitableTimerEx';result := DllCall("KERNEL32\SetWaitableTimerEx"
, "Ptr", hTimer ; HANDLE
, "Ptr", lpDueTime ; LONGLONG*
, "Int", lPeriod ; INT
, "Ptr", pfnCompletionRoutine ; PTIMERAPCROUTINE optional
, "Ptr", lpArgToCompletionRoutine ; void* optional
, "Ptr", WakeContext ; REASON_CONTEXT* optional
, "UInt", TolerableDelay ; DWORD
, "Int") ; return: BOOL●SetWaitableTimerEx(hTimer, lpDueTime, lPeriod, pfnCompletionRoutine, lpArgToCompletionRoutine, WakeContext, TolerableDelay) = DLL("KERNEL32.dll", "bool SetWaitableTimerEx(void*, void*, int, void*, void*, void*, dword)")
# 呼び出し: SetWaitableTimerEx(hTimer, lpDueTime, lPeriod, pfnCompletionRoutine, lpArgToCompletionRoutine, WakeContext, TolerableDelay)
# hTimer : HANDLE -> "void*"
# lpDueTime : LONGLONG* -> "void*"
# lPeriod : INT -> "int"
# pfnCompletionRoutine : PTIMERAPCROUTINE optional -> "void*"
# lpArgToCompletionRoutine : void* optional -> "void*"
# WakeContext : REASON_CONTEXT* optional -> "void*"
# TolerableDelay : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。