Win32 API 日本語リファレンス
ホームGraphics.Printing › PORT_DATA_LIST_1

PORT_DATA_LIST_1

構造体
サイズx64: 1076 バイト / x86: 1076 バイト

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

フィールド

フィールドサイズx64x86説明
dwVersionDWORD4+0+0構造体のバージョン番号。
cPortDataDWORD4+4+4pPortData配列に含まれるポートデータの数。
pPortDataPORT_DATA_21068+8+8ポート設定を表すPORT_DATA_2の可変長配列。

各言語での定義

#include <windows.h>

// PORT_DATA_2  (x64 1068 / x86 1068 バイト)
typedef struct PORT_DATA_2 {
    WCHAR sztPortName[64];
    DWORD dwVersion;
    DWORD dwProtocol;
    DWORD cbSize;
    DWORD dwReserved;
    WCHAR sztHostAddress[128];
    WCHAR sztSNMPCommunity[33];
    DWORD dwDoubleSpool;
    WCHAR sztQueue[33];
    BYTE Reserved[514];
    DWORD dwPortNumber;
    DWORD dwSNMPEnabled;
    DWORD dwSNMPDevIndex;
    DWORD dwPortMonitorMibIndex;
} PORT_DATA_2;

// PORT_DATA_LIST_1  (x64 1076 / x86 1076 バイト)
typedef struct PORT_DATA_LIST_1 {
    DWORD dwVersion;
    DWORD cPortData;
    PORT_DATA_2 pPortData[1];
} PORT_DATA_LIST_1;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct PORT_DATA_2
{
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string sztPortName;
    public uint dwVersion;
    public uint dwProtocol;
    public uint cbSize;
    public uint dwReserved;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)] public string sztHostAddress;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 33)] public string sztSNMPCommunity;
    public uint dwDoubleSpool;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 33)] public string sztQueue;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 514)] public byte[] Reserved;
    public uint dwPortNumber;
    public uint dwSNMPEnabled;
    public uint dwSNMPDevIndex;
    public uint dwPortMonitorMibIndex;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct PORT_DATA_LIST_1
{
    public uint dwVersion;
    public uint cPortData;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public PORT_DATA_2[] pPortData;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure PORT_DATA_2
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=64)> Public sztPortName As String
    Public dwVersion As UInteger
    Public dwProtocol As UInteger
    Public cbSize As UInteger
    Public dwReserved As UInteger
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> Public sztHostAddress As String
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=33)> Public sztSNMPCommunity As String
    Public dwDoubleSpool As UInteger
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=33)> Public sztQueue As String
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=514)> Public Reserved() As Byte
    Public dwPortNumber As UInteger
    Public dwSNMPEnabled As UInteger
    Public dwSNMPDevIndex As UInteger
    Public dwPortMonitorMibIndex As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure PORT_DATA_LIST_1
    Public dwVersion As UInteger
    Public cPortData As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public pPortData() As PORT_DATA_2
End Structure
import ctypes
from ctypes import wintypes

class PORT_DATA_2(ctypes.Structure):
    _fields_ = [
        ("sztPortName", ctypes.c_wchar * 64),
        ("dwVersion", wintypes.DWORD),
        ("dwProtocol", wintypes.DWORD),
        ("cbSize", wintypes.DWORD),
        ("dwReserved", wintypes.DWORD),
        ("sztHostAddress", ctypes.c_wchar * 128),
        ("sztSNMPCommunity", ctypes.c_wchar * 33),
        ("dwDoubleSpool", wintypes.DWORD),
        ("sztQueue", ctypes.c_wchar * 33),
        ("Reserved", ctypes.c_ubyte * 514),
        ("dwPortNumber", wintypes.DWORD),
        ("dwSNMPEnabled", wintypes.DWORD),
        ("dwSNMPDevIndex", wintypes.DWORD),
        ("dwPortMonitorMibIndex", wintypes.DWORD),
    ]

class PORT_DATA_LIST_1(ctypes.Structure):
    _fields_ = [
        ("dwVersion", wintypes.DWORD),
        ("cPortData", wintypes.DWORD),
        ("pPortData", PORT_DATA_2 * 1),
    ]
#[repr(C)]
pub struct PORT_DATA_2 {
    pub sztPortName: [u16; 64],
    pub dwVersion: u32,
    pub dwProtocol: u32,
    pub cbSize: u32,
    pub dwReserved: u32,
    pub sztHostAddress: [u16; 128],
    pub sztSNMPCommunity: [u16; 33],
    pub dwDoubleSpool: u32,
    pub sztQueue: [u16; 33],
    pub Reserved: [u8; 514],
    pub dwPortNumber: u32,
    pub dwSNMPEnabled: u32,
    pub dwSNMPDevIndex: u32,
    pub dwPortMonitorMibIndex: u32,
}

#[repr(C)]
pub struct PORT_DATA_LIST_1 {
    pub dwVersion: u32,
    pub cPortData: u32,
    pub pPortData: [PORT_DATA_2; 1],
}
import "golang.org/x/sys/windows"

