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

USB_PORT_CONNECTOR_PROPERTIES

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

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

フィールド

フィールドサイズx64x86説明
ConnectionIndexDWORD4+0+0照会対象ポートの1始まりインデックス。
ActualLengthDWORD4+4+4返された構造体の実バイト長。
UsbPortPropertiesUSB_PORT_PROPERTIES4+8+8ポートのプロパティを示すフラグ集合。
CompanionIndexWORD2+12+12コンパニオン(対となる)ポートのインデックス。
CompanionPortNumberWORD2+14+14コンパニオンポートの物理ポート番号。
CompanionHubSymbolicLinkNameWCHAR2+16+16コンパニオンハブのシンボリックリンク名(ワイド文字列)。

各言語での定義

#include <windows.h>

// USB_PORT_PROPERTIES  (x64 4 / x86 4 バイト)
#pragma pack(push, 1)
typedef struct USB_PORT_PROPERTIES {
    DWORD ul;
    _Anonymous_e__Struct Anonymous;
} USB_PORT_PROPERTIES;
#pragma pack(pop)

// USB_PORT_CONNECTOR_PROPERTIES  (x64 18 / x86 18 バイト)
#pragma pack(push, 1)
typedef struct USB_PORT_CONNECTOR_PROPERTIES {
    DWORD ConnectionIndex;
    DWORD ActualLength;
    USB_PORT_PROPERTIES UsbPortProperties;
    WORD CompanionIndex;
    WORD CompanionPortNumber;
    WCHAR CompanionHubSymbolicLinkName[1];
} USB_PORT_CONNECTOR_PROPERTIES;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_PORT_PROPERTIES
{
    public uint ul;
    public _Anonymous_e__Struct Anonymous;
}

[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct USB_PORT_CONNECTOR_PROPERTIES
{
    public uint ConnectionIndex;
    public uint ActualLength;
    public USB_PORT_PROPERTIES UsbPortProperties;
    public ushort CompanionIndex;
    public ushort CompanionPortNumber;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)] public string CompanionHubSymbolicLinkName;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_PORT_PROPERTIES
    Public ul As UInteger
    Public Anonymous As _Anonymous_e__Struct
End Structure

<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure USB_PORT_CONNECTOR_PROPERTIES
    Public ConnectionIndex As UInteger
    Public ActualLength As UInteger
    Public UsbPortProperties As USB_PORT_PROPERTIES
    Public CompanionIndex As UShort
    Public CompanionPortNumber As UShort
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=1)> Public CompanionHubSymbolicLinkName As String
End Structure
import ctypes
from ctypes import wintypes

class USB_PORT_PROPERTIES(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("ul", wintypes.DWORD),
        ("Anonymous", _Anonymous_e__Struct),
    ]

class USB_PORT_CONNECTOR_PROPERTIES(ctypes.Structure):
    _pack_ = 1
    _fields_ = [
        ("ConnectionIndex", wintypes.DWORD),
        ("ActualLength", wintypes.DWORD),
        ("UsbPortProperties", USB_PORT_PROPERTIES),
        ("CompanionIndex", ctypes.c_ushort),
        ("CompanionPortNumber", ctypes.c_ushort),
        ("CompanionHubSymbolicLinkName", ctypes.c_wchar * 1),
    ]
#[repr(C, packed(1))]
pub struct USB_PORT_PROPERTIES {
    pub ul: u32,
    pub Anonymous: _Anonymous_e__Struct,
}

#[repr(C, packed(1))]
pub struct USB_PORT_CONNECTOR_PROPERTIES {
    pub ConnectionIndex: u32,
    pub ActualLength: u32,
    pub UsbPortProperties: USB_PORT_PROPERTIES,
    pub CompanionIndex: u16,
    pub CompanionPortNumber: u16,
    pub CompanionHubSymbolicLinkName: [u16; 1],
}
import "golang.org/x/sys/windows"

type USB_PORT_PROPERTIES struct {
	ul uint32
	Anonymous _Anonymous_e__Struct
}

type USB_PORT_CONNECTOR_PROPERTIES struct {
	ConnectionIndex uint32
	ActualLength uint32
	UsbPortProperties USB_PORT_PROPERTIES
	CompanionIndex uint16
	CompanionPortNumber uint16
	CompanionHubSymbolicLinkName [1]uint16
}
type
  USB_PORT_PROPERTIES = packed record
    ul: DWORD;
    Anonymous: _Anonymous_e__Struct;
  end;

  USB_PORT_CONNECTOR_PROPERTIES = packed record
    ConnectionIndex: DWORD;
    ActualLength: DWORD;
    UsbPortProperties: USB_PORT_PROPERTIES;
    CompanionIndex: Word;
    CompanionPortNumber: Word;
    CompanionHubSymbolicLinkName: array[0..0] of WideChar;
  end;
const USB_PORT_PROPERTIES = extern struct {
    ul: u32,
    Anonymous: _Anonymous_e__Struct,
};

const USB_PORT_CONNECTOR_PROPERTIES = extern struct {
    ConnectionIndex: u32,
    ActualLength: u32,
    UsbPortProperties: USB_PORT_PROPERTIES,
    CompanionIndex: u16,
    CompanionPortNumber: u16,
    CompanionHubSymbolicLinkName: [1]u16,
};
type
  USB_PORT_PROPERTIES {.packed.} = object
    ul: uint32
    Anonymous: _Anonymous_e__Struct

  USB_PORT_CONNECTOR_PROPERTIES {.packed.} = object
    ConnectionIndex: uint32
    ActualLength: uint32
    UsbPortProperties: USB_PORT_PROPERTIES
    CompanionIndex: uint16
    CompanionPortNumber: uint16
    CompanionHubSymbolicLinkName: array[1, uint16]
align(1)
struct USB_PORT_PROPERTIES
{
    uint ul;
    _Anonymous_e__Struct Anonymous;
}

align(1)
struct USB_PORT_CONNECTOR_PROPERTIES
{
    uint ConnectionIndex;
    uint ActualLength;
    USB_PORT_PROPERTIES UsbPortProperties;
    ushort CompanionIndex;
    ushort CompanionPortNumber;
    wchar[1] CompanionHubSymbolicLinkName;
}

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_CONNECTOR_PROPERTIES サイズ: 18 バイト(x64)
dim st, 5    ; 4byte整数×5(構造体サイズ 18 / 4 切り上げ)
; ConnectionIndex : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; ActualLength : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; UsbPortProperties : USB_PORT_PROPERTIES (+8, 4byte)  varptr(st)+8 を基点に操作(4byte:入れ子/配列)
; CompanionIndex : WORD (+12, 2byte)  wpoke st,12,値  /  値 = wpeek(st,12)
; CompanionPortNumber : WORD (+14, 2byte)  wpoke st,14,値  /  値 = wpeek(st,14)
; CompanionHubSymbolicLinkName : WCHAR (+16, 2byte)  varptr(st)+16 を基点に操作(2byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global USB_PORT_CONNECTOR_PROPERTIES, pack=1
    #field int ConnectionIndex
    #field int ActualLength
    #field byte UsbPortProperties 4
    #field short CompanionIndex
    #field short CompanionPortNumber
    #field wchar CompanionHubSymbolicLinkName 1
#endstruct

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