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

GetCommTimeouts

関数
通信デバイスの送受信タイムアウト設定を取得する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL GetCommTimeouts(
    HANDLE hFile,
    COMMTIMEOUTS* lpCommTimeouts
);

パラメーター

名前方向
hFileHANDLEin
lpCommTimeoutsCOMMTIMEOUTS*out

戻り値の型: BOOL

各言語での呼び出し定義

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

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

GetCommTimeouts = ctypes.windll.kernel32.GetCommTimeouts
GetCommTimeouts.restype = wintypes.BOOL
GetCommTimeouts.argtypes = [
    wintypes.HANDLE,  # hFile : HANDLE
    ctypes.c_void_p,  # lpCommTimeouts : COMMTIMEOUTS* out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

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

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procGetCommTimeouts = kernel32.NewProc("GetCommTimeouts")
)

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