ホーム › System.Ole › SAFEARRAYUNION
SAFEARRAYUNION
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| sfType | DWORD | 4 | +0 | +0 | 共用体uが保持する要素の種類を示す判別子(SF_TYPEフラグ)である。 |
| u | _u_e__Struct | 32/24 | +8 | +4 | sfTypeに応じた配列データ表現を保持する共用体である。 |
共用体: _u_e__Struct x64 32B / x86 24B
| フィールド | 型 | サイズ | x64 | x86 |
|---|---|---|---|---|
| BstrStr | SAFEARR_BSTR | 16/8 | +0 | +0 |
| UnknownStr | SAFEARR_UNKNOWN | 16/8 | +0 | +0 |
| DispatchStr | SAFEARR_DISPATCH | 16/8 | +0 | +0 |
| VariantStr | SAFEARR_VARIANT | 16/8 | +0 | +0 |
| RecordStr | SAFEARR_BRECORD | 16/8 | +0 | +0 |
| HaveIidStr | SAFEARR_HAVEIID | 32/24 | +0 | +0 |
| ByteStr | BYTE_SIZEDARR | 16/8 | +0 | +0 |
| WordStr | WORD_SIZEDARR | 16/8 | +0 | +0 |
| LongStr | DWORD_SIZEDARR | 16/8 | +0 | +0 |
| HyperStr | HYPER_SIZEDARR | 16/8 | +0 | +0 |
各言語での定義
#include <windows.h>
// SAFEARRAYUNION (x64 40 / x86 28 バイト)
typedef struct SAFEARRAYUNION {
DWORD sfType;
_u_e__Struct u;
} SAFEARRAYUNION;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SAFEARRAYUNION
{
public uint sfType;
public _u_e__Struct u;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SAFEARRAYUNION
Public sfType As UInteger
Public u As _u_e__Struct
End Structureimport ctypes
from ctypes import wintypes
class SAFEARRAYUNION(ctypes.Structure):
_fields_ = [
("sfType", wintypes.DWORD),
("u", _u_e__Struct),
]#[repr(C)]
pub struct SAFEARRAYUNION {
pub sfType: u32,
pub u: _u_e__Struct,
}import "golang.org/x/sys/windows"
type SAFEARRAYUNION struct {
sfType uint32
u _u_e__Struct
}type
SAFEARRAYUNION = record
sfType: DWORD;
u: _u_e__Struct;
end;const SAFEARRAYUNION = extern struct {
sfType: u32,
u: _u_e__Struct,
};type
SAFEARRAYUNION {.bycopy.} = object
sfType: uint32
u: _u_e__Structstruct SAFEARRAYUNION
{
uint sfType;
_u_e__Struct u;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; SAFEARRAYUNION サイズ: 28 バイト(x86)
dim st, 7 ; 4byte整数×7(構造体サイズ 28 / 4 切り上げ)
; sfType : DWORD (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; u : _u_e__Struct (+4, 24byte) varptr(st)+4 を基点に操作(24byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; SAFEARRAYUNION サイズ: 40 バイト(x64)
dim st, 10 ; 4byte整数×10(構造体サイズ 40 / 4 切り上げ)
; sfType : DWORD (+0, 4byte) st.0 = 値 / 値 = st.0 (lpoke/lpeek も可)
; u : _u_e__Struct (+8, 32byte) varptr(st)+8 を基点に操作(32byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global SAFEARRAYUNION
#field int sfType
#field byte u 32
#endstruct
stdim st, SAFEARRAYUNION ; NSTRUCT 変数を確保
st->sfType = 100
mes "sfType=" + st->sfType
; ※union フィールドは byte 列で確保(NSTRUCT は union 非対応)。必要に応じ手動でアクセス。