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

USBUSER_RAW_RESET_ROOT_PORT

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

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

フィールド

フィールドサイズx64x86説明
HeaderUSBUSER_REQUEST_HEADER16+0+0USBUSER要求共通ヘッダ。要求コードと結果を保持する。
ParametersRAW_RESET_PORT_PARAMETERS4+16+16ルートポートの生リセットに必要なパラメータを保持する。

各言語での定義

#include <windows.h>

// USBUSER_REQUEST_HEADER  (x64 16 / x86 16 バイト)
#pragma pack(push, 1)
typedef struct USBUSER_REQUEST_HEADER {
    DWORD UsbUserRequest;
    USB_USER_ERROR_CODE UsbUserStatusCode;
    DWORD RequestBufferLength;
    DWORD ActualBufferLength;
} USBUSER_REQUEST_HEADER;
#pragma pack(pop)

// RAW_RESET_PORT_PARAMETERS  (x64 4 / x86 4 バイト)
#pragma pack(push, 1)
typedef struct RAW_RESET_PORT_PARAMETERS {
    WORD PortNumber;
    WORD PortStatus;
} RAW_RESET_PORT_PARAMETERS;
#pragma pack(pop)

// USBUSER_RAW_RESET_ROOT_PORT  (x64 20 / x86 20 バイト)
#pragma pack(push, 1)
typedef struct USBUSER_RAW_RESET_ROOT_PORT {
    USBUSER_REQUEST_HEADER Header;
    RAW_RESET_PORT_PARAMETERS Parameters;
} USBUSER_RAW_RESET_ROOT_PORT;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USBUSER_REQUEST_HEADER
{
    public uint UsbUserRequest;
    public int UsbUserStatusCode;
    public uint RequestBufferLength;
    public uint ActualBufferLength;
}

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct RAW_RESET_PORT_PARAMETERS
{
    public ushort PortNumber;
    public ushort PortStatus;
}

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USBUSER_RAW_RESET_ROOT_PORT
{
    public USBUSER_REQUEST_HEADER Header;
    public RAW_RESET_PORT_PARAMETERS Parameters;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USBUSER_REQUEST_HEADER
    Public UsbUserRequest As UInteger
    Public UsbUserStatusCode As Integer
    Public RequestBufferLength As UInteger
    Public ActualBufferLength As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure RAW_RESET_PORT_PARAMETERS
    Public PortNumber As UShort
    Public PortStatus As UShort
End Structure

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USBUSER_RAW_RESET_ROOT_PORT
    Public Header As USBUSER_REQUEST_HEADER
    Public Parameters As RAW_RESET_PORT_PARAMETERS
End Structure
import ctypes
from ctypes import wintypes

class USBUSER_REQUEST_HEADER(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("UsbUserRequest", wintypes.DWORD),
        ("UsbUserStatusCode", ctypes.c_int),
        ("RequestBufferLength", wintypes.DWORD),
        ("ActualBufferLength", wintypes.DWORD),
    ]

class RAW_RESET_PORT_PARAMETERS(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("PortNumber", ctypes.c_ushort),
        ("PortStatus", ctypes.c_ushort),
    ]

class USBUSER_RAW_RESET_ROOT_PORT(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("Header", USBUSER_REQUEST_HEADER),
        ("Parameters", RAW_RESET_PORT_PARAMETERS),
    ]
#[repr(C, packed(1))]
pub struct USBUSER_REQUEST_HEADER {
    pub UsbUserRequest: u32,
    pub UsbUserStatusCode: i32,
    pub RequestBufferLength: u32,
    pub ActualBufferLength: u32,
}

#[repr(C, packed(1))]
pub struct RAW_RESET_PORT_PARAMETERS {
    pub PortNumber: u16,
    pub PortStatus: u16,
}

#[repr(C, packed(1))]
pub struct USBUSER_RAW_RESET_ROOT_PORT {
    pub Header: USBUSER_REQUEST_HEADER,
    pub Parameters: RAW_RESET_PORT_PARAMETERS,
}
import "golang.org/x/sys/windows"

type USBUSER_REQUEST_HEADER struct {
	UsbUserRequest uint32
	UsbUserStatusCode int32
	RequestBufferLength uint32
	ActualBufferLength uint32
}

type RAW_RESET_PORT_PARAMETERS struct {
	PortNumber uint16
	PortStatus uint16
}

type USBUSER_RAW_RESET_ROOT_PORT struct {
	Header USBUSER_REQUEST_HEADER
	Parameters RAW_RESET_PORT_PARAMETERS
}
type
  USBUSER_REQUEST_HEADER = packed record
    UsbUserRequest: DWORD;
    UsbUserStatusCode: Integer;
    RequestBufferLength: DWORD;
    ActualBufferLength: DWORD;
  end;

  RAW_RESET_PORT_PARAMETERS = packed record
    PortNumber: Word;
    PortStatus: Word;
  end;

  USBUSER_RAW_RESET_ROOT_PORT = packed record
    Header: USBUSER_REQUEST_HEADER;
    Parameters: RAW_RESET_PORT_PARAMETERS;
  end;
const USBUSER_REQUEST_HEADER = extern struct {
    UsbUserRequest: u32,
    UsbUserStatusCode: i32,
    RequestBufferLength: u32,
    ActualBufferLength: u32,
};

const RAW_RESET_PORT_PARAMETERS = extern struct {
    PortNumber: u16,
    PortStatus: u16,
};

const USBUSER_RAW_RESET_ROOT_PORT = extern struct {
    Header: USBUSER_REQUEST_HEADER,
    Parameters: RAW_RESET_PORT_PARAMETERS,
};
type
  USBUSER_REQUEST_HEADER {.packed.} = object
    UsbUserRequest: uint32
    UsbUserStatusCode: int32
    RequestBufferLength: uint32
    ActualBufferLength: uint32

  RAW_RESET_PORT_PARAMETERS {.packed.} = object
    PortNumber: uint16
    PortStatus: uint16

  USBUSER_RAW_RESET_ROOT_PORT {.packed.} = object
    Header: USBUSER_REQUEST_HEADER
    Parameters: RAW_RESET_PORT_PARAMETERS
align(1)
struct USBUSER_REQUEST_HEADER
{
    uint UsbUserRequest;
    int UsbUserStatusCode;
    uint RequestBufferLength;
    uint ActualBufferLength;
}

align(1)
struct RAW_RESET_PORT_PARAMETERS
{
    ushort PortNumber;
    ushort PortStatus;
}

align(1)
struct USBUSER_RAW_RESET_ROOT_PORT
{
    USBUSER_REQUEST_HEADER Header;
    RAW_RESET_PORT_PARAMETERS Parameters;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; USBUSER_RAW_RESET_ROOT_PORT サイズ: 20 バイト(x64)
dim st, 5    ; 4byte整数×5(構造体サイズ 20 / 4 切り上げ)
; Header : USBUSER_REQUEST_HEADER (+0, 16byte)  varptr(st)+0 を基点に操作(16byte:入れ子/配列)
; Parameters : RAW_RESET_PORT_PARAMETERS (+16, 4byte)  varptr(st)+16 を基点に操作(4byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global USBUSER_REQUEST_HEADER, pack=1
    #field int UsbUserRequest
    #field int UsbUserStatusCode
    #field int RequestBufferLength
    #field int ActualBufferLength
#endstruct

#defstruct global RAW_RESET_PORT_PARAMETERS, pack=1
    #field short PortNumber
    #field short PortStatus
#endstruct

#defstruct global USBUSER_RAW_RESET_ROOT_PORT, pack=1
    #field USBUSER_REQUEST_HEADER Header
    #field RAW_RESET_PORT_PARAMETERS Parameters
#endstruct

stdim st, USBUSER_RAW_RESET_ROOT_PORT        ; NSTRUCT 変数を確保