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

COMMCONFIG

構造体
サイズx64: 52 バイト / x86: 52 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
dwSizeDWORD4+0+0この構造体のバイト単位サイズ。使用前に設定する必要がある。
wVersionWORD2+4+4構造体のバージョン番号を示す。
wReservedWORD2+6+6予約フィールド。0を設定する。
dcbDCB28+8+8シリアルポート設定を保持するDCB構造体。
dwProviderSubTypeDWORD4+36+36通信プロバイダのサブタイプを示す。
dwProviderOffsetDWORD4+40+40プロバイダ固有データへの構造体先頭からのオフセットを示す。
dwProviderSizeDWORD4+44+44プロバイダ固有データのバイト単位サイズを示す。
wcProviderDataWCHAR2+48+48プロバイダ固有の可変長データ部の先頭文字。

各言語での定義

#include <windows.h>

// DCB  (x64 28 / x86 28 バイト)
typedef struct DCB {
    DWORD DCBlength;
    DWORD BaudRate;
    DWORD _bitfield;
    WORD wReserved;
    WORD XonLim;
    WORD XoffLim;
    BYTE ByteSize;
    DCB_PARITY Parity;
    DCB_STOP_BITS StopBits;
    CHAR XonChar;
    CHAR XoffChar;
    CHAR ErrorChar;
    CHAR EofChar;
    CHAR EvtChar;
    WORD wReserved1;
} DCB;

// COMMCONFIG  (x64 52 / x86 52 バイト)
typedef struct COMMCONFIG {
    DWORD dwSize;
    WORD wVersion;
    WORD wReserved;
    DCB dcb;
    DWORD dwProviderSubType;
    DWORD dwProviderOffset;
    DWORD dwProviderSize;
    WCHAR wcProviderData[1];
} COMMCONFIG;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct DCB
{
    public uint DCBlength;
    public uint BaudRate;
    public uint _bitfield;
    public ushort wReserved;
    public ushort XonLim;
    public ushort XoffLim;
    public byte ByteSize;
    public byte Parity;
    public byte StopBits;
    public sbyte XonChar;
    public sbyte XoffChar;
    public sbyte ErrorChar;
    public sbyte EofChar;
    public sbyte EvtChar;
    public ushort wReserved1;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct COMMCONFIG
{
    public uint dwSize;
    public ushort wVersion;
    public ushort wReserved;
    public DCB dcb;
    public uint dwProviderSubType;
    public uint dwProviderOffset;
    public uint dwProviderSize;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)] public string wcProviderData;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure DCB
    Public DCBlength As UInteger
    Public BaudRate As UInteger
    Public _bitfield As UInteger
    Public wReserved As UShort
    Public XonLim As UShort
    Public XoffLim As UShort
    Public ByteSize As Byte
    Public Parity As Byte
    Public StopBits As Byte
    Public XonChar As SByte
    Public XoffChar As SByte
    Public ErrorChar As SByte
    Public EofChar As SByte
    Public EvtChar As SByte
    Public wReserved1 As UShort
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure COMMCONFIG
    Public dwSize As UInteger
    Public wVersion As UShort
    Public wReserved As UShort
    Public dcb As DCB
    Public dwProviderSubType As UInteger
    Public dwProviderOffset As UInteger
    Public dwProviderSize As UInteger
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=1)> Public wcProviderData As String
End Structure
import ctypes
from ctypes import wintypes

class DCB(ctypes.Structure):
    _fields_ = [
        ("DCBlength", wintypes.DWORD),
        ("BaudRate", wintypes.DWORD),
        ("_bitfield", wintypes.DWORD),
        ("wReserved", ctypes.c_ushort),
        ("XonLim", ctypes.c_ushort),
        ("XoffLim", ctypes.c_ushort),
        ("ByteSize", ctypes.c_ubyte),
        ("Parity", ctypes.c_ubyte),
        ("StopBits", ctypes.c_ubyte),
        ("XonChar", ctypes.c_byte),
        ("XoffChar", ctypes.c_byte),
        ("ErrorChar", ctypes.c_byte),
        ("EofChar", ctypes.c_byte),
        ("EvtChar", ctypes.c_byte),
        ("wReserved1", ctypes.c_ushort),
    ]

class COMMCONFIG(ctypes.Structure):
    _fields_ = [
        ("dwSize", wintypes.DWORD),
        ("wVersion", ctypes.c_ushort),
        ("wReserved", ctypes.c_ushort),
        ("dcb", DCB),
        ("dwProviderSubType", wintypes.DWORD),
        ("dwProviderOffset", wintypes.DWORD),
        ("dwProviderSize", wintypes.DWORD),
        ("wcProviderData", ctypes.c_wchar * 1),
    ]
#[repr(C)]
pub struct DCB {
    pub DCBlength: u32,
    pub BaudRate: u32,
    pub _bitfield: u32,
    pub wReserved: u16,
    pub XonLim: u16,
    pub XoffLim: u16,
    pub ByteSize: u8,
    pub Parity: u8,
    pub StopBits: u8,
    pub XonChar: i8,
    pub XoffChar: i8,
    pub ErrorChar: i8,
    pub EofChar: i8,
    pub EvtChar: i8,
    pub wReserved1: u16,
}

