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

USB_COMPOSITE_DEVICE_INFO

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

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

フィールド

フィールドサイズx64x86説明
DeviceDescriptorUSB_DEVICE_DESCRIPTOR18+0+0複合デバイスのUSBデバイス記述子。
CurrentConfigDescriptorUSB_CONFIGURATION_DESCRIPTOR9+18+18現在のコンフィギュレーション記述子。
CurrentConfigurationValueBYTE1+27+27現在選択中のコンフィギュレーション値。
NumberOfFunctionsBYTE1+28+28複合デバイスを構成するファンクション数。
FunctionInfoUSB_COMPOSITE_FUNCTION_INFO4+29+29各ファンクション情報を格納する可変長配列の先頭。

各言語での定義

#include <windows.h>

// USB_DEVICE_DESCRIPTOR  (x64 18 / x86 18 バイト)
#pragma pack(push, 1)
typedef struct USB_DEVICE_DESCRIPTOR {
    BYTE bLength;
    BYTE bDescriptorType;
    WORD bcdUSB;
    BYTE bDeviceClass;
    BYTE bDeviceSubClass;
    BYTE bDeviceProtocol;
    BYTE bMaxPacketSize0;
    WORD idVendor;
    WORD idProduct;
    WORD bcdDevice;
    BYTE iManufacturer;
    BYTE iProduct;
    BYTE iSerialNumber;
    BYTE bNumConfigurations;
} USB_DEVICE_DESCRIPTOR;
#pragma pack(pop)

// 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)

// USB_COMPOSITE_FUNCTION_INFO  (x64 4 / x86 4 バイト)
typedef struct USB_COMPOSITE_FUNCTION_INFO {
    BYTE FunctionNumber;
    BYTE BaseInterfaceNumber;
    BYTE NumberOfInterfaces;
    BOOLEAN FunctionIsIdle;
} USB_COMPOSITE_FUNCTION_INFO;

// USB_COMPOSITE_DEVICE_INFO  (x64 33 / x86 33 バイト)
typedef struct USB_COMPOSITE_DEVICE_INFO {
    USB_DEVICE_DESCRIPTOR DeviceDescriptor;
    USB_CONFIGURATION_DESCRIPTOR CurrentConfigDescriptor;
    BYTE CurrentConfigurationValue;
    BYTE NumberOfFunctions;
    USB_COMPOSITE_FUNCTION_INFO FunctionInfo[1];
} USB_COMPOSITE_DEVICE_INFO;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_DEVICE_DESCRIPTOR
{
    public byte bLength;
    public byte bDescriptorType;
    public ushort bcdUSB;
    public byte bDeviceClass;
    public byte bDeviceSubClass;
    public byte bDeviceProtocol;
    public byte bMaxPacketSize0;
    public ushort idVendor;
    public ushort idProduct;
    public ushort bcdDevice;
    public byte iManufacturer;
    public byte iProduct;
    public byte iSerialNumber;
    public byte bNumConfigurations;
}

