ホーム › System.Ole › _wireSAFEARRAY
_wireSAFEARRAY
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 |
|---|---|---|---|---|
| cDims | WORD | 2 | +0 | +0 |
| fFeatures | WORD | 2 | +2 | +2 |
| cbElements | DWORD | 4 | +4 | +4 |
| cLocks | DWORD | 4 | +8 | +8 |
| uArrayStructs | SAFEARRAYUNION | 40/28 | +16 | +12 |
| rgsabound | SAFEARRAYBOUND | 8 | +56 | +40 |
各言語での定義
#include <windows.h>
// SAFEARRAYUNION (x64 40 / x86 28 バイト)
typedef struct SAFEARRAYUNION {
DWORD sfType;
_u_e__Struct u;
} SAFEARRAYUNION;
// SAFEARRAYBOUND (x64 8 / x86 8 バイト)
typedef struct SAFEARRAYBOUND {
DWORD cElements;
INT lLbound;
} SAFEARRAYBOUND;
// _wireSAFEARRAY (x64 64 / x86 48 バイト)
typedef struct _wireSAFEARRAY {
WORD cDims;
WORD fFeatures;
DWORD cbElements;
DWORD cLocks;
SAFEARRAYUNION uArrayStructs;
SAFEARRAYBOUND rgsabound[1];
} _wireSAFEARRAY;using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SAFEARRAYUNION
{
public uint sfType;
public _u_e__Struct u;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SAFEARRAYBOUND
{
public uint cElements;
public int lLbound;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct _wireSAFEARRAY
{
public ushort cDims;
public ushort fFeatures;
public uint cbElements;
public uint cLocks;
public SAFEARRAYUNION uArrayStructs;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public SAFEARRAYBOUND[] rgsabound;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SAFEARRAYUNION
Public sfType As UInteger
Public u As _u_e__Struct
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SAFEARRAYBOUND
Public cElements As UInteger
Public lLbound As Integer
End Structure
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure _wireSAFEARRAY
Public cDims As UShort
Public fFeatures As UShort
Public cbElements As UInteger
Public cLocks As UInteger
Public uArrayStructs As SAFEARRAYUNION
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public rgsabound() As SAFEARRAYBOUND
End Structureimport ctypes
from ctypes import wintypes
class SAFEARRAYUNION(ctypes.Structure):
_fields_ = [
("sfType", wintypes.DWORD),
("u", _u_e__Struct),
]
class SAFEARRAYBOUND(ctypes.Structure):
_fields_ = [
("cElements", wintypes.DWORD),
("lLbound", ctypes.c_int),
]
class _wireSAFEARRAY(ctypes.Structure):
_fields_ = [
("cDims", ctypes.c_ushort),
("fFeatures", ctypes.c_ushort),
("cbElements", wintypes.DWORD),
("cLocks", wintypes.DWORD),
("uArrayStructs", SAFEARRAYUNION),
("rgsabound", SAFEARRAYBOUND * 1),
]#[repr(C)]
pub struct SAFEARRAYUNION {
pub sfType: u32,
pub u: _u_e__Struct,
}
#[repr(C)]
pub struct SAFEARRAYBOUND {
pub cElements: u32,
pub lLbound: i32,
}
#[repr(C)]
pub struct _wireSAFEARRAY {
pub cDims: u16,
pub fFeatures: u16,
pub cbElements: u32,
pub cLocks: u32,
pub uArrayStructs: SAFEARRAYUNION,
pub rgsabound: [SAFEARRAYBOUND; 1],
}import "golang.org/x/sys/windows"
type SAFEARRAYUNION struct {
sfType uint32
u _u_e__Struct
}
type SAFEARRAYBOUND struct {
cElements uint32
lLbound int32
}
type _wireSAFEARRAY struct {
cDims uint16
fFeatures uint16
cbElements uint32
cLocks uint32
uArrayStructs SAFEARRAYUNION
rgsabound [1]SAFEARRAYBOUND
}type
SAFEARRAYUNION = record
sfType: DWORD;
u: _u_e__Struct;
end;
SAFEARRAYBOUND = record
cElements: DWORD;
lLbound: Integer;
end;
_wireSAFEARRAY = record
cDims: Word;
fFeatures: Word;
cbElements: DWORD;
cLocks: DWORD;
uArrayStructs: SAFEARRAYUNION;
rgsabound: array[0..0] of SAFEARRAYBOUND;
end;const SAFEARRAYUNION = extern struct {
sfType: u32,
u: _u_e__Struct,
};
const SAFEARRAYBOUND = extern struct {
cElements: u32,
lLbound: i32,
};
const _wireSAFEARRAY = extern struct {
cDims: u16,
fFeatures: u16,
cbElements: u32,
cLocks: u32,
uArrayStructs: SAFEARRAYUNION,
rgsabound: [1]SAFEARRAYBOUND,
};type
SAFEARRAYUNION {.bycopy.} = object
sfType: uint32
u: _u_e__Struct
SAFEARRAYBOUND {.bycopy.} = object
cElements: uint32
lLbound: int32
_wireSAFEARRAY {.bycopy.} = object
cDims: uint16
fFeatures: uint16
cbElements: uint32
cLocks: uint32
uArrayStructs: SAFEARRAYUNION
rgsabound: array[1, SAFEARRAYBOUND]struct SAFEARRAYUNION
{
uint sfType;
_u_e__Struct u;
}
struct SAFEARRAYBOUND
{
uint cElements;
int lLbound;
}
struct _wireSAFEARRAY
{
ushort cDims;
ushort fFeatures;
uint cbElements;
uint cLocks;
SAFEARRAYUNION uArrayStructs;
SAFEARRAYBOUND[1] rgsabound;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; _wireSAFEARRAY サイズ: 48 バイト(x86)
dim st, 12 ; 4byte整数×12(構造体サイズ 48 / 4 切り上げ)
; cDims : WORD (+0, 2byte) wpoke st,0,値 / 値 = wpeek(st,0)
; fFeatures : WORD (+2, 2byte) wpoke st,2,値 / 値 = wpeek(st,2)
; cbElements : DWORD (+4, 4byte) st.1 = 値 / 値 = st.1 (lpoke/lpeek も可)
; cLocks : DWORD (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; uArrayStructs : SAFEARRAYUNION (+12, 28byte) varptr(st)+12 を基点に操作(28byte:入れ子/配列)
; rgsabound : SAFEARRAYBOUND (+40, 8byte) varptr(st)+40 を基点に操作(8byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; _wireSAFEARRAY サイズ: 64 バイト(x64)
dim st, 16 ; 4byte整数×16(構造体サイズ 64 / 4 切り上げ)
; cDims : WORD (+0, 2byte) wpoke st,0,値 / 値 = wpeek(st,0)
; fFeatures : WORD (+2, 2byte) wpoke st,2,値 / 値 = wpeek(st,2)
; cbElements : DWORD (+4, 4byte) st.1 = 値 / 値 = st.1 (lpoke/lpeek も可)
; cLocks : DWORD (+8, 4byte) st.2 = 値 / 値 = st.2 (lpoke/lpeek も可)
; uArrayStructs : SAFEARRAYUNION (+16, 40byte) varptr(st)+16 を基点に操作(40byte:入れ子/配列)
; rgsabound : SAFEARRAYBOUND (+56, 8byte) varptr(st)+56 を基点に操作(8byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global SAFEARRAYUNION
#field int sfType
#field byte u 32
#endstruct
#defstruct global SAFEARRAYBOUND
#field int cElements
#field int lLbound
#endstruct
#defstruct global _wireSAFEARRAY
#field short cDims
#field short fFeatures
#field int cbElements
#field int cLocks
#field SAFEARRAYUNION uArrayStructs
#field SAFEARRAYBOUND rgsabound 1
#endstruct
stdim st, _wireSAFEARRAY ; NSTRUCT 変数を確保
st->cDims = 100
mes "cDims=" + st->cDims