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

USB_INTERFACE_DESCRIPTOR

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

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

フィールド

フィールドサイズx64x86説明
bLengthBYTE1+0+0このディスクリプタのサイズをバイト単位で示す。通常9。
bDescriptorTypeBYTE1+1+1ディスクリプタ種別。インターフェイスは0x04。
bInterfaceNumberBYTE1+2+2このインターフェイスの番号を示す。
bAlternateSettingBYTE1+3+3代替設定の番号を示す。
bNumEndpointsBYTE1+4+4エンドポイント0以外のエンドポイント数を示す。
bInterfaceClassBYTE1+5+5インターフェイスのクラスコードを示す。
bInterfaceSubClassBYTE1+6+6インターフェイスのサブクラスコードを示す。
bInterfaceProtocolBYTE1+7+7インターフェイスのプロトコルコードを示す。
iInterfaceBYTE1+8+8インターフェイス名文字列ディスクリプタのインデックス。

各言語での定義

#include <windows.h>

// USB_INTERFACE_DESCRIPTOR  (x64 9 / x86 9 バイト)
typedef struct USB_INTERFACE_DESCRIPTOR {
    BYTE bLength;
    BYTE bDescriptorType;
    BYTE bInterfaceNumber;
    BYTE bAlternateSetting;
    BYTE bNumEndpoints;
    BYTE bInterfaceClass;
    BYTE bInterfaceSubClass;
    BYTE bInterfaceProtocol;
    BYTE iInterface;
} USB_INTERFACE_DESCRIPTOR;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USB_INTERFACE_DESCRIPTOR
{
    public byte bLength;
    public byte bDescriptorType;
    public byte bInterfaceNumber;
    public byte bAlternateSetting;
    public byte bNumEndpoints;
    public byte bInterfaceClass;
    public byte bInterfaceSubClass;
    public byte bInterfaceProtocol;
    public byte iInterface;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure USB_INTERFACE_DESCRIPTOR
    Public bLength As Byte
    Public bDescriptorType As Byte
    Public bInterfaceNumber As Byte
    Public bAlternateSetting As Byte
    Public bNumEndpoints As Byte
    Public bInterfaceClass As Byte
    Public bInterfaceSubClass As Byte
    Public bInterfaceProtocol As Byte
    Public iInterface As Byte
End Structure
import ctypes
from ctypes import wintypes

class USB_INTERFACE_DESCRIPTOR(ctypes.Structure):
    _fields_ = [
        ("bLength", ctypes.c_ubyte),
        ("bDescriptorType", ctypes.c_ubyte),
        ("bInterfaceNumber", ctypes.c_ubyte),
        ("bAlternateSetting", ctypes.c_ubyte),
        ("bNumEndpoints", ctypes.c_ubyte),
        ("bInterfaceClass", ctypes.c_ubyte),
        ("bInterfaceSubClass", ctypes.c_ubyte),
        ("bInterfaceProtocol", ctypes.c_ubyte),
        ("iInterface", ctypes.c_ubyte),
    ]
#[repr(C)]
pub struct USB_INTERFACE_DESCRIPTOR {
    pub bLength: u8,
    pub bDescriptorType: u8,
    pub bInterfaceNumber: u8,
    pub bAlternateSetting: u8,
    pub bNumEndpoints: u8,
    pub bInterfaceClass: u8,
    pub bInterfaceSubClass: u8,
    pub bInterfaceProtocol: u8,
    pub iInterface: u8,
}
import "golang.org/x/sys/windows"

type USB_INTERFACE_DESCRIPTOR struct {
	bLength byte
	bDescriptorType byte
	bInterfaceNumber byte
	bAlternateSetting byte
	bNumEndpoints byte
	bInterfaceClass byte
	bInterfaceSubClass byte
	bInterfaceProtocol byte
	iInterface byte
}
type
  USB_INTERFACE_DESCRIPTOR = record
    bLength: Byte;
    bDescriptorType: Byte;
    bInterfaceNumber: Byte;
    bAlternateSetting: Byte;
    bNumEndpoints: Byte;
    bInterfaceClass: Byte;
    bInterfaceSubClass: Byte;
    bInterfaceProtocol: Byte;
    iInterface: Byte;
  end;
const USB_INTERFACE_DESCRIPTOR = extern struct {
    bLength: u8,
    bDescriptorType: u8,
    bInterfaceNumber: u8,
    bAlternateSetting: u8,
    bNumEndpoints: u8,
    bInterfaceClass: u8,
    bInterfaceSubClass: u8,
    bInterfaceProtocol: u8,
    iInterface: u8,
};
type
  USB_INTERFACE_DESCRIPTOR {.bycopy.} = object
    bLength: uint8
    bDescriptorType: uint8
    bInterfaceNumber: uint8
    bAlternateSetting: uint8
    bNumEndpoints: uint8
    bInterfaceClass: uint8
    bInterfaceSubClass: uint8
    bInterfaceProtocol: uint8
    iInterface: uint8
struct USB_INTERFACE_DESCRIPTOR
{
    ubyte bLength;
    ubyte bDescriptorType;
    ubyte bInterfaceNumber;
    ubyte bAlternateSetting;
    ubyte bNumEndpoints;
    ubyte bInterfaceClass;
    ubyte bInterfaceSubClass;
    ubyte bInterfaceProtocol;
    ubyte iInterface;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; USB_INTERFACE_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)
; bInterfaceNumber : BYTE (+2, 1byte)  poke st,2,値  /  値 = peek(st,2)
; bAlternateSetting : BYTE (+3, 1byte)  poke st,3,値  /  値 = peek(st,3)
; bNumEndpoints : BYTE (+4, 1byte)  poke st,4,値  /  値 = peek(st,4)
; bInterfaceClass : BYTE (+5, 1byte)  poke st,5,値  /  値 = peek(st,5)
; bInterfaceSubClass : BYTE (+6, 1byte)  poke st,6,値  /  値 = peek(st,6)
; bInterfaceProtocol : BYTE (+7, 1byte)  poke st,7,値  /  値 = peek(st,7)
; iInterface : BYTE (+8, 1byte)  poke st,8,値  /  値 = peek(st,8)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global USB_INTERFACE_DESCRIPTOR
    #field byte bLength
    #field byte bDescriptorType
    #field byte bInterfaceNumber
    #field byte bAlternateSetting
    #field byte bNumEndpoints
    #field byte bInterfaceClass
    #field byte bInterfaceSubClass
    #field byte bInterfaceProtocol
    #field byte iInterface
#endstruct

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