ホーム › Devices.Usb › OS_STRING
OS_STRING
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| bLength | BYTE | 1 | +0 | +0 | このディスクリプタのサイズをバイト単位で示す。 |
| bDescriptorType | BYTE | 1 | +1 | +1 | ディスクリプタ種別。文字列ディスクリプタ。 |
| MicrosoftString | WCHAR | 14 | +2 | +2 | "MSFT100"等のMicrosoft OSディスクリプタ識別子を示すワイド文字配列。 |
| bVendorCode | BYTE | 1 | +16 | +16 | OS機能ディスクリプタ取得に使うベンダリクエストコードを示す。 |
| Anonymous | _Anonymous_e__Union | 1 | +17 | +17 | パディングまたはサブコンテナIDを保持する無名共用体。 |
共用体: _Anonymous_e__Union x64 1B / x86 1B
| フィールド | 型 | サイズ | x64 | x86 |
|---|---|---|---|---|
| bPad | BYTE | 1 | +0 | +0 |
| bFlags | BYTE | 1 | +0 | +0 |
各言語での定義
#include <windows.h>
// OS_STRING (x64 18 / x86 18 バイト)
typedef struct OS_STRING {
BYTE bLength;
BYTE bDescriptorType;
WCHAR MicrosoftString[7];
BYTE bVendorCode;
_Anonymous_e__Union Anonymous;
} OS_STRING;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct OS_STRING
{
public byte bLength;
public byte bDescriptorType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7)] public string MicrosoftString;
public byte bVendorCode;
public _Anonymous_e__Union Anonymous;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure OS_STRING
Public bLength As Byte
Public bDescriptorType As Byte
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=7)> Public MicrosoftString As String
Public bVendorCode As Byte
Public Anonymous As _Anonymous_e__Union
End Structureimport ctypes
from ctypes import wintypes
class OS_STRING(ctypes.Structure):
_fields_ = [
("bLength", ctypes.c_ubyte),
("bDescriptorType", ctypes.c_ubyte),
("MicrosoftString", ctypes.c_wchar * 7),
("bVendorCode", ctypes.c_ubyte),
("Anonymous", _Anonymous_e__Union),
]#[repr(C)]
pub struct OS_STRING {
pub bLength: u8,
pub bDescriptorType: u8,
pub MicrosoftString: [u16; 7],
pub bVendorCode: u8,
pub Anonymous: _Anonymous_e__Union,
}import "golang.org/x/sys/windows"
type OS_STRING struct {
bLength byte
bDescriptorType byte
MicrosoftString [7]uint16
bVendorCode byte
Anonymous _Anonymous_e__Union
}type
OS_STRING = record
bLength: Byte;
bDescriptorType: Byte;
MicrosoftString: array[0..6] of WideChar;
bVendorCode: Byte;
Anonymous: _Anonymous_e__Union;
end;const OS_STRING = extern struct {
bLength: u8,
bDescriptorType: u8,
MicrosoftString: [7]u16,
bVendorCode: u8,
Anonymous: _Anonymous_e__Union,
};type
OS_STRING {.bycopy.} = object
bLength: uint8
bDescriptorType: uint8
MicrosoftString: array[7, uint16]
bVendorCode: uint8
Anonymous: _Anonymous_e__Unionstruct OS_STRING
{
ubyte bLength;
ubyte bDescriptorType;
wchar[7] MicrosoftString;
ubyte bVendorCode;
_Anonymous_e__Union Anonymous;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; OS_STRING サイズ: 18 バイト(x64)
dim st, 5 ; 4byte整数×5(構造体サイズ 18 / 4 切り上げ)
; bLength : BYTE (+0, 1byte) poke st,0,値 / 値 = peek(st,0)
; bDescriptorType : BYTE (+1, 1byte) poke st,1,値 / 値 = peek(st,1)
; MicrosoftString : WCHAR (+2, 14byte) varptr(st)+2 を基点に操作(14byte:入れ子/配列)
; bVendorCode : BYTE (+16, 1byte) poke st,16,値 / 値 = peek(st,16)
; Anonymous : _Anonymous_e__Union (+17, 1byte) varptr(st)+17 を基点に操作(1byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global OS_STRING
#field byte bLength
#field byte bDescriptorType
#field wchar MicrosoftString 7
#field byte bVendorCode
#field byte Anonymous 1
#endstruct
stdim st, OS_STRING ; NSTRUCT 変数を確保
st->bLength = 100
mes "bLength=" + st->bLength
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。