Win32 API 日本語リファレンス
ホームNetworkManagement.Snmp › AsnAny

AsnAny

構造体
サイズx64: 20 バイト / x86: 16 バイトパッキング4

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

フィールド

フィールドサイズx64x86説明
asnTypeBYTE1+0+0値の ASN.1 型を示すタグバイト。整数・文字列などの種別を表す。
asnValue_asnValue_e__Union16/12+4+4asnType に応じた実際の値を保持する共用体。

共用体: _asnValue_e__Union x64 16B / x86 12B

フィールドサイズx64x86
numberINT4+0+0
unsigned32DWORD4+0+0
counter64ULONGLONG8+0+0
stringAsnOctetString16/12+0+0
bitsAsnOctetString16/12+0+0
objectAsnObjectIdentifier12/8+0+0
sequenceAsnOctetString16/12+0+0
addressAsnOctetString16/12+0+0
counterDWORD4+0+0
gaugeDWORD4+0+0
ticksDWORD4+0+0
arbitraryAsnOctetString16/12+0+0

各言語での定義

#include <windows.h>

// AsnAny  (x64 20 / x86 16 バイト)
#pragma pack(push, 4)
typedef struct AsnAny {
    BYTE asnType;
    _asnValue_e__Union asnValue;
} AsnAny;
#pragma pack(pop)
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Unicode)]
public struct AsnAny
{
    public byte asnType;
    public _asnValue_e__Union asnValue;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)>
Public Structure AsnAny
    Public asnType As Byte
    Public asnValue As _asnValue_e__Union
End Structure
import ctypes
from ctypes import wintypes

class AsnAny(ctypes.Structure):
    _pack_ = 4
    _fields_ = [
        ("asnType", ctypes.c_ubyte),
        ("asnValue", _asnValue_e__Union),
    ]
#[repr(C, packed(4))]
pub struct AsnAny {
    pub asnType: u8,
    pub asnValue: _asnValue_e__Union,
}
import "golang.org/x/sys/windows"

type AsnAny struct {
	asnType byte
	asnValue _asnValue_e__Union
}
type
  AsnAny = packed record
    asnType: Byte;
    asnValue: _asnValue_e__Union;
  end;
const AsnAny = extern struct {
    asnType: u8,
    asnValue: _asnValue_e__Union,
};
type
  AsnAny {.packed.} = object
    asnType: uint8
    asnValue: _asnValue_e__Union
align(4)
struct AsnAny
{
    ubyte asnType;
    _asnValue_e__Union asnValue;
}

HSP用 定義

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

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

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