ホーム › Devices.DeviceAndDriverInstallation › MEM_RESOURCE
MEM_RESOURCE
構造体サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。
フィールド
| フィールド | 型 | サイズ | x64 | x86 | 説明 |
|---|---|---|---|---|---|
| MEM_Header | MEM_DES | 32 | +0 | +0 | メモリリソースの記述子ヘッダ(MEM_DES)。 |
| MEM_Data | MEM_RANGE | 36 | +32 | +32 | メモリ範囲データの先頭(MEM_RANGE)。可変長配列の起点。 |
各言語での定義
#include <windows.h>
// MEM_DES (x64 32 / x86 32 バイト)
#pragma pack(push, 1)
typedef struct MEM_DES {
DWORD MD_Count;
DWORD MD_Type;
ULONGLONG MD_Alloc_Base;
ULONGLONG MD_Alloc_End;
MD_FLAGS MD_Flags;
DWORD MD_Reserved;
} MEM_DES;
#pragma pack(pop)
// MEM_RANGE (x64 36 / x86 36 バイト)
#pragma pack(push, 1)
typedef struct MEM_RANGE {
ULONGLONG MR_Align;
DWORD MR_nBytes;
ULONGLONG MR_Min;
ULONGLONG MR_Max;
MD_FLAGS MR_Flags;
DWORD MR_Reserved;
} MEM_RANGE;
#pragma pack(pop)
// MEM_RESOURCE (x64 68 / x86 68 バイト)
#pragma pack(push, 1)
typedef struct MEM_RESOURCE {
MEM_DES MEM_Header;
MEM_RANGE MEM_Data[1];
} MEM_RESOURCE;
#pragma pack(pop)using System;
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct MEM_DES
{
public uint MD_Count;
public uint MD_Type;
public ulong MD_Alloc_Base;
public ulong MD_Alloc_End;
public uint MD_Flags;
public uint MD_Reserved;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct MEM_RANGE
{
public ulong MR_Align;
public uint MR_nBytes;
public ulong MR_Min;
public ulong MR_Max;
public uint MR_Flags;
public uint MR_Reserved;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Unicode)]
public struct MEM_RESOURCE
{
public MEM_DES MEM_Header;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public MEM_RANGE[] MEM_Data;
}Imports System.Runtime.InteropServices
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure MEM_DES
Public MD_Count As UInteger
Public MD_Type As UInteger
Public MD_Alloc_Base As ULong
Public MD_Alloc_End As ULong
Public MD_Flags As UInteger
Public MD_Reserved As UInteger
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure MEM_RANGE
Public MR_Align As ULong
Public MR_nBytes As UInteger
Public MR_Min As ULong
Public MR_Max As ULong
Public MR_Flags As UInteger
Public MR_Reserved As UInteger
End Structure
<StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Unicode)>
Public Structure MEM_RESOURCE
Public MEM_Header As MEM_DES
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public MEM_Data() As MEM_RANGE
End Structureimport ctypes
from ctypes import wintypes
class MEM_DES(ctypes.Structure):
_pack_ = 1
_fields_ = [
("MD_Count", wintypes.DWORD),
("MD_Type", wintypes.DWORD),
("MD_Alloc_Base", ctypes.c_ulonglong),
("MD_Alloc_End", ctypes.c_ulonglong),
("MD_Flags", wintypes.DWORD),
("MD_Reserved", wintypes.DWORD),
]
class MEM_RANGE(ctypes.Structure):
_pack_ = 1
_fields_ = [
("MR_Align", ctypes.c_ulonglong),
("MR_nBytes", wintypes.DWORD),
("MR_Min", ctypes.c_ulonglong),
("MR_Max", ctypes.c_ulonglong),
("MR_Flags", wintypes.DWORD),
("MR_Reserved", wintypes.DWORD),
]
class MEM_RESOURCE(ctypes.Structure):
_pack_ = 1
_fields_ = [
("MEM_Header", MEM_DES),
("MEM_Data", MEM_RANGE * 1),
]#[repr(C, packed(1))]
pub struct MEM_DES {
pub MD_Count: u32,
pub MD_Type: u32,
pub MD_Alloc_Base: u64,
pub MD_Alloc_End: u64,
pub MD_Flags: u32,
pub MD_Reserved: u32,
}
#[repr(C, packed(1))]
pub struct MEM_RANGE {
pub MR_Align: u64,
pub MR_nBytes: u32,
pub MR_Min: u64,
pub MR_Max: u64,
pub MR_Flags: u32,
pub MR_Reserved: u32,
}
#[repr(C, packed(1))]
pub struct MEM_RESOURCE {
pub MEM_Header: MEM_DES,
pub MEM_Data: [MEM_RANGE; 1],
}import "golang.org/x/sys/windows"
type MEM_DES struct {
MD_Count uint32
MD_Type uint32
MD_Alloc_Base uint64
MD_Alloc_End uint64
MD_Flags uint32
MD_Reserved uint32
}
type MEM_RANGE struct {
MR_Align uint64
MR_nBytes uint32
MR_Min uint64
MR_Max uint64
MR_Flags uint32
MR_Reserved uint32
}
type MEM_RESOURCE struct {
MEM_Header MEM_DES
MEM_Data [1]MEM_RANGE
}type
MEM_DES = packed record
MD_Count: DWORD;
MD_Type: DWORD;
MD_Alloc_Base: UInt64;
MD_Alloc_End: UInt64;
MD_Flags: DWORD;
MD_Reserved: DWORD;
end;
MEM_RANGE = packed record
MR_Align: UInt64;
MR_nBytes: DWORD;
MR_Min: UInt64;
MR_Max: UInt64;
MR_Flags: DWORD;
MR_Reserved: DWORD;
end;
MEM_RESOURCE = packed record
MEM_Header: MEM_DES;
MEM_Data: array[0..0] of MEM_RANGE;
end;const MEM_DES = extern struct {
MD_Count: u32,
MD_Type: u32,
MD_Alloc_Base: u64,
MD_Alloc_End: u64,
MD_Flags: u32,
MD_Reserved: u32,
};
const MEM_RANGE = extern struct {
MR_Align: u64,
MR_nBytes: u32,
MR_Min: u64,
MR_Max: u64,
MR_Flags: u32,
MR_Reserved: u32,
};
const MEM_RESOURCE = extern struct {
MEM_Header: MEM_DES,
MEM_Data: [1]MEM_RANGE,
};type
MEM_DES {.packed.} = object
MD_Count: uint32
MD_Type: uint32
MD_Alloc_Base: uint64
MD_Alloc_End: uint64
MD_Flags: uint32
MD_Reserved: uint32
MEM_RANGE {.packed.} = object
MR_Align: uint64
MR_nBytes: uint32
MR_Min: uint64
MR_Max: uint64
MR_Flags: uint32
MR_Reserved: uint32
MEM_RESOURCE {.packed.} = object
MEM_Header: MEM_DES
MEM_Data: array[1, MEM_RANGE]align(1)
struct MEM_DES
{
uint MD_Count;
uint MD_Type;
ulong MD_Alloc_Base;
ulong MD_Alloc_End;
uint MD_Flags;
uint MD_Reserved;
}
align(1)
struct MEM_RANGE
{
ulong MR_Align;
uint MR_nBytes;
ulong MR_Min;
ulong MR_Max;
uint MR_Flags;
uint MR_Reserved;
}
align(1)
struct MEM_RESOURCE
{
MEM_DES MEM_Header;
MEM_RANGE[1] MEM_Data;
}HSP用 定義
HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; MEM_RESOURCE サイズ: 68 バイト(x64)
dim st, 17 ; 4byte整数×17(構造体サイズ 68 / 4 切り上げ)
; MEM_Header : MEM_DES (+0, 32byte) varptr(st)+0 を基点に操作(32byte:入れ子/配列)
; MEM_Data : MEM_RANGE (+32, 36byte) varptr(st)+32 を基点に操作(36byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global MEM_DES, pack=1
#field int MD_Count
#field int MD_Type
#field int64 MD_Alloc_Base
#field int64 MD_Alloc_End
#field int MD_Flags
#field int MD_Reserved
#endstruct
#defstruct global MEM_RANGE, pack=1
#field int64 MR_Align
#field int MR_nBytes
#field int64 MR_Min
#field int64 MR_Max
#field int MR_Flags
#field int MR_Reserved
#endstruct
#defstruct global MEM_RESOURCE, pack=1
#field MEM_DES MEM_Header
#field MEM_RANGE MEM_Data 1
#endstruct
stdim st, MEM_RESOURCE ; NSTRUCT 変数を確保