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

WINUSB_SETUP_PACKET

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

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

フィールド

フィールドサイズx64x86説明
RequestTypeBYTE1+0+0セットアップパケットのbmRequestType(方向・種別・受信側)。
RequestBYTE1+1+1実行する特定の要求コード(bRequest)。
ValueWORD2+2+2要求依存のwValueフィールド。
IndexWORD2+4+4要求依存のwIndexフィールド(インターフェイス/エンドポイント等)。
LengthWORD2+6+6データステージで転送するバイト数(wLength)。

各言語での定義

#include <windows.h>

// WINUSB_SETUP_PACKET  (x64 8 / x86 8 バイト)
#pragma pack(push, 1)
typedef struct WINUSB_SETUP_PACKET {
    BYTE RequestType;
    BYTE Request;
    WORD Value;
    WORD Index;
    WORD Length;
} WINUSB_SETUP_PACKET;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct WINUSB_SETUP_PACKET
{
    public byte RequestType;
    public byte Request;
    public ushort Value;
    public ushort Index;
    public ushort Length;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure WINUSB_SETUP_PACKET
    Public RequestType As Byte
    Public Request As Byte
    Public Value As UShort
    Public Index As UShort
    Public Length As UShort
End Structure
import ctypes
from ctypes import wintypes

class WINUSB_SETUP_PACKET(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("RequestType", ctypes.c_ubyte),
        ("Request", ctypes.c_ubyte),
        ("Value", ctypes.c_ushort),
        ("Index", ctypes.c_ushort),
        ("Length", ctypes.c_ushort),
    ]
#[repr(C, packed(1))]
pub struct WINUSB_SETUP_PACKET {
    pub RequestType: u8,
    pub Request: u8,
    pub Value: u16,
    pub Index: u16,
    pub Length: u16,
}
import "golang.org/x/sys/windows"

type WINUSB_SETUP_PACKET struct {
	RequestType byte
	Request byte
	Value uint16
	Index uint16
	Length uint16
}
type
  WINUSB_SETUP_PACKET = packed record
    RequestType: Byte;
    Request: Byte;
    Value: Word;
    Index: Word;
    Length: Word;
  end;
const WINUSB_SETUP_PACKET = extern struct {
    RequestType: u8,
    Request: u8,
    Value: u16,
    Index: u16,
    Length: u16,
};
type
  WINUSB_SETUP_PACKET {.packed.} = object
    RequestType: uint8
    Request: uint8
    Value: uint16
    Index: uint16
    Length: uint16
align(1)
struct WINUSB_SETUP_PACKET
{
    ubyte RequestType;
    ubyte Request;
    ushort Value;
    ushort Index;
    ushort Length;
}

HSP用 定義

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

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

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