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

PORT_DATA_2

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

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

フィールド

フィールドサイズx64x86説明
sztPortNameWCHAR128+0+0ポート名を格納するUnicode文字配列。
dwVersionDWORD4+128+128構造体のバージョン番号。
dwProtocolDWORD4+132+132使用する印刷プロトコル(RAWまたはLPR)を示す値。
cbSizeDWORD4+136+136この構造体のサイズをバイト単位で指定する。
dwReservedDWORD4+140+140予約フィールド。0に設定する。
sztHostAddressWCHAR256+144+144プリンターのホストアドレスを格納するUnicode文字配列。
sztSNMPCommunityWCHAR66+400+400SNMPコミュニティ名を格納するUnicode文字配列。
dwDoubleSpoolDWORD4+468+468ダブルスプール(双方向スプール)を有効にするか示すフラグ。
sztQueueWCHAR66+472+472LPRプロトコル時のキュー名を格納するUnicode文字配列。
ReservedBYTE514+538+538予約バイト配列。
dwPortNumberDWORD4+1052+1052RAWプロトコル時のTCPポート番号。
dwSNMPEnabledDWORD4+1056+1056SNMPステータス監視を有効にするか示すフラグ。
dwSNMPDevIndexDWORD4+1060+1060SNMPデバイスインデックス番号。
dwPortMonitorMibIndexDWORD4+1064+1064ポートモニターのMIBインデックス番号。

各言語での定義

#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;
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;
}
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
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),
    ]
#[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,
}
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_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;
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,
};
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
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;
}

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_2 サイズ: 1068 バイト(x64)
dim st, 267    ; 4byte整数×267(構造体サイズ 1068 / 4 切り上げ)
; sztPortName : WCHAR (+0, 128byte)  varptr(st)+0 を基点に操作(128byte:入れ子/配列)
; dwVersion : DWORD (+128, 4byte)  st.32 = 値  /  値 = st.32   (lpoke/lpeek も可)
; dwProtocol : DWORD (+132, 4byte)  st.33 = 値  /  値 = st.33   (lpoke/lpeek も可)
; cbSize : DWORD (+136, 4byte)  st.34 = 値  /  値 = st.34   (lpoke/lpeek も可)
; dwReserved : DWORD (+140, 4byte)  st.35 = 値  /  値 = st.35   (lpoke/lpeek も可)
; sztHostAddress : WCHAR (+144, 256byte)  varptr(st)+144 を基点に操作(256byte:入れ子/配列)
; sztSNMPCommunity : WCHAR (+400, 66byte)  varptr(st)+400 を基点に操作(66byte:入れ子/配列)
; dwDoubleSpool : DWORD (+468, 4byte)  st.117 = 値  /  値 = st.117   (lpoke/lpeek も可)
; sztQueue : WCHAR (+472, 66byte)  varptr(st)+472 を基点に操作(66byte:入れ子/配列)
; Reserved : BYTE (+538, 514byte)  varptr(st)+538 を基点に操作(514byte:入れ子/配列)
; dwPortNumber : DWORD (+1052, 4byte)  st.263 = 値  /  値 = st.263   (lpoke/lpeek も可)
; dwSNMPEnabled : DWORD (+1056, 4byte)  st.264 = 値  /  値 = st.264   (lpoke/lpeek も可)
; dwSNMPDevIndex : DWORD (+1060, 4byte)  st.265 = 値  /  値 = st.265   (lpoke/lpeek も可)
; dwPortMonitorMibIndex : DWORD (+1064, 4byte)  st.266 = 値  /  値 = st.266   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#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

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