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

WaitForSingleObjectEx

関数
警告可能モードで単一オブジェクトのシグナルを待機する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

// KERNEL32.dll
#include <windows.h>

WAIT_EVENT WaitForSingleObjectEx(
    HANDLE hHandle,
    DWORD dwMilliseconds,
    BOOL bAlertable
);

パラメーター

名前方向
hHandleHANDLEin
dwMillisecondsDWORDin
bAlertableBOOLin

戻り値の型: WAIT_EVENT

各言語での呼び出し定義

// KERNEL32.dll
#include <windows.h>

WAIT_EVENT WaitForSingleObjectEx(
    HANDLE hHandle,
    DWORD dwMilliseconds,
    BOOL bAlertable
);
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern uint WaitForSingleObjectEx(
    IntPtr hHandle,   // HANDLE
    uint dwMilliseconds,   // DWORD
    bool bAlertable   // BOOL
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WaitForSingleObjectEx(
    hHandle As IntPtr,   ' HANDLE
    dwMilliseconds As UInteger,   ' DWORD
    bAlertable As Boolean   ' BOOL
) As UInteger
End Function
' hHandle : HANDLE
' dwMilliseconds : DWORD
' bAlertable : BOOL
Declare PtrSafe Function WaitForSingleObjectEx Lib "kernel32" ( _
    ByVal hHandle As LongPtr, _
    ByVal dwMilliseconds As Long, _
    ByVal bAlertable As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WaitForSingleObjectEx = ctypes.windll.kernel32.WaitForSingleObjectEx
WaitForSingleObjectEx.restype = wintypes.DWORD
WaitForSingleObjectEx.argtypes = [
    wintypes.HANDLE,  # hHandle : HANDLE
    wintypes.DWORD,  # dwMilliseconds : DWORD
    wintypes.BOOL,  # bAlertable : BOOL
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
WaitForSingleObjectEx = Fiddle::Function.new(
  lib['WaitForSingleObjectEx'],
  [
    Fiddle::TYPE_VOIDP,  # hHandle : HANDLE
    -Fiddle::TYPE_INT,  # dwMilliseconds : DWORD
    Fiddle::TYPE_INT,  # bAlertable : BOOL
  ],
  -Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn WaitForSingleObjectEx(
        hHandle: *mut core::ffi::c_void,  // HANDLE
        dwMilliseconds: u32,  // DWORD
        bAlertable: i32  // BOOL
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern uint WaitForSingleObjectEx(IntPtr hHandle, uint dwMilliseconds, bool bAlertable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_WaitForSingleObjectEx' -Namespace Win32 -PassThru
# $api::WaitForSingleObjectEx(hHandle, dwMilliseconds, bAlertable)
#uselib "KERNEL32.dll"
#func global WaitForSingleObjectEx "WaitForSingleObjectEx" sptr, sptr, sptr
; WaitForSingleObjectEx hHandle, dwMilliseconds, bAlertable   ; 戻り値は stat
; hHandle : HANDLE -> "sptr"
; dwMilliseconds : DWORD -> "sptr"
; bAlertable : BOOL -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global WaitForSingleObjectEx "WaitForSingleObjectEx" sptr, int, int
; res = WaitForSingleObjectEx(hHandle, dwMilliseconds, bAlertable)
; hHandle : HANDLE -> "sptr"
; dwMilliseconds : DWORD -> "int"
; bAlertable : BOOL -> "int"
; WAIT_EVENT WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertable)
#uselib "KERNEL32.dll"
#cfunc global WaitForSingleObjectEx "WaitForSingleObjectEx" intptr, int, int
; res = WaitForSingleObjectEx(hHandle, dwMilliseconds, bAlertable)
; hHandle : HANDLE -> "intptr"
; dwMilliseconds : DWORD -> "int"
; bAlertable : BOOL -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procWaitForSingleObjectEx = kernel32.NewProc("WaitForSingleObjectEx")
)

// hHandle (HANDLE), dwMilliseconds (DWORD), bAlertable (BOOL)
r1, _, err := procWaitForSingleObjectEx.Call(
	uintptr(hHandle),
	uintptr(dwMilliseconds),
	uintptr(bAlertable),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WAIT_EVENT
function WaitForSingleObjectEx(
  hHandle: THandle;   // HANDLE
  dwMilliseconds: DWORD;   // DWORD
  bAlertable: BOOL   // BOOL
): DWORD; stdcall;
  external 'KERNEL32.dll' name 'WaitForSingleObjectEx';
result := DllCall("KERNEL32\WaitForSingleObjectEx"
    , "Ptr", hHandle   ; HANDLE
    , "UInt", dwMilliseconds   ; DWORD
    , "Int", bAlertable   ; BOOL
    , "UInt")   ; return: WAIT_EVENT
●WaitForSingleObjectEx(hHandle, dwMilliseconds, bAlertable) = DLL("KERNEL32.dll", "dword WaitForSingleObjectEx(void*, dword, bool)")
# 呼び出し: WaitForSingleObjectEx(hHandle, dwMilliseconds, bAlertable)
# hHandle : HANDLE -> "void*"
# dwMilliseconds : DWORD -> "dword"
# bAlertable : BOOL -> "bool"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。