[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;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USB_COMPOSITE_FUNCTION_INFO
{
    public byte FunctionNumber;
    public byte BaseInterfaceNumber;
    public byte NumberOfInterfaces;
    [MarshalAs(UnmanagedType.U1)] public bool FunctionIsIdle;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USB_COMPOSITE_DEVICE_INFO
{
    public USB_DEVICE_DESCRIPTOR DeviceDescriptor;
    public USB_CONFIGURATION_DESCRIPTOR CurrentConfigDescriptor;
    public byte CurrentConfigurationValue;
    public byte NumberOfFunctions;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public USB_COMPOSITE_FUNCTION_INFO[] FunctionInfo;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_DEVICE_DESCRIPTOR
    Public bLength As Byte
    Public bDescriptorType As Byte
    Public bcdUSB As UShort
    Public bDeviceClass As Byte
    Public bDeviceSubClass As Byte
    Public bDeviceProtocol As Byte
    Public bMaxPacketSize0 As Byte
    Public idVendor As UShort
    Public idProduct As UShort
    Public bcdDevice As UShort
    Public iManufacturer As Byte
    Public iProduct As Byte
    Public iSerialNumber As Byte
    Public bNumConfigurations As Byte
End Structure

<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

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure USB_COMPOSITE_FUNCTION_INFO
    Public FunctionNumber As Byte
    Public BaseInterfaceNumber As Byte
    Public NumberOfInterfaces As Byte
    <MarshalAs(UnmanagedType.U1)> Public FunctionIsIdle As Boolean
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure USB_COMPOSITE_DEVICE_INFO
    Public DeviceDescriptor As USB_DEVICE_DESCRIPTOR
    Public CurrentConfigDescriptor As USB_CONFIGURATION_DESCRIPTOR
    Public CurrentConfigurationValue As Byte
    Public NumberOfFunctions As Byte
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public FunctionInfo() As USB_COMPOSITE_FUNCTION_INFO
End Structure
import ctypes
from ctypes import wintypes

class USB_DEVICE_DESCRIPTOR(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("bLength", ctypes.c_ubyte),
        ("bDescriptorType", ctypes.c_ubyte),
        ("bcdUSB", ctypes.c_ushort),
        ("bDeviceClass", ctypes.c_ubyte),
        ("bDeviceSubClass", ctypes.c_ubyte),
        ("bDeviceProtocol", ctypes.c_ubyte),
        ("bMaxPacketSize0", ctypes.c_ubyte),
        ("idVendor", ctypes.c_ushort),
        ("idProduct", ctypes.c_ushort),
        ("bcdDevice", ctypes.c_ushort),
        ("iManufacturer", ctypes.c_ubyte),
        ("iProduct", ctypes.c_ubyte),
        ("iSerialNumber", ctypes.c_ubyte),
        ("bNumConfigurations", ctypes.c_ubyte),
    ]

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),
    ]

class USB_COMPOSITE_FUNCTION_INFO(ctypes.Structure):
    _fields_ = [
        ("FunctionNumber", ctypes.c_ubyte),
        ("BaseInterfaceNumber", ctypes.c_ubyte),
        ("NumberOfInterfaces", ctypes.c_ubyte),
        ("FunctionIsIdle", ctypes.c_byte),
    ]

class USB_COMPOSITE_DEVICE_INFO(ctypes.Structure):
    _fields_ = [
        ("DeviceDescriptor", USB_DEVICE_DESCRIPTOR),
        ("CurrentConfigDescriptor", USB_CONFIGURATION_DESCRIPTOR),
        ("CurrentConfigurationValue", ctypes.c_ubyte),
        ("NumberOfFunctions", ctypes.c_ubyte),
        ("FunctionInfo", USB_COMPOSITE_FUNCTION_INFO * 1),
    ]
#[repr(C, packed(1))]
pub struct USB_DEVICE_DESCRIPTOR {
    pub bLength: u8,
    pub bDescriptorType: u8,
    pub bcdUSB: u16,
    pub bDeviceClass: u8,
    pub bDeviceSubClass: u8,
    pub bDeviceProtocol: u8,
    pub bMaxPacketSize0: u8,
    pub idVendor: u16,
    pub idProduct: u16,
    pub bcdDevice: u16,
    pub iManufacturer: u8,
    pub iProduct: u8,
    pub iSerialNumber: u8,
    pub bNumConfigurations: u8,
}

#[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,
}

#[repr(C)]
pub struct USB_COMPOSITE_FUNCTION_INFO {
    pub FunctionNumber: u8,
    pub BaseInterfaceNumber: u8,
    pub NumberOfInterfaces: u8,
    pub FunctionIsIdle: u8,
}

#[repr(C)]
pub struct USB_COMPOSITE_DEVICE_INFO {
    pub DeviceDescriptor: USB_DEVICE_DESCRIPTOR,
    pub CurrentConfigDescriptor: USB_CONFIGURATION_DESCRIPTOR,
    pub CurrentConfigurationValue: u8,
    pub NumberOfFunctions: u8,
    pub FunctionInfo: [USB_COMPOSITE_FUNCTION_INFO; 1],
}
import "golang.org/x/sys/windows"

type USB_DEVICE_DESCRIPTOR struct {
	bLength byte
	bDescriptorType byte
	bcdUSB uint16
	bDeviceClass byte
	bDeviceSubClass byte
	bDeviceProtocol byte
	bMaxPacketSize0 byte
	idVendor uint16
	idProduct uint16
	bcdDevice uint16
	iManufacturer byte
	iProduct byte
	iSerialNumber byte
	bNumConfigurations byte
}

type USB_CONFIGURATION_DESCRIPTOR struct {
	bLength byte
	bDescriptorType byte
	wTotalLength uint16
	bNumInterfaces byte
	bConfigurationValue byte
	iConfiguration byte
	bmAttributes byte
	MaxPower byte
}

