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

COMMCONFIG

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

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

フィールド

フィールドサイズx64x86説明
dwSizeDWORD4+0+0構造体のサイズ (バイト単位)。呼び出し元はこのメンバーに sizeof(COMMCONFIG) を設定しなければなりません。
wVersionWORD2+4+4構造体のバージョン番号。このパラメーターには 1 を指定できます。プロバイダー固有の構造体のバージョンは wcProviderData メンバーに含める必要があります。
wReservedWORD2+6+6予約済みです。使用しないでください。
dcbDCB28+8+8RS-232 シリアルデバイス用のデバイス制御ブロック (DCB) 構造体。 DCB 構造体は、デバイスの COMMPROP 構造体で指定されたポートドライバーのサブタイプに関係なく、常に存在します。
dwProviderSubTypeDWORD4+36+36通信プロバイダーの種類、およびそれに応じたプロバイダー固有データの形式。通信プロバイダーの種類の一覧については、 COMMPROP 構造体の説明を参照してください。
dwProviderOffsetDWORD4+40+40構造体の先頭を基準とした、プロバイダー固有データのオフセット (バイト単位)。プロバイダー固有データが存在しない場合、このメンバーは 0 です。
dwProviderSizeDWORD4+44+44プロバイダー固有データのサイズ (バイト単位)。
wcProviderDataWCHAR2+48+48省略可能なプロバイダー固有データ。このメンバーは任意のサイズにでき、省略することもできます。 COMMCONFIG 構造体は将来拡張される可能性があるため、アプリケーションはこのメンバーの位置を判断するために dwProviderOffset メンバーを使用してください。

公式ドキュメント

通信デバイスの構成状態に関する情報を格納します。

解説(Remarks)

プロバイダーのサブタイプが PST_RS232 または PST_PARALLELPORT の場合、wcProviderData メンバーは省略されます。プロバイダーのサブタイプが PST_MODEM の場合、wcProviderData メンバーには MODEMSETTINGS 構造体が格納されます。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#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