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

SetupComm

関数
通信デバイスの送受信バッファサイズを設定する。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows XP 以降

シグネチャ

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

BOOL SetupComm(
    HANDLE hFile,
    DWORD dwInQueue,
    DWORD dwOutQueue
);

パラメーター

名前方向
hFileHANDLEin
dwInQueueDWORDin
dwOutQueueDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

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

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

SetupComm = ctypes.windll.kernel32.SetupComm
SetupComm.restype = wintypes.BOOL
SetupComm.argtypes = [
    wintypes.HANDLE,  # hFile : HANDLE
    wintypes.DWORD,  # dwInQueue : DWORD
    wintypes.DWORD,  # dwOutQueue : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
SetupComm = Fiddle::Function.new(
  lib['SetupComm'],
  [
    Fiddle::TYPE_VOIDP,  # hFile : HANDLE
    -Fiddle::TYPE_INT,  # dwInQueue : DWORD
    -Fiddle::TYPE_INT,  # dwOutQueue : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn SetupComm(
        hFile: *mut core::ffi::c_void,  // HANDLE
        dwInQueue: u32,  // DWORD
        dwOutQueue: u32  // DWORD
    ) -> 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 SetupComm(IntPtr hFile, uint dwInQueue, uint dwOutQueue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_SetupComm' -Namespace Win32 -PassThru
# $api::SetupComm(hFile, dwInQueue, dwOutQueue)
#uselib "KERNEL32.dll"
#func global SetupComm "SetupComm" sptr, sptr, sptr
; SetupComm hFile, dwInQueue, dwOutQueue   ; 戻り値は stat
; hFile : HANDLE -> "sptr"
; dwInQueue : DWORD -> "sptr"
; dwOutQueue : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "KERNEL32.dll"
#cfunc global SetupComm "SetupComm" sptr, int, int
; res = SetupComm(hFile, dwInQueue, dwOutQueue)
; hFile : HANDLE -> "sptr"
; dwInQueue : DWORD -> "int"
; dwOutQueue : DWORD -> "int"
; BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)
#uselib "KERNEL32.dll"
#cfunc global SetupComm "SetupComm" intptr, int, int
; res = SetupComm(hFile, dwInQueue, dwOutQueue)
; hFile : HANDLE -> "intptr"
; dwInQueue : DWORD -> "int"
; dwOutQueue : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procSetupComm = kernel32.NewProc("SetupComm")
)

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