type PORT_DATA_2 struct {
	sztPortName [64]uint16
	dwVersion uint32
	dwProtocol uint32
	cbSize uint32
	dwReserved uint32
	sztHostAddress [128]uint16
	sztSNMPCommunity [33]uint16
	dwDoubleSpool uint32
	sztQueue [33]uint16
	Reserved [514]byte
	dwPortNumber uint32
	dwSNMPEnabled uint32
	dwSNMPDevIndex uint32
	dwPortMonitorMibIndex uint32
}

type PORT_DATA_LIST_1 struct {
	dwVersion uint32
	cPortData uint32
	pPortData [1]PORT_DATA_2
}
type
  PORT_DATA_2 = record
    sztPortName: array[0..63] of WideChar;
    dwVersion: DWORD;
    dwProtocol: DWORD;
    cbSize: DWORD;
    dwReserved: DWORD;
    sztHostAddress: array[0..127] of WideChar;
    sztSNMPCommunity: array[0..32] of WideChar;
    dwDoubleSpool: DWORD;
    sztQueue: array[0..32] of WideChar;
    Reserved: array[0..513] of Byte;
    dwPortNumber: DWORD;
    dwSNMPEnabled: DWORD;
    dwSNMPDevIndex: DWORD;
    dwPortMonitorMibIndex: DWORD;
  end;

  PORT_DATA_LIST_1 = record
    dwVersion: DWORD;
    cPortData: DWORD;
    pPortData: array[0..0] of PORT_DATA_2;
  end;
const PORT_DATA_2 = extern struct {
    sztPortName: [64]u16,
    dwVersion: u32,
    dwProtocol: u32,
    cbSize: u32,
    dwReserved: u32,
    sztHostAddress: [128]u16,
    sztSNMPCommunity: [33]u16,
    dwDoubleSpool: u32,
    sztQueue: [33]u16,
    Reserved: [514]u8,
    dwPortNumber: u32,
    dwSNMPEnabled: u32,
    dwSNMPDevIndex: u32,
    dwPortMonitorMibIndex: u32,
};

const PORT_DATA_LIST_1 = extern struct {
    dwVersion: u32,
    cPortData: u32,
    pPortData: [1]PORT_DATA_2,
};
type
  PORT_DATA_2 {.bycopy.} = object
    sztPortName: array[64, uint16]
    dwVersion: uint32
    dwProtocol: uint32
    cbSize: uint32
    dwReserved: uint32
    sztHostAddress: array[128, uint16]
    sztSNMPCommunity: array[33, uint16]
    dwDoubleSpool: uint32
    sztQueue: array[33, uint16]
    Reserved: array[514, uint8]
    dwPortNumber: uint32
    dwSNMPEnabled: uint32
    dwSNMPDevIndex: uint32
    dwPortMonitorMibIndex: uint32

  PORT_DATA_LIST_1 {.bycopy.} = object
    dwVersion: uint32
    cPortData: uint32
    pPortData: array[1, PORT_DATA_2]
struct PORT_DATA_2
{
    wchar[64] sztPortName;
    uint dwVersion;
    uint dwProtocol;
    uint cbSize;
    uint dwReserved;
    wchar[128] sztHostAddress;
    wchar[33] sztSNMPCommunity;
    uint dwDoubleSpool;
    wchar[33] sztQueue;
    ubyte[514] Reserved;
    uint dwPortNumber;
    uint dwSNMPEnabled;
    uint dwSNMPDevIndex;
    uint dwPortMonitorMibIndex;
}

struct PORT_DATA_LIST_1
{
    uint dwVersion;
    uint cPortData;
    PORT_DATA_2[1] pPortData;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; PORT_DATA_LIST_1 サイズ: 1076 バイト(x64)
dim st, 269    ; 4byte整数×269(構造体サイズ 1076 / 4 切り上げ)
; dwVersion : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; cPortData : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; pPortData : PORT_DATA_2 (+8, 1068byte)  varptr(st)+8 を基点に操作(1068byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global PORT_DATA_2
    #field wchar sztPortName 64
    #field int dwVersion
    #field int dwProtocol
    #field int cbSize
    #field int dwReserved
    #field wchar sztHostAddress 128
    #field wchar sztSNMPCommunity 33
    #field int dwDoubleSpool
    #field wchar sztQueue 33
    #field byte Reserved 514
    #field int dwPortNumber
    #field int dwSNMPEnabled
    #field int dwSNMPDevIndex
    #field int dwPortMonitorMibIndex
#endstruct

#defstruct global PORT_DATA_LIST_1
    #field int dwVersion
    #field int cPortData
    #field PORT_DATA_2 pPortData 1
#endstruct

stdim st, PORT_DATA_LIST_1        ; NSTRUCT 変数を確保
st->dwVersion = 100
mes "dwVersion=" + st->dwVersion