Win32 API 日本語リファレンス
ホームDevices.Communication › WaitCommEvent

WaitCommEvent

関数
通信デバイスで指定したイベントの発生を待機する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL WaitCommEvent(
    HANDLE hFile,
    COMM_EVENT_MASK* lpEvtMask,
    OVERLAPPED* lpOverlapped   // optional
);

パラメーター

名前方向
hFileHANDLEin
lpEvtMaskCOMM_EVENT_MASK*inout
lpOverlappedOVERLAPPED*inoutoptional

戻り値の型: BOOL

各言語での呼び出し定義

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

BOOL WaitCommEvent(
    HANDLE hFile,
    COMM_EVENT_MASK* lpEvtMask,
    OVERLAPPED* lpOverlapped   // optional
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool WaitCommEvent(
    IntPtr hFile,   // HANDLE
    ref uint lpEvtMask,   // COMM_EVENT_MASK* in/out
    IntPtr lpOverlapped   // OVERLAPPED* optional, in/out
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function WaitCommEvent(
    hFile As IntPtr,   ' HANDLE
    ByRef lpEvtMask As UInteger,   ' COMM_EVENT_MASK* in/out
    lpOverlapped As IntPtr   ' OVERLAPPED* optional, in/out
) As Boolean
End Function
' hFile : HANDLE
' lpEvtMask : COMM_EVENT_MASK* in/out
' lpOverlapped : OVERLAPPED* optional, in/out
Declare PtrSafe Function WaitCommEvent Lib "kernel32" ( _
    ByVal hFile As LongPtr, _
    ByRef lpEvtMask As Long, _
    ByVal lpOverlapped As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WaitCommEvent = ctypes.windll.kernel32.WaitCommEvent
WaitCommEvent.restype = wintypes.BOOL
WaitCommEvent.argtypes = [
    wintypes.HANDLE,  # hFile : HANDLE
    ctypes.c_void_p,  # lpEvtMask : COMM_EVENT_MASK* in/out
    ctypes.c_void_p,  # lpOverlapped : OVERLAPPED* optional, in/out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
WaitCommEvent = Fiddle::Function.new(
  lib['WaitCommEvent'],
  [
    Fiddle::TYPE_VOIDP,  # hFile : HANDLE
    Fiddle::TYPE_VOIDP,  # lpEvtMask : COMM_EVENT_MASK* in/out
    Fiddle::TYPE_VOIDP,  # lpOverlapped : OVERLAPPED* optional, in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn WaitCommEvent(
        hFile: *mut core::ffi::c_void,  // HANDLE
        lpEvtMask: *mut u32,  // COMM_EVENT_MASK* in/out
        lpOverlapped: *mut OVERLAPPED  // OVERLAPPED* optional, in/out
    ) -> 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 WaitCommEvent(IntPtr hFile, ref uint lpEvtMask, IntPtr lpOverlapped);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_WaitCommEvent' -Namespace Win32 -PassThru
# $api::WaitCommEvent(hFile, lpEvtMask, lpOverlapped)
#uselib "KERNEL32.dll"
#func global WaitCommEvent "WaitCommEvent" sptr, sptr, sptr
; WaitCommEvent hFile, lpEvtMask, varptr(lpOverlapped)   ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; lpEvtMask : COMM_EVENT_MASK* in/out -> "sptr"
; lpOverlapped : OVERLAPPED* optional, in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global WaitCommEvent "WaitCommEvent" sptr, int, var
; res = WaitCommEvent(hFile, lpEvtMask, lpOverlapped)
; hFile : HANDLE -> "sptr"
; lpEvtMask : COMM_EVENT_MASK* in/out -> "int"
; lpOverlapped : OVERLAPPED* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL WaitCommEvent(HANDLE hFile, COMM_EVENT_MASK* lpEvtMask, OVERLAPPED* lpOverlapped)
#uselib "KERNEL32.dll"
#cfunc global WaitCommEvent "WaitCommEvent" intptr, int, var
; res = WaitCommEvent(hFile, lpEvtMask, lpOverlapped)
; hFile : HANDLE -> "intptr"
; lpEvtMask : COMM_EVENT_MASK* in/out -> "int"
; lpOverlapped : OVERLAPPED* optional, in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procWaitCommEvent = kernel32.NewProc("WaitCommEvent")
)

// hFile (HANDLE), lpEvtMask (COMM_EVENT_MASK* in/out), lpOverlapped (OVERLAPPED* optional, in/out)
r1, _, err := procWaitCommEvent.Call(
	uintptr(hFile),
	uintptr(lpEvtMask),
	uintptr(lpOverlapped),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function WaitCommEvent(
  hFile: THandle;   // HANDLE
  lpEvtMask: Pointer;   // COMM_EVENT_MASK* in/out
  lpOverlapped: Pointer   // OVERLAPPED* optional, in/out
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'WaitCommEvent';
result := DllCall("KERNEL32\WaitCommEvent"
    , "Ptr", hFile   ; HANDLE
    , "Ptr", lpEvtMask   ; COMM_EVENT_MASK* in/out
    , "Ptr", lpOverlapped   ; OVERLAPPED* optional, in/out
    , "Int")   ; return: BOOL
●WaitCommEvent(hFile, lpEvtMask, lpOverlapped) = DLL("KERNEL32.dll", "bool WaitCommEvent(void*, void*, void*)")
# 呼び出し: WaitCommEvent(hFile, lpEvtMask, lpOverlapped)
# hFile : HANDLE -> "void*"
# lpEvtMask : COMM_EVENT_MASK* in/out -> "void*"
# lpOverlapped : OVERLAPPED* optional, in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。