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

SleepEx

関数
指定時間スレッドを休止し警告可能な待機を行う。
DLLKERNEL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

DWORD SleepEx(
    DWORD dwMilliseconds,
    BOOL bAlertable
);

パラメーター

名前方向
dwMillisecondsDWORDin
bAlertableBOOLin

戻り値の型: DWORD

各言語での呼び出し定義

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

DWORD SleepEx(
    DWORD dwMilliseconds,
    BOOL bAlertable
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern uint SleepEx(
    uint dwMilliseconds,   // DWORD
    bool bAlertable   // BOOL
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Function SleepEx(
    dwMilliseconds As UInteger,   ' DWORD
    bAlertable As Boolean   ' BOOL
) As UInteger
End Function
' dwMilliseconds : DWORD
' bAlertable : BOOL
Declare PtrSafe Function SleepEx Lib "kernel32" ( _
    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

SleepEx = ctypes.windll.kernel32.SleepEx
SleepEx.restype = wintypes.DWORD
SleepEx.argtypes = [
    wintypes.DWORD,  # dwMilliseconds : DWORD
    wintypes.BOOL,  # bAlertable : BOOL
]
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSleepEx = kernel32.NewProc("SleepEx")
)

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