type USB_COMPOSITE_FUNCTION_INFO struct {
	FunctionNumber byte
	BaseInterfaceNumber byte
	NumberOfInterfaces byte
	FunctionIsIdle byte
}

type USB_COMPOSITE_DEVICE_INFO struct {
	DeviceDescriptor USB_DEVICE_DESCRIPTOR
	CurrentConfigDescriptor USB_CONFIGURATION_DESCRIPTOR
	CurrentConfigurationValue byte
	NumberOfFunctions byte
	FunctionInfo [1]USB_COMPOSITE_FUNCTION_INFO
}
type
  USB_DEVICE_DESCRIPTOR = packed record
    bLength: Byte;
    bDescriptorType: Byte;
    bcdUSB: Word;
    bDeviceClass: Byte;
    bDeviceSubClass: Byte;
    bDeviceProtocol: Byte;
    bMaxPacketSize0: Byte;
    idVendor: Word;
    idProduct: Word;
    bcdDevice: Word;
    iManufacturer: Byte;
    iProduct: Byte;
    iSerialNumber: Byte;
    bNumConfigurations: Byte;
  end;

  USB_CONFIGURATION_DESCRIPTOR = packed record
    bLength: Byte;
    bDescriptorType: Byte;
    wTotalLength: Word;
    bNumInterfaces: Byte;
    bConfigurationValue: Byte;
    iConfiguration: Byte;
    bmAttributes: Byte;
    MaxPower: Byte;
  end;

  USB_COMPOSITE_FUNCTION_INFO = record
    FunctionNumber: Byte;
    BaseInterfaceNumber: Byte;
    NumberOfInterfaces: Byte;
    FunctionIsIdle: ByteBool;
  end;

  USB_COMPOSITE_DEVICE_INFO = record
    DeviceDescriptor: USB_DEVICE_DESCRIPTOR;
    CurrentConfigDescriptor: USB_CONFIGURATION_DESCRIPTOR;
    CurrentConfigurationValue: Byte;
    NumberOfFunctions: Byte;
    FunctionInfo: array[0..0] of USB_COMPOSITE_FUNCTION_INFO;
  end;
const USB_DEVICE_DESCRIPTOR = extern struct {
    bLength: u8,
    bDescriptorType: u8,
    bcdUSB: u16,
    bDeviceClass: u8,
    bDeviceSubClass: u8,
    bDeviceProtocol: u8,
    bMaxPacketSize0: u8,
    idVendor: u16,
    idProduct: u16,
    bcdDevice: u16,
    iManufacturer: u8,
    iProduct: u8,
    iSerialNumber: u8,
    bNumConfigurations: u8,
};

const USB_CONFIGURATION_DESCRIPTOR = extern struct {
    bLength: u8,
    bDescriptorType: u8,
    wTotalLength: u16,
    bNumInterfaces: u8,
    bConfigurationValue: u8,
    iConfiguration: u8,
    bmAttributes: u8,
    MaxPower: u8,
};

const USB_COMPOSITE_FUNCTION_INFO = extern struct {
    FunctionNumber: u8,
    BaseInterfaceNumber: u8,
    NumberOfInterfaces: u8,
    FunctionIsIdle: u8,
};

const USB_COMPOSITE_DEVICE_INFO = extern struct {
    DeviceDescriptor: USB_DEVICE_DESCRIPTOR,
    CurrentConfigDescriptor: USB_CONFIGURATION_DESCRIPTOR,
    CurrentConfigurationValue: u8,
    NumberOfFunctions: u8,
    FunctionInfo: [1]USB_COMPOSITE_FUNCTION_INFO,
};
type
  USB_DEVICE_DESCRIPTOR {.packed.} = object
    bLength: uint8
    bDescriptorType: uint8
    bcdUSB: uint16
    bDeviceClass: uint8
    bDeviceSubClass: uint8
    bDeviceProtocol: uint8
    bMaxPacketSize0: uint8
    idVendor: uint16
    idProduct: uint16
    bcdDevice: uint16
    iManufacturer: uint8
    iProduct: uint8
    iSerialNumber: uint8
    bNumConfigurations: uint8

  USB_CONFIGURATION_DESCRIPTOR {.packed.} = object
    bLength: uint8
    bDescriptorType: uint8
    wTotalLength: uint16
    bNumInterfaces: uint8
    bConfigurationValue: uint8
    iConfiguration: uint8
    bmAttributes: uint8
    MaxPower: uint8

  USB_COMPOSITE_FUNCTION_INFO {.bycopy.} = object
    FunctionNumber: uint8
    BaseInterfaceNumber: uint8
    NumberOfInterfaces: uint8
    FunctionIsIdle: uint8

  USB_COMPOSITE_DEVICE_INFO {.bycopy.} = object
    DeviceDescriptor: USB_DEVICE_DESCRIPTOR
    CurrentConfigDescriptor: USB_CONFIGURATION_DESCRIPTOR
    CurrentConfigurationValue: uint8
    NumberOfFunctions: uint8
    FunctionInfo: array[1, USB_COMPOSITE_FUNCTION_INFO]
