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

OpenWaitableTimerW

関数
既存の名前付き待機可能タイマーを開く(Unicode版)。
DLLKERNEL32.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

HANDLE OpenWaitableTimerW(
    SYNCHRONIZATION_ACCESS_RIGHTS dwDesiredAccess,
    BOOL bInheritHandle,
    LPCWSTR lpTimerName
);

パラメーター

名前方向
dwDesiredAccessSYNCHRONIZATION_ACCESS_RIGHTSin
bInheritHandleBOOLin
lpTimerNameLPCWSTRin

戻り値の型: HANDLE

各言語での呼び出し定義

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

HANDLE OpenWaitableTimerW(
    SYNCHRONIZATION_ACCESS_RIGHTS dwDesiredAccess,
    BOOL bInheritHandle,
    LPCWSTR lpTimerName
);
[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern IntPtr OpenWaitableTimerW(
    uint dwDesiredAccess,   // SYNCHRONIZATION_ACCESS_RIGHTS
    bool bInheritHandle,   // BOOL
    [MarshalAs(UnmanagedType.LPWStr)] string lpTimerName   // LPCWSTR
);
<DllImport("KERNEL32.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function OpenWaitableTimerW(
    dwDesiredAccess As UInteger,   ' SYNCHRONIZATION_ACCESS_RIGHTS
    bInheritHandle As Boolean,   ' BOOL
    <MarshalAs(UnmanagedType.LPWStr)> lpTimerName As String   ' LPCWSTR
) As IntPtr
End Function
' dwDesiredAccess : SYNCHRONIZATION_ACCESS_RIGHTS
' bInheritHandle : BOOL
' lpTimerName : LPCWSTR
Declare PtrSafe Function OpenWaitableTimerW Lib "kernel32" ( _
    ByVal dwDesiredAccess As Long, _
    ByVal bInheritHandle 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

OpenWaitableTimerW = ctypes.windll.kernel32.OpenWaitableTimerW
OpenWaitableTimerW.restype = ctypes.c_void_p
OpenWaitableTimerW.argtypes = [
    wintypes.DWORD,  # dwDesiredAccess : SYNCHRONIZATION_ACCESS_RIGHTS
    wintypes.BOOL,  # bInheritHandle : BOOL
    wintypes.LPCWSTR,  # lpTimerName : LPCWSTR
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
OpenWaitableTimerW = Fiddle::Function.new(
  lib['OpenWaitableTimerW'],
  [
    -Fiddle::TYPE_INT,  # dwDesiredAccess : SYNCHRONIZATION_ACCESS_RIGHTS
    Fiddle::TYPE_INT,  # bInheritHandle : BOOL
    Fiddle::TYPE_VOIDP,  # lpTimerName : LPCWSTR
  ],
  Fiddle::TYPE_VOIDP)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "kernel32")]
extern "system" {
    fn OpenWaitableTimerW(
        dwDesiredAccess: u32,  // SYNCHRONIZATION_ACCESS_RIGHTS
        bInheritHandle: i32,  // BOOL
        lpTimerName: *const u16  // LPCWSTR
    ) -> *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 OpenWaitableTimerW(uint dwDesiredAccess, bool bInheritHandle, [MarshalAs(UnmanagedType.LPWStr)] string lpTimerName);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_OpenWaitableTimerW' -Namespace Win32 -PassThru
# $api::OpenWaitableTimerW(dwDesiredAccess, bInheritHandle, lpTimerName)
#uselib "KERNEL32.dll"
#func global OpenWaitableTimerW "OpenWaitableTimerW" wptr, wptr, wptr
; OpenWaitableTimerW dwDesiredAccess, bInheritHandle, lpTimerName   ; 戻り値は stat
; dwDesiredAccess : SYNCHRONIZATION_ACCESS_RIGHTS -> "wptr"
; bInheritHandle : BOOL -> "wptr"
; lpTimerName : LPCWSTR -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global OpenWaitableTimerW "OpenWaitableTimerW" int, int, wstr
; res = OpenWaitableTimerW(dwDesiredAccess, bInheritHandle, lpTimerName)
; dwDesiredAccess : SYNCHRONIZATION_ACCESS_RIGHTS -> "int"
; bInheritHandle : BOOL -> "int"
; lpTimerName : LPCWSTR -> "wstr"
; HANDLE OpenWaitableTimerW(SYNCHRONIZATION_ACCESS_RIGHTS dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpTimerName)
#uselib "KERNEL32.dll"
#cfunc global OpenWaitableTimerW "OpenWaitableTimerW" int, int, wstr
; res = OpenWaitableTimerW(dwDesiredAccess, bInheritHandle, lpTimerName)
; dwDesiredAccess : SYNCHRONIZATION_ACCESS_RIGHTS -> "int"
; bInheritHandle : BOOL -> "int"
; lpTimerName : LPCWSTR -> "wstr"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procOpenWaitableTimerW = kernel32.NewProc("OpenWaitableTimerW")
)

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