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

CreateWaitableTimerW

関数
名前付きまたは無名の待機可能タイマーを作成する(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

HANDLE CreateWaitableTimerW(
    SECURITY_ATTRIBUTES* lpTimerAttributes,   // optional
    BOOL bManualReset,
    LPCWSTR lpTimerName   // optional
);

パラメーター

名前方向
lpTimerAttributesSECURITY_ATTRIBUTES*inoptional
bManualResetBOOLin
lpTimerNameLPCWSTRinoptional

戻り値の型: HANDLE

各言語での呼び出し定義

// KERNEL32.dll  (Unicode / -W)
#include <windows.h>

HANDLE CreateWaitableTimerW(
    SECURITY_ATTRIBUTES* lpTimerAttributes,   // optional
    BOOL bManualReset,
    LPCWSTR lpTimerName   // optional
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateWaitableTimerW(
    IntPtr lpTimerAttributes,   // SECURITY_ATTRIBUTES* optional
    bool bManualReset,   // BOOL
    [MarshalAs(UnmanagedType.LPWStr)] string lpTimerName   // LPCWSTR optional
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateWaitableTimerW(
    lpTimerAttributes As IntPtr,   ' SECURITY_ATTRIBUTES* optional
    bManualReset As Boolean,   ' BOOL
    <MarshalAs(UnmanagedType.LPWStr)> lpTimerName As String   ' LPCWSTR optional
) As IntPtr
End Function
' lpTimerAttributes : SECURITY_ATTRIBUTES* optional
' bManualReset : BOOL
' lpTimerName : LPCWSTR optional
Declare PtrSafe Function CreateWaitableTimerW Lib "kernel32" ( _
    ByVal lpTimerAttributes As LongPtr, _
    ByVal bManualReset As Long, _
    ByVal lpTimerName As LongPtr) As LongPtr
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

CreateWaitableTimerW = ctypes.windll.kernel32.CreateWaitableTimerW
CreateWaitableTimerW.restype = ctypes.c_void_p
CreateWaitableTimerW.argtypes = [
    ctypes.c_void_p,  # lpTimerAttributes : SECURITY_ATTRIBUTES* optional
    wintypes.BOOL,  # bManualReset : BOOL
    wintypes.LPCWSTR,  # lpTimerName : LPCWSTR optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
CreateWaitableTimerW = Fiddle::Function.new(
  lib['CreateWaitableTimerW'],
  [
    Fiddle::TYPE_VOIDP,  # lpTimerAttributes : SECURITY_ATTRIBUTES* optional
    Fiddle::TYPE_INT,  # bManualReset : BOOL
    Fiddle::TYPE_VOIDP,  # lpTimerName : LPCWSTR optional
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn CreateWaitableTimerW(
        lpTimerAttributes: *mut SECURITY_ATTRIBUTES,  // SECURITY_ATTRIBUTES* optional
        bManualReset: i32,  // BOOL
        lpTimerName: *const u16  // LPCWSTR optional
    ) -> *mut core::ffi::c_void;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CreateWaitableTimerW(IntPtr lpTimerAttributes, bool bManualReset, [MarshalAs(UnmanagedType.LPWStr)] string lpTimerName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CreateWaitableTimerW' -Namespace Win32 -PassThru
# $api::CreateWaitableTimerW(lpTimerAttributes, bManualReset, lpTimerName)
#uselib "KERNEL32.dll"
#func global CreateWaitableTimerW "CreateWaitableTimerW" wptr, wptr, wptr
; CreateWaitableTimerW varptr(lpTimerAttributes), bManualReset, lpTimerName   ; 戻り値は stat
; lpTimerAttributes : SECURITY_ATTRIBUTES* optional -> "wptr"
; bManualReset : BOOL -> "wptr"
; lpTimerName : LPCWSTR optional -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global CreateWaitableTimerW "CreateWaitableTimerW" var, int, wstr
; res = CreateWaitableTimerW(lpTimerAttributes, bManualReset, lpTimerName)
; lpTimerAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; bManualReset : BOOL -> "int"
; lpTimerName : LPCWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; HANDLE CreateWaitableTimerW(SECURITY_ATTRIBUTES* lpTimerAttributes, BOOL bManualReset, LPCWSTR lpTimerName)
#uselib "KERNEL32.dll"
#cfunc global CreateWaitableTimerW "CreateWaitableTimerW" var, int, wstr
; res = CreateWaitableTimerW(lpTimerAttributes, bManualReset, lpTimerName)
; lpTimerAttributes : SECURITY_ATTRIBUTES* optional -> "var"
; bManualReset : BOOL -> "int"
; lpTimerName : LPCWSTR optional -> "wstr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procCreateWaitableTimerW = kernel32.NewProc("CreateWaitableTimerW")
)

// lpTimerAttributes (SECURITY_ATTRIBUTES* optional), bManualReset (BOOL), lpTimerName (LPCWSTR optional)
r1, _, err := procCreateWaitableTimerW.Call(
	uintptr(lpTimerAttributes),
	uintptr(bManualReset),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpTimerName))),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HANDLE
function CreateWaitableTimerW(
  lpTimerAttributes: Pointer;   // SECURITY_ATTRIBUTES* optional
  bManualReset: BOOL;   // BOOL
  lpTimerName: PWideChar   // LPCWSTR optional
): THandle; stdcall;
  external 'KERNEL32.dll' name 'CreateWaitableTimerW';
result := DllCall("KERNEL32\CreateWaitableTimerW"
    , "Ptr", lpTimerAttributes   ; SECURITY_ATTRIBUTES* optional
    , "Int", bManualReset   ; BOOL
    , "WStr", lpTimerName   ; LPCWSTR optional
    , "Ptr")   ; return: HANDLE
●CreateWaitableTimerW(lpTimerAttributes, bManualReset, lpTimerName) = DLL("KERNEL32.dll", "void* CreateWaitableTimerW(void*, bool, char*)")
# 呼び出し: CreateWaitableTimerW(lpTimerAttributes, bManualReset, lpTimerName)
# lpTimerAttributes : SECURITY_ATTRIBUTES* optional -> "void*"
# bManualReset : BOOL -> "bool"
# lpTimerName : LPCWSTR optional -> "char*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。