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