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

USB_CONFIGURATION_DESCRIPTOR

構造体
サイズx64: 9 バイト / x86: 9 バイトパッキング1

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

フィールド

フィールドサイズx64x86説明
bLengthBYTE1+0+0このディスクリプタのサイズをバイト単位で示す。通常9。
bDescriptorTypeBYTE1+1+1ディスクリプタ種別。コンフィギュレーションは0x02。
wTotalLengthWORD2+2+2このコンフィギュレーションで返される全データの合計長を示す。
bNumInterfacesBYTE1+4+4このコンフィギュレーションが持つインターフェイス数を示す。
bConfigurationValueBYTE1+5+5SET_CONFIGURATIONで選択するための値を示す。
iConfigurationBYTE1+6+6コンフィギュレーション名文字列ディスクリプタのインデックス。
bmAttributesBYTE1+7+7セルフパワー・リモートウェイクアップ等の属性ビットを示す。
MaxPowerBYTE1+8+8バスから消費する最大電力を2mA単位で示す。

各言語での定義

#include <windows.h>

// USB_CONFIGURATION_DESCRIPTOR  (x64 9 / x86 9 バイト)
#pragma pack(push, 1)
typedef struct USB_CONFIGURATION_DESCRIPTOR {
    BYTE bLength;
    BYTE bDescriptorType;
    WORD wTotalLength;
    BYTE bNumInterfaces;
    BYTE bConfigurationValue;
    BYTE iConfiguration;
    BYTE bmAttributes;
    BYTE MaxPower;
} USB_CONFIGURATION_DESCRIPTOR;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_CONFIGURATION_DESCRIPTOR
{
    public byte bLength;
    public byte bDescriptorType;
    public ushort wTotalLength;
    public byte bNumInterfaces;
    public byte bConfigurationValue;
    public byte iConfiguration;
    public byte bmAttributes;
    public byte MaxPower;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_CONFIGURATION_DESCRIPTOR
    Public bLength As Byte
    Public bDescriptorType As Byte
    Public wTotalLength As UShort
    Public bNumInterfaces As Byte
    Public bConfigurationValue As Byte
    Public iConfiguration As Byte
    Public bmAttributes As Byte
    Public MaxPower As Byte
End Structure
import ctypes
from ctypes import wintypes

class USB_CONFIGURATION_DESCRIPTOR(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("bLength", ctypes.c_ubyte),
        ("bDescriptorType", ctypes.c_ubyte),
        ("wTotalLength", ctypes.c_ushort),
        ("bNumInterfaces", ctypes.c_ubyte),
        ("bConfigurationValue", ctypes.c_ubyte),
        ("iConfiguration", ctypes.c_ubyte),
        ("bmAttributes", ctypes.c_ubyte),
        ("MaxPower", ctypes.c_ubyte),
    ]
#[repr(C, packed(1))]
pub struct USB_CONFIGURATION_DESCRIPTOR {
    pub bLength: u8,
    pub bDescriptorType: u8,
    pub wTotalLength: u16,
    pub bNumInterfaces: u8,
    pub bConfigurationValue: u8,
    pub iConfiguration: u8,
    pub bmAttributes: u8,
    pub MaxPower: u8,
}
import "golang.org/x/sys/windows"

type USB_CONFIGURATION_DESCRIPTOR struct {
	bLength byte
	bDescriptorType byte
	wTotalLength uint16
	bNumInterfaces byte
	bConfigurationValue byte
	iConfiguration byte
	bmAttributes byte
	MaxPower byte
}
type
  USB_CONFIGURATION_DESCRIPTOR = packed record
    bLength: Byte;
    bDescriptorType: Byte;
    wTotalLength: Word;
    bNumInterfaces: Byte;
    bConfigurationValue: Byte;
    iConfiguration: Byte;
    bmAttributes: Byte;
    MaxPower: Byte;
  end;
const USB_CONFIGURATION_DESCRIPTOR = extern struct {
    bLength: u8,
    bDescriptorType: u8,
    wTotalLength: u16,
    bNumInterfaces: u8,
    bConfigurationValue: u8,
    iConfiguration: u8,
    bmAttributes: u8,
    MaxPower: u8,
};
type
  USB_CONFIGURATION_DESCRIPTOR {.packed.} = object
    bLength: uint8
    bDescriptorType: uint8
    wTotalLength: uint16
    bNumInterfaces: uint8
    bConfigurationValue: uint8
    iConfiguration: uint8
    bmAttributes: uint8
    MaxPower: uint8
align(1)
struct USB_CONFIGURATION_DESCRIPTOR
{
    ubyte bLength;
    ubyte bDescriptorType;
    ushort wTotalLength;
    ubyte bNumInterfaces;
    ubyte bConfigurationValue;
    ubyte iConfiguration;
    ubyte bmAttributes;
    ubyte MaxPower;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; USB_CONFIGURATION_DESCRIPTOR サイズ: 9 バイト(x64)
dim st, 3    ; 4byte整数×3(構造体サイズ 9 / 4 切り上げ)
; bLength : BYTE (+0, 1byte)  poke st,0,値  /  値 = peek(st,0)
; bDescriptorType : BYTE (+1, 1byte)  poke st,1,値  /  値 = peek(st,1)
; wTotalLength : WORD (+2, 2byte)  wpoke st,2,値  /  値 = wpeek(st,2)
; bNumInterfaces : BYTE (+4, 1byte)  poke st,4,値  /  値 = peek(st,4)
; bConfigurationValue : BYTE (+5, 1byte)  poke st,5,値  /  値 = peek(st,5)
; iConfiguration : BYTE (+6, 1byte)  poke st,6,値  /  値 = peek(st,6)
; bmAttributes : BYTE (+7, 1byte)  poke st,7,値  /  値 = peek(st,7)
; MaxPower : BYTE (+8, 1byte)  poke st,8,値  /  値 = peek(st,8)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global USB_CONFIGURATION_DESCRIPTOR, pack=1
    #field byte bLength
    #field byte bDescriptorType
    #field short wTotalLength
    #field byte bNumInterfaces
    #field byte bConfigurationValue
    #field byte iConfiguration
    #field byte bmAttributes
    #field byte MaxPower
#endstruct

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