#[repr(C)]
pub struct COMMCONFIG {
    pub dwSize: u32,
    pub wVersion: u16,
    pub wReserved: u16,
    pub dcb: DCB,
    pub dwProviderSubType: u32,
    pub dwProviderOffset: u32,
    pub dwProviderSize: u32,
    pub wcProviderData: [u16; 1],
}
import "golang.org/x/sys/windows"

type DCB struct {
	DCBlength uint32
	BaudRate uint32
	_bitfield uint32
	wReserved uint16
	XonLim uint16
	XoffLim uint16
	ByteSize byte
	Parity byte
	StopBits byte
	XonChar int8
	XoffChar int8
	ErrorChar int8
	EofChar int8
	EvtChar int8
	wReserved1 uint16
}

type COMMCONFIG struct {
	dwSize uint32
	wVersion uint16
	wReserved uint16
	dcb DCB
	dwProviderSubType uint32
	dwProviderOffset uint32
	dwProviderSize uint32
	wcProviderData [1]uint16
}
type
  DCB = record
    DCBlength: DWORD;
    BaudRate: DWORD;
    _bitfield: DWORD;
    wReserved: Word;
    XonLim: Word;
    XoffLim: Word;
    ByteSize: Byte;
    Parity: Byte;
    StopBits: Byte;
    XonChar: Shortint;
    XoffChar: Shortint;
    ErrorChar: Shortint;
    EofChar: Shortint;
    EvtChar: Shortint;
    wReserved1: Word;
  end;

  COMMCONFIG = record
    dwSize: DWORD;
    wVersion: Word;
    wReserved: Word;
    dcb: DCB;
    dwProviderSubType: DWORD;
    dwProviderOffset: DWORD;
    dwProviderSize: DWORD;
    wcProviderData: array[0..0] of WideChar;
  end;
const DCB = extern struct {
    DCBlength: u32,
    BaudRate: u32,
    _bitfield: u32,
    wReserved: u16,
    XonLim: u16,
    XoffLim: u16,
    ByteSize: u8,
    Parity: u8,
    StopBits: u8,
    XonChar: i8,
    XoffChar: i8,
    ErrorChar: i8,
    EofChar: i8,
    EvtChar: i8,
    wReserved1: u16,
};

const COMMCONFIG = extern struct {
    dwSize: u32,
    wVersion: u16,
    wReserved: u16,
    dcb: DCB,
    dwProviderSubType: u32,
    dwProviderOffset: u32,
    dwProviderSize: u32,
    wcProviderData: [1]u16,
};
type
  DCB {.bycopy.} = object
    DCBlength: uint32
    BaudRate: uint32
    _bitfield: uint32
    wReserved: uint16
    XonLim: uint16
    XoffLim: uint16
    ByteSize: uint8
    Parity: uint8
    StopBits: uint8
    XonChar: int8
    XoffChar: int8
    ErrorChar: int8
    EofChar: int8
    EvtChar: int8
    wReserved1: uint16

  COMMCONFIG {.bycopy.} = object
    dwSize: uint32
    wVersion: uint16
    wReserved: uint16
    dcb: DCB
    dwProviderSubType: uint32
    dwProviderOffset: uint32
    dwProviderSize: uint32
    wcProviderData: array[1, uint16]
struct DCB
{
    uint DCBlength;
    uint BaudRate;
    uint _bitfield;
    ushort wReserved;
    ushort XonLim;
    ushort XoffLim;
    ubyte ByteSize;
    ubyte Parity;
    ubyte StopBits;
    byte XonChar;
    byte XoffChar;
    byte ErrorChar;
    byte EofChar;
    byte EvtChar;
    ushort wReserved1;
}

struct COMMCONFIG
{
    uint dwSize;
    ushort wVersion;
    ushort wReserved;
    DCB dcb;
    uint dwProviderSubType;
    uint dwProviderOffset;
    uint dwProviderSize;
    wchar[1] wcProviderData;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; COMMCONFIG サイズ: 52 バイト(x64)
dim st, 13    ; 4byte整数×13(構造体サイズ 52 / 4 切り上げ)
; dwSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; wVersion : WORD (+4, 2byte)  wpoke st,4,値  /  値 = wpeek(st,4)
; wReserved : WORD (+6, 2byte)  wpoke st,6,値  /  値 = wpeek(st,6)
; dcb : DCB (+8, 28byte)  varptr(st)+8 を基点に操作(28byte:入れ子/配列)
; dwProviderSubType : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; dwProviderOffset : DWORD (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; dwProviderSize : DWORD (+44, 4byte)  st.11 = 値  /  値 = st.11   (lpoke/lpeek も可)
; wcProviderData : WCHAR (+48, 2byte)  varptr(st)+48 を基点に操作(2byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global DCB
    #field int DCBlength
    #field int BaudRate
    #field int _bitfield
    #field short wReserved
    #field short XonLim
    #field short XoffLim
    #field byte ByteSize
    #field byte Parity
    #field byte StopBits
    #field byte XonChar
    #field byte XoffChar
    #field byte ErrorChar
    #field byte EofChar
    #field byte EvtChar
    #field short wReserved1
#endstruct

#defstruct global COMMCONFIG
    #field int dwSize
    #field short wVersion
    #field short wReserved
    #field DCB dcb
    #field int dwProviderSubType
    #field int dwProviderOffset
    #field int dwProviderSize
    #field wchar wcProviderData 1
#endstruct

stdim st, COMMCONFIG        ; NSTRUCT 変数を確保
st->dwSize = 100
mes "dwSize=" + st->dwSize