align(1)
struct USB_DEVICE_DESCRIPTOR
{
    ubyte bLength;
    ubyte bDescriptorType;
    ushort bcdUSB;
    ubyte bDeviceClass;
    ubyte bDeviceSubClass;
    ubyte bDeviceProtocol;
    ubyte bMaxPacketSize0;
    ushort idVendor;
    ushort idProduct;
    ushort bcdDevice;
    ubyte iManufacturer;
    ubyte iProduct;
    ubyte iSerialNumber;
    ubyte bNumConfigurations;
}

align(1)
struct USB_CONFIGURATION_DESCRIPTOR
{
    ubyte bLength;
    ubyte bDescriptorType;
    ushort wTotalLength;
    ubyte bNumInterfaces;
    ubyte bConfigurationValue;
    ubyte iConfiguration;
    ubyte bmAttributes;
    ubyte MaxPower;
}

struct USB_COMPOSITE_FUNCTION_INFO
{
    ubyte FunctionNumber;
    ubyte BaseInterfaceNumber;
    ubyte NumberOfInterfaces;
    ubyte FunctionIsIdle;
}

struct USB_COMPOSITE_DEVICE_INFO
{
    USB_DEVICE_DESCRIPTOR DeviceDescriptor;
    USB_CONFIGURATION_DESCRIPTOR CurrentConfigDescriptor;
    ubyte CurrentConfigurationValue;
    ubyte NumberOfFunctions;
    USB_COMPOSITE_FUNCTION_INFO[1] FunctionInfo;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; USB_COMPOSITE_DEVICE_INFO サイズ: 33 バイト(x64)
dim st, 9    ; 4byte整数×9(構造体サイズ 33 / 4 切り上げ)
; DeviceDescriptor : USB_DEVICE_DESCRIPTOR (+0, 18byte)  varptr(st)+0 を基点に操作(18byte:入れ子/配列)
; CurrentConfigDescriptor : USB_CONFIGURATION_DESCRIPTOR (+18, 9byte)  varptr(st)+18 を基点に操作(9byte:入れ子/配列)
; CurrentConfigurationValue : BYTE (+27, 1byte)  poke st,27,値  /  値 = peek(st,27)
; NumberOfFunctions : BYTE (+28, 1byte)  poke st,28,値  /  値 = peek(st,28)
; FunctionInfo : USB_COMPOSITE_FUNCTION_INFO (+29, 4byte)  varptr(st)+29 を基点に操作(4byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global USB_DEVICE_DESCRIPTOR, pack=1
    #field byte bLength
    #field byte bDescriptorType
    #field short bcdUSB
    #field byte bDeviceClass
    #field byte bDeviceSubClass
    #field byte bDeviceProtocol
    #field byte bMaxPacketSize0
    #field short idVendor
    #field short idProduct
    #field short bcdDevice
    #field byte iManufacturer
    #field byte iProduct
    #field byte iSerialNumber
    #field byte bNumConfigurations
#endstruct

#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

#defstruct global USB_COMPOSITE_FUNCTION_INFO
    #field byte FunctionNumber
    #field byte BaseInterfaceNumber
    #field byte NumberOfInterfaces
    #field bool1 FunctionIsIdle
#endstruct

#defstruct global USB_COMPOSITE_DEVICE_INFO
    #field USB_DEVICE_DESCRIPTOR DeviceDescriptor
    #field USB_CONFIGURATION_DESCRIPTOR CurrentConfigDescriptor
    #field byte CurrentConfigurationValue
    #field byte NumberOfFunctions
    #field USB_COMPOSITE_FUNCTION_INFO FunctionInfo 1
#endstruct

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