ホーム › Devices.Communication › SetupComm
SetupComm
関数通信デバイスの送受信バッファサイズを設定する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL SetupComm(
HANDLE hFile,
DWORD dwInQueue,
DWORD dwOutQueue
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hFile | HANDLE | in | 対象の通信デバイスを表すハンドル。 |
| dwInQueue | DWORD | in | 受信バッファに推奨するサイズ(バイト単位)。 |
| dwOutQueue | DWORD | in | 送信バッファに推奨するサイズ(バイト単位)。 |
戻り値の型: 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 <MarshalAs(UnmanagedType.Bool)> 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 // BOOLfunction 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)。const std = @import("std");
extern "kernel32" fn SetupComm(
hFile: ?*anyopaque, // HANDLE
dwInQueue: u32, // DWORD
dwOutQueue: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc SetupComm(
hFile: pointer, # HANDLE
dwInQueue: uint32, # DWORD
dwOutQueue: uint32 # DWORD
): int32 {.importc: "SetupComm", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int SetupComm(
void* hFile, // HANDLE
uint dwInQueue, // DWORD
uint dwOutQueue // DWORD
);ccall((:SetupComm, "KERNEL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, UInt32, UInt32),
hFile, dwInQueue, dwOutQueue)
# hFile : HANDLE -> Ptr{Cvoid}
# dwInQueue : DWORD -> UInt32
# dwOutQueue : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetupComm(
void* hFile,
uint32_t dwInQueue,
uint32_t dwOutQueue);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.SetupComm(hFile, dwInQueue, dwOutQueue)
-- hFile : HANDLE
-- dwInQueue : DWORD
-- dwOutQueue : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const SetupComm = lib.func('__stdcall', 'SetupComm', 'int32_t', ['void *', 'uint32_t', 'uint32_t']);
// SetupComm(hFile, dwInQueue, dwOutQueue)
// hFile : HANDLE -> 'void *'
// dwInQueue : DWORD -> 'uint32_t'
// dwOutQueue : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
SetupComm: { parameters: ["pointer", "u32", "u32"], result: "i32" },
});
// lib.symbols.SetupComm(hFile, dwInQueue, dwOutQueue)
// hFile : HANDLE -> "pointer"
// dwInQueue : DWORD -> "u32"
// dwOutQueue : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetupComm(
void* hFile,
uint32_t dwInQueue,
uint32_t dwOutQueue);
C, "KERNEL32.dll");
// $ffi->SetupComm(hFile, dwInQueue, dwOutQueue);
// hFile : HANDLE
// dwInQueue : DWORD
// dwOutQueue : DWORD
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
boolean SetupComm(
Pointer hFile, // HANDLE
int dwInQueue, // DWORD
int dwOutQueue // DWORD
);
}@[Link("kernel32")]
lib LibKERNEL32
fun SetupComm = SetupComm(
hFile : Void*, # HANDLE
dwInQueue : UInt32, # DWORD
dwOutQueue : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetupCommNative = Int32 Function(Pointer<Void>, Uint32, Uint32);
typedef SetupCommDart = int Function(Pointer<Void>, int, int);
final SetupComm = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<SetupCommNative, SetupCommDart>('SetupComm');
// hFile : HANDLE -> Pointer<Void>
// dwInQueue : DWORD -> Uint32
// dwOutQueue : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetupComm(
hFile: THandle; // HANDLE
dwInQueue: DWORD; // DWORD
dwOutQueue: DWORD // DWORD
): BOOL; stdcall;
external 'KERNEL32.dll' name 'SetupComm';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetupComm"
c_SetupComm :: Ptr () -> Word32 -> Word32 -> IO CInt
-- hFile : HANDLE -> Ptr ()
-- dwInQueue : DWORD -> Word32
-- dwOutQueue : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setupcomm =
foreign "SetupComm"
((ptr void) @-> uint32_t @-> uint32_t @-> returning int32_t)
(* hFile : HANDLE -> (ptr void) *)
(* dwInQueue : DWORD -> uint32_t *)
(* dwOutQueue : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("SetupComm" setup-comm :convention :stdcall) :int32
(h-file :pointer) ; HANDLE
(dw-in-queue :uint32) ; DWORD
(dw-out-queue :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetupComm = Win32::API::More->new('KERNEL32',
'BOOL SetupComm(HANDLE hFile, DWORD dwInQueue, DWORD dwOutQueue)');
# my $ret = $SetupComm->Call($hFile, $dwInQueue, $dwOutQueue);
# hFile : HANDLE -> HANDLE
# dwInQueue : DWORD -> DWORD
# dwOutQueue : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。