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

USB_PORT_CHANGE

共用体
サイズx64: 2 バイト / x86: 2 バイトパッキング1

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

フィールド

フィールドサイズx64x86説明
AsUshort16WORD2+0+0ポート変化ビットを16ビット生値として参照するメンバ。
Usb20PortChangeUSB_20_PORT_CHANGE2+0+0USB2.0として解釈したポート変化情報。
Usb30PortChangeUSB_30_PORT_CHANGE2+0+0USB3.0として解釈したポート変化情報。

各言語での定義

#include <windows.h>

// USB_20_PORT_CHANGE  (x64 2 / x86 2 バイト)
#pragma pack(push, 1)
typedef struct USB_20_PORT_CHANGE {
    WORD AsUshort16;
    _Anonymous_e__Struct Anonymous;
} USB_20_PORT_CHANGE;
#pragma pack(pop)

// USB_30_PORT_CHANGE  (x64 2 / x86 2 バイト)
#pragma pack(push, 1)
typedef struct USB_30_PORT_CHANGE {
    WORD AsUshort16;
    _Anonymous_e__Struct Anonymous;
} USB_30_PORT_CHANGE;
#pragma pack(pop)

// USB_PORT_CHANGE  (x64 2 / x86 2 バイト)
#pragma pack(push, 1)
typedef struct USB_PORT_CHANGE {
    WORD AsUshort16;
    USB_20_PORT_CHANGE Usb20PortChange;
    USB_30_PORT_CHANGE Usb30PortChange;
} USB_PORT_CHANGE;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_20_PORT_CHANGE
{
    public ushort AsUshort16;
    public _Anonymous_e__Struct Anonymous;
}

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_30_PORT_CHANGE
{
    public ushort AsUshort16;
    public _Anonymous_e__Struct Anonymous;
}

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_PORT_CHANGE
{
    public ushort AsUshort16;
    public USB_20_PORT_CHANGE Usb20PortChange;
    public USB_30_PORT_CHANGE Usb30PortChange;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_20_PORT_CHANGE
    Public AsUshort16 As UShort
    Public Anonymous As _Anonymous_e__Struct
End Structure

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_30_PORT_CHANGE
    Public AsUshort16 As UShort
    Public Anonymous As _Anonymous_e__Struct
End Structure

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_PORT_CHANGE
    Public AsUshort16 As UShort
    Public Usb20PortChange As USB_20_PORT_CHANGE
    Public Usb30PortChange As USB_30_PORT_CHANGE
End Structure
import ctypes
from ctypes import wintypes

class USB_20_PORT_CHANGE(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("AsUshort16", ctypes.c_ushort),
        ("Anonymous", _Anonymous_e__Struct),
    ]

class USB_30_PORT_CHANGE(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("AsUshort16", ctypes.c_ushort),
        ("Anonymous", _Anonymous_e__Struct),
    ]

class USB_PORT_CHANGE(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("AsUshort16", ctypes.c_ushort),
        ("Usb20PortChange", USB_20_PORT_CHANGE),
        ("Usb30PortChange", USB_30_PORT_CHANGE),
    ]
#[repr(C, packed(1))]
pub struct USB_20_PORT_CHANGE {
    pub AsUshort16: u16,
    pub Anonymous: _Anonymous_e__Struct,
}

#[repr(C, packed(1))]
pub struct USB_30_PORT_CHANGE {
    pub AsUshort16: u16,
    pub Anonymous: _Anonymous_e__Struct,
}

#[repr(C, packed(1))]
pub struct USB_PORT_CHANGE {
    pub AsUshort16: u16,
    pub Usb20PortChange: USB_20_PORT_CHANGE,
    pub Usb30PortChange: USB_30_PORT_CHANGE,
}
import "golang.org/x/sys/windows"

type USB_20_PORT_CHANGE struct {
	AsUshort16 uint16
	Anonymous _Anonymous_e__Struct
}

type USB_30_PORT_CHANGE struct {
	AsUshort16 uint16
	Anonymous _Anonymous_e__Struct
}

type USB_PORT_CHANGE struct {
	AsUshort16 uint16
	Usb20PortChange USB_20_PORT_CHANGE
	Usb30PortChange USB_30_PORT_CHANGE
}
type
  USB_20_PORT_CHANGE = packed record
    AsUshort16: Word;
    Anonymous: _Anonymous_e__Struct;
  end;

  USB_30_PORT_CHANGE = packed record
    AsUshort16: Word;
    Anonymous: _Anonymous_e__Struct;
  end;

  USB_PORT_CHANGE = packed record
    AsUshort16: Word;
    Usb20PortChange: USB_20_PORT_CHANGE;
    Usb30PortChange: USB_30_PORT_CHANGE;
  end;
const USB_20_PORT_CHANGE = extern struct {
    AsUshort16: u16,
    Anonymous: _Anonymous_e__Struct,
};

const USB_30_PORT_CHANGE = extern struct {
    AsUshort16: u16,
    Anonymous: _Anonymous_e__Struct,
};

const USB_PORT_CHANGE = extern struct {
    AsUshort16: u16,
    Usb20PortChange: USB_20_PORT_CHANGE,
    Usb30PortChange: USB_30_PORT_CHANGE,
};
type
  USB_20_PORT_CHANGE {.packed.} = object
    AsUshort16: uint16
    Anonymous: _Anonymous_e__Struct

  USB_30_PORT_CHANGE {.packed.} = object
    AsUshort16: uint16
    Anonymous: _Anonymous_e__Struct

  USB_PORT_CHANGE {.packed.} = object
    AsUshort16: uint16
    Usb20PortChange: USB_20_PORT_CHANGE
    Usb30PortChange: USB_30_PORT_CHANGE
align(1)
struct USB_20_PORT_CHANGE
{
    ushort AsUshort16;
    _Anonymous_e__Struct Anonymous;
}

align(1)
struct USB_30_PORT_CHANGE
{
    ushort AsUshort16;
    _Anonymous_e__Struct Anonymous;
}

align(1)
struct USB_PORT_CHANGE
{
    ushort AsUshort16;
    USB_20_PORT_CHANGE Usb20PortChange;
    USB_30_PORT_CHANGE Usb30PortChange;
}

HSP用 定義

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

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

stdim st, USB_PORT_CHANGE        ; NSTRUCT 変数を確保
st->AsUshort16 = 100
mes "AsUshort16=" + st->AsUshort16
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。