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要求の種類です。このメンバーに割り当てられる値は、Universal Serial Bus (USB) 仕様 (www.usb.org) のセクション 9.3 の表 9.2 で定義されています。
RequestBYTE1+1+1デバイス要求です。このメンバーに割り当てられる値は、Universal Serial Bus (USB) 仕様のセクション 9.4 の表 9.3 で定義されています。
ValueWORD2+2+2このメンバーの意味は要求によって異なります。このメンバーの説明については、Universal Serial Bus (USB) 仕様を参照してください。
IndexWORD2+4+4このメンバーの意味は要求によって異なります。このメンバーの説明については、Universal Serial Bus (USB) 仕様を参照してください。
LengthWORD2+6+6転送するバイト数です。

公式ドキュメント

WINUSB_SETUP_PACKET 構造体は、USB のセットアップパケットを記述します。

解説(Remarks)

WinUsb_ControlTransfer ルーチンの呼び出し元は、WINUSB_SETUP_PACKET 構造体を渡さなければなりません。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#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