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

USB_STRING_DESCRIPTOR

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

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

フィールド

フィールドサイズx64x86説明
bLengthBYTE1+0+0このディスクリプタのサイズをバイト単位で示す。
bDescriptorTypeBYTE1+1+1ディスクリプタ種別。文字列は0x03。
bStringWCHAR2+2+2UTF-16LEエンコードの文字列データ(可変長)。

各言語での定義

#include <windows.h>

// USB_STRING_DESCRIPTOR  (x64 4 / x86 4 バイト)
#pragma pack(push, 1)
typedef struct USB_STRING_DESCRIPTOR {
    BYTE bLength;
    BYTE bDescriptorType;
    WCHAR bString[1];
} USB_STRING_DESCRIPTOR;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_STRING_DESCRIPTOR
{
    public byte bLength;
    public byte bDescriptorType;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)] public string bString;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_STRING_DESCRIPTOR
    Public bLength As Byte
    Public bDescriptorType As Byte
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=1)> Public bString As String
End Structure
import ctypes
from ctypes import wintypes

class USB_STRING_DESCRIPTOR(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("bLength", ctypes.c_ubyte),
        ("bDescriptorType", ctypes.c_ubyte),
        ("bString", ctypes.c_wchar * 1),
    ]
#[repr(C, packed(1))]
pub struct USB_STRING_DESCRIPTOR {
    pub bLength: u8,
    pub bDescriptorType: u8,
    pub bString: [u16; 1],
}
import "golang.org/x/sys/windows"

type USB_STRING_DESCRIPTOR struct {
	bLength byte
	bDescriptorType byte
	bString [1]uint16
}
type
  USB_STRING_DESCRIPTOR = packed record
    bLength: Byte;
    bDescriptorType: Byte;
    bString: array[0..0] of WideChar;
  end;
const USB_STRING_DESCRIPTOR = extern struct {
    bLength: u8,
    bDescriptorType: u8,
    bString: [1]u16,
};
type
  USB_STRING_DESCRIPTOR {.packed.} = object
    bLength: uint8
    bDescriptorType: uint8
    bString: array[1, uint16]
align(1)
struct USB_STRING_DESCRIPTOR
{
    ubyte bLength;
    ubyte bDescriptorType;
    wchar[1] bString;
}

HSP用 定義

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

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

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