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

USBUSER_POWER_INFO_REQUEST

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

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

フィールド

フィールドサイズx64x86説明
HeaderUSBUSER_REQUEST_HEADER16+0+0USBUSER_REQUEST_HEADER 型の構造体を格納します。この構造体は、IOCTL_USB_USER_REQUEST への入力時にユーザーモード要求を指定し、出力時にバッファーおよび状態情報を提供します。
PowerInformationUSB_POWER_INFO34+16+16USB_POWER_INFO 型の構造体を格納します。この構造体は、この要求に関連するパラメーターを指定します。

公式ドキュメント

USBUSER_POWER_INFO_REQUEST 構造体は、IOCTL_USB_USER_REQUEST I/O 制御要求と組み合わせて使用し、特定のシステム状態とホストコントローラーおよびルートハブの電源状態との関係に関する電源ポリシー情報を取得します。

解説(Remarks)

USBUSER_POWER_INFO_REQUEST 構造体は、USBUSER_GET_POWER_STATE_MAP ユーザーモード要求と組み合わせて使用します。この要求の説明については、IOCTL_USB_USER_REQUEST を参照してください。

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

各言語での定義

#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)

// USB_POWER_INFO  (x64 34 / x86 34 バイト)
#pragma pack(push, 1)
typedef struct USB_POWER_INFO {
    WDMUSB_POWER_STATE SystemState;
    WDMUSB_POWER_STATE HcDevicePowerState;
    WDMUSB_POWER_STATE HcDeviceWake;
    WDMUSB_POWER_STATE HcSystemWake;
    WDMUSB_POWER_STATE RhDevicePowerState;
    WDMUSB_POWER_STATE RhDeviceWake;
    WDMUSB_POWER_STATE RhSystemWake;
    WDMUSB_POWER_STATE LastSystemSleepState;
    BOOLEAN CanWakeup;
    BOOLEAN IsPowered;
} USB_POWER_INFO;
#pragma pack(pop)

// USBUSER_POWER_INFO_REQUEST  (x64 50 / x86 50 バイト)
#pragma pack(push, 1)
typedef struct USBUSER_POWER_INFO_REQUEST {
    USBUSER_REQUEST_HEADER Header;
    USB_POWER_INFO PowerInformation;
} USBUSER_POWER_INFO_REQUEST;
#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 USB_POWER_INFO
{
    public int SystemState;
    public int HcDevicePowerState;
    public int HcDeviceWake;
    public int HcSystemWake;
    public int RhDevicePowerState;
    public int RhDeviceWake;
    public int RhSystemWake;
    public int LastSystemSleepState;
    [MarshalAs(UnmanagedType.U1)] public bool CanWakeup;
    [MarshalAs(UnmanagedType.U1)] public bool IsPowered;
}

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USBUSER_POWER_INFO_REQUEST
{
    public USBUSER_REQUEST_HEADER Header;
    public USB_POWER_INFO PowerInformation;
}
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 USB_POWER_INFO
    Public SystemState As Integer
    Public HcDevicePowerState As Integer
    Public HcDeviceWake As Integer
    Public HcSystemWake As Integer
    Public RhDevicePowerState As Integer
    Public RhDeviceWake As Integer
    Public RhSystemWake As Integer
    Public LastSystemSleepState As Integer
    <MarshalAs(UnmanagedType.U1)> Public CanWakeup As Boolean
    <MarshalAs(UnmanagedType.U1)> Public IsPowered As Boolean
End Structure

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USBUSER_POWER_INFO_REQUEST
    Public Header As USBUSER_REQUEST_HEADER
    Public PowerInformation As USB_POWER_INFO
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 USB_POWER_INFO(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("SystemState", ctypes.c_int),
        ("HcDevicePowerState", ctypes.c_int),
        ("HcDeviceWake", ctypes.c_int),
        ("HcSystemWake", ctypes.c_int),
        ("RhDevicePowerState", ctypes.c_int),
        ("RhDeviceWake", ctypes.c_int),
        ("RhSystemWake", ctypes.c_int),
        ("LastSystemSleepState", ctypes.c_int),
        ("CanWakeup", ctypes.c_byte),
        ("IsPowered", ctypes.c_byte),
    ]

class USBUSER_POWER_INFO_REQUEST(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("Header", USBUSER_REQUEST_HEADER),
        ("PowerInformation", USB_POWER_INFO),
    ]
#[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 USB_POWER_INFO {
    pub SystemState: i32,
    pub HcDevicePowerState: i32,
    pub HcDeviceWake: i32,
    pub HcSystemWake: i32,
    pub RhDevicePowerState: i32,
    pub RhDeviceWake: i32,
    pub RhSystemWake: i32,
    pub LastSystemSleepState: i32,
    pub CanWakeup: u8,
    pub IsPowered: u8,
}

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

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

type USB_POWER_INFO struct {
	SystemState int32
	HcDevicePowerState int32
	HcDeviceWake int32
	HcSystemWake int32
	RhDevicePowerState int32
	RhDeviceWake int32
	RhSystemWake int32
	LastSystemSleepState int32
	CanWakeup byte
	IsPowered byte
}

type USBUSER_POWER_INFO_REQUEST struct {
	Header USBUSER_REQUEST_HEADER
	PowerInformation USB_POWER_INFO
}
type
  USBUSER_REQUEST_HEADER = packed record
    UsbUserRequest: DWORD;
    UsbUserStatusCode: Integer;
    RequestBufferLength: DWORD;
    ActualBufferLength: DWORD;
  end;

  USB_POWER_INFO = packed record
    SystemState: Integer;
    HcDevicePowerState: Integer;
    HcDeviceWake: Integer;
    HcSystemWake: Integer;
    RhDevicePowerState: Integer;
    RhDeviceWake: Integer;
    RhSystemWake: Integer;
    LastSystemSleepState: Integer;
    CanWakeup: ByteBool;
    IsPowered: ByteBool;
  end;

  USBUSER_POWER_INFO_REQUEST = packed record
    Header: USBUSER_REQUEST_HEADER;
    PowerInformation: USB_POWER_INFO;
  end;
const USBUSER_REQUEST_HEADER = extern struct {
    UsbUserRequest: u32,
    UsbUserStatusCode: i32,
    RequestBufferLength: u32,
    ActualBufferLength: u32,
};

const USB_POWER_INFO = extern struct {
    SystemState: i32,
    HcDevicePowerState: i32,
    HcDeviceWake: i32,
    HcSystemWake: i32,
    RhDevicePowerState: i32,
    RhDeviceWake: i32,
    RhSystemWake: i32,
    LastSystemSleepState: i32,
    CanWakeup: u8,
    IsPowered: u8,
};

const USBUSER_POWER_INFO_REQUEST = extern struct {
    Header: USBUSER_REQUEST_HEADER,
    PowerInformation: USB_POWER_INFO,
};
type
  USBUSER_REQUEST_HEADER {.packed.} = object
    UsbUserRequest: uint32
    UsbUserStatusCode: int32
    RequestBufferLength: uint32
    ActualBufferLength: uint32

  USB_POWER_INFO {.packed.} = object
    SystemState: int32
    HcDevicePowerState: int32
    HcDeviceWake: int32
    HcSystemWake: int32
    RhDevicePowerState: int32
    RhDeviceWake: int32
    RhSystemWake: int32
    LastSystemSleepState: int32
    CanWakeup: uint8
    IsPowered: uint8

  USBUSER_POWER_INFO_REQUEST {.packed.} = object
    Header: USBUSER_REQUEST_HEADER
    PowerInformation: USB_POWER_INFO
align(1)
struct USBUSER_REQUEST_HEADER
{
    uint UsbUserRequest;
    int UsbUserStatusCode;
    uint RequestBufferLength;
    uint ActualBufferLength;
}

align(1)
struct USB_POWER_INFO
{
    int SystemState;
    int HcDevicePowerState;
    int HcDeviceWake;
    int HcSystemWake;
    int RhDevicePowerState;
    int RhDeviceWake;
    int RhSystemWake;
    int LastSystemSleepState;
    ubyte CanWakeup;
    ubyte IsPowered;
}

align(1)
struct USBUSER_POWER_INFO_REQUEST
{
    USBUSER_REQUEST_HEADER Header;
    USB_POWER_INFO PowerInformation;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; USBUSER_POWER_INFO_REQUEST サイズ: 50 バイト(x64)
dim st, 13    ; 4byte整数×13(構造体サイズ 50 / 4 切り上げ)
; Header : USBUSER_REQUEST_HEADER (+0, 16byte)  varptr(st)+0 を基点に操作(16byte:入れ子/配列)
; PowerInformation : USB_POWER_INFO (+16, 34byte)  varptr(st)+16 を基点に操作(34byte:入れ子/配列)
; ※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 USB_POWER_INFO, pack=1
    #field int SystemState
    #field int HcDevicePowerState
    #field int HcDeviceWake
    #field int HcSystemWake
    #field int RhDevicePowerState
    #field int RhDeviceWake
    #field int RhSystemWake
    #field int LastSystemSleepState
    #field bool1 CanWakeup
    #field bool1 IsPowered
#endstruct

#defstruct global USBUSER_POWER_INFO_REQUEST, pack=1
    #field USBUSER_REQUEST_HEADER Header
    #field USB_POWER_INFO PowerInformation
#endstruct

stdim st, USBUSER_POWER_INFO_REQUEST        ; NSTRUCT 変数を確保