Win32 API 日本語リファレンス
ホームStorage.FileSystem › OFSTRUCT

OFSTRUCT

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

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

フィールド

フィールドサイズx64x86説明
cBytesBYTE1+0+0この構造体のバイト長。
fFixedDiskBYTE1+1+1ファイルが固定ディスク上にあれば非0。
nErrCodeWORD2+2+2OpenFile失敗時のMS-DOSエラーコード。
Reserved1WORD2+4+4予約フィールド。
Reserved2WORD2+6+6予約フィールド。
szPathNameCHAR128+8+8ファイルのパス名(OEM文字、ANSIバイト配列)。

各言語での定義

#include <windows.h>

// OFSTRUCT  (x64 136 / x86 136 バイト)
typedef struct OFSTRUCT {
    BYTE cBytes;
    BYTE fFixedDisk;
    WORD nErrCode;
    WORD Reserved1;
    WORD Reserved2;
    CHAR szPathName[128];
} OFSTRUCT;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct OFSTRUCT
{
    public byte cBytes;
    public byte fFixedDisk;
    public ushort nErrCode;
    public ushort Reserved1;
    public ushort Reserved2;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)] public sbyte[] szPathName;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure OFSTRUCT
    Public cBytes As Byte
    Public fFixedDisk As Byte
    Public nErrCode As UShort
    Public Reserved1 As UShort
    Public Reserved2 As UShort
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=128)> Public szPathName() As SByte
End Structure
import ctypes
from ctypes import wintypes

class OFSTRUCT(ctypes.Structure):
    _fields_ = [
        ("cBytes", ctypes.c_ubyte),
        ("fFixedDisk", ctypes.c_ubyte),
        ("nErrCode", ctypes.c_ushort),
        ("Reserved1", ctypes.c_ushort),
        ("Reserved2", ctypes.c_ushort),
        ("szPathName", ctypes.c_byte * 128),
    ]
#[repr(C)]
pub struct OFSTRUCT {
    pub cBytes: u8,
    pub fFixedDisk: u8,
    pub nErrCode: u16,
    pub Reserved1: u16,
    pub Reserved2: u16,
    pub szPathName: [i8; 128],
}
import "golang.org/x/sys/windows"

type OFSTRUCT struct {
	cBytes byte
	fFixedDisk byte
	nErrCode uint16
	Reserved1 uint16
	Reserved2 uint16
	szPathName [128]int8
}
type
  OFSTRUCT = record
    cBytes: Byte;
    fFixedDisk: Byte;
    nErrCode: Word;
    Reserved1: Word;
    Reserved2: Word;
    szPathName: array[0..127] of Shortint;
  end;
const OFSTRUCT = extern struct {
    cBytes: u8,
    fFixedDisk: u8,
    nErrCode: u16,
    Reserved1: u16,
    Reserved2: u16,
    szPathName: [128]i8,
};
type
  OFSTRUCT {.bycopy.} = object
    cBytes: uint8
    fFixedDisk: uint8
    nErrCode: uint16
    Reserved1: uint16
    Reserved2: uint16
    szPathName: array[128, int8]
struct OFSTRUCT
{
    ubyte cBytes;
    ubyte fFixedDisk;
    ushort nErrCode;
    ushort Reserved1;
    ushort Reserved2;
    byte[128] szPathName;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; OFSTRUCT サイズ: 136 バイト(x64)
dim st, 34    ; 4byte整数×34(構造体サイズ 136 / 4 切り上げ)
; cBytes : BYTE (+0, 1byte)  poke st,0,値  /  値 = peek(st,0)
; fFixedDisk : BYTE (+1, 1byte)  poke st,1,値  /  値 = peek(st,1)
; nErrCode : WORD (+2, 2byte)  wpoke st,2,値  /  値 = wpeek(st,2)
; Reserved1 : WORD (+4, 2byte)  wpoke st,4,値  /  値 = wpeek(st,4)
; Reserved2 : WORD (+6, 2byte)  wpoke st,6,値  /  値 = wpeek(st,6)
; szPathName : CHAR (+8, 128byte)  varptr(st)+8 を基点に操作(128byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global OFSTRUCT
    #field byte cBytes
    #field byte fFixedDisk
    #field short nErrCode
    #field short Reserved1
    #field short Reserved2
    #field byte szPathName 128
#endstruct

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