ホーム › Devices.Communication › SetCommTimeouts
SetCommTimeouts
関数通信デバイスの送受信タイムアウト設定を構成する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL SetCommTimeouts(
HANDLE hFile,
COMMTIMEOUTS* lpCommTimeouts
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hFile | HANDLE | in |
| lpCommTimeouts | COMMTIMEOUTS* | in |
戻り値の型: BOOL
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL SetCommTimeouts(
HANDLE hFile,
COMMTIMEOUTS* lpCommTimeouts
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool SetCommTimeouts(
IntPtr hFile, // HANDLE
IntPtr lpCommTimeouts // COMMTIMEOUTS*
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function SetCommTimeouts(
hFile As IntPtr, ' HANDLE
lpCommTimeouts As IntPtr ' COMMTIMEOUTS*
) As Boolean
End Function' hFile : HANDLE
' lpCommTimeouts : COMMTIMEOUTS*
Declare PtrSafe Function SetCommTimeouts 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
SetCommTimeouts = ctypes.windll.kernel32.SetCommTimeouts
SetCommTimeouts.restype = wintypes.BOOL
SetCommTimeouts.argtypes = [
wintypes.HANDLE, # hFile : HANDLE
ctypes.c_void_p, # lpCommTimeouts : COMMTIMEOUTS*
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
SetCommTimeouts = Fiddle::Function.new(
lib['SetCommTimeouts'],
[
Fiddle::TYPE_VOIDP, # hFile : HANDLE
Fiddle::TYPE_VOIDP, # lpCommTimeouts : COMMTIMEOUTS*
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn SetCommTimeouts(
hFile: *mut core::ffi::c_void, // HANDLE
lpCommTimeouts: *mut COMMTIMEOUTS // COMMTIMEOUTS*
) -> 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 SetCommTimeouts(IntPtr hFile, IntPtr lpCommTimeouts);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetCommTimeouts' -Namespace Win32 -PassThru
# $api::SetCommTimeouts(hFile, lpCommTimeouts)#uselib "KERNEL32.dll"
#func global SetCommTimeouts "SetCommTimeouts" sptr, sptr
; SetCommTimeouts hFile, varptr(lpCommTimeouts) ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; lpCommTimeouts : COMMTIMEOUTS* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global SetCommTimeouts "SetCommTimeouts" sptr, var ; res = SetCommTimeouts(hFile, lpCommTimeouts) ; hFile : HANDLE -> "sptr" ; lpCommTimeouts : COMMTIMEOUTS* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global SetCommTimeouts "SetCommTimeouts" sptr, sptr ; res = SetCommTimeouts(hFile, varptr(lpCommTimeouts)) ; hFile : HANDLE -> "sptr" ; lpCommTimeouts : COMMTIMEOUTS* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; BOOL SetCommTimeouts(HANDLE hFile, COMMTIMEOUTS* lpCommTimeouts) #uselib "KERNEL32.dll" #cfunc global SetCommTimeouts "SetCommTimeouts" intptr, var ; res = SetCommTimeouts(hFile, lpCommTimeouts) ; hFile : HANDLE -> "intptr" ; lpCommTimeouts : COMMTIMEOUTS* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL SetCommTimeouts(HANDLE hFile, COMMTIMEOUTS* lpCommTimeouts) #uselib "KERNEL32.dll" #cfunc global SetCommTimeouts "SetCommTimeouts" intptr, intptr ; res = SetCommTimeouts(hFile, varptr(lpCommTimeouts)) ; hFile : HANDLE -> "intptr" ; lpCommTimeouts : COMMTIMEOUTS* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procSetCommTimeouts = kernel32.NewProc("SetCommTimeouts")
)
// hFile (HANDLE), lpCommTimeouts (COMMTIMEOUTS*)
r1, _, err := procSetCommTimeouts.Call(
uintptr(hFile),
uintptr(lpCommTimeouts),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction SetCommTimeouts(
hFile: THandle; // HANDLE
lpCommTimeouts: Pointer // COMMTIMEOUTS*
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetCommTimeouts';result := DllCall("KERNEL32\SetCommTimeouts"
, "Ptr", hFile ; HANDLE
, "Ptr", lpCommTimeouts ; COMMTIMEOUTS*
, "Int") ; return: BOOL●SetCommTimeouts(hFile, lpCommTimeouts) = DLL("KERNEL32.dll", "bool SetCommTimeouts(void*, void*)")
# 呼び出し: SetCommTimeouts(hFile, lpCommTimeouts)
# hFile : HANDLE -> "void*"
# lpCommTimeouts : COMMTIMEOUTS* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。