Win32 API 日本語リファレンス
ホームSystem.Power › POWER_ADAPTER_STATUS

POWER_ADAPTER_STATUS

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

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

フィールド

フィールドサイズx64x86説明
VersionBYTE1+0+0構造体のバージョン番号である。
ReservedBYTE3+1+1予約フィールドである。0となる。
PowerStatePOWER_ADAPTER_POWER_STATES4+4+4アダプタの電源状態(POWER_ADAPTER_POWER_STATES)である。
PeakPowerDWORD4+8+8アダプタのピーク出力電力(mW)である。
MaxOutputPowerDWORD4+12+12アダプタの最大出力電力(mW)である。
MaxInputPowerDWORD4+16+16アダプタの最大入力電力(mW)である。
RecStartTimeULONGLONG8+24+24推奨動作期間の開始時刻である。
RecEndTimeULONGLONG8+32+32推奨動作期間の終了時刻である。

各言語での定義

#include <windows.h>

// POWER_ADAPTER_POWER_STATES  (x64 4 / x86 4 バイト)
typedef struct POWER_ADAPTER_POWER_STATES {
    _States_e__Struct States;
    DWORD AsUlong;
} POWER_ADAPTER_POWER_STATES;

// POWER_ADAPTER_STATUS  (x64 40 / x86 40 バイト)
typedef struct POWER_ADAPTER_STATUS {
    BYTE Version;
    BYTE Reserved[3];
    POWER_ADAPTER_POWER_STATES PowerState;
    DWORD PeakPower;
    DWORD MaxOutputPower;
    DWORD MaxInputPower;
    ULONGLONG RecStartTime;
    ULONGLONG RecEndTime;
} POWER_ADAPTER_STATUS;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct POWER_ADAPTER_POWER_STATES
{
    public _States_e__Struct States;
    public uint AsUlong;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct POWER_ADAPTER_STATUS
{
    public byte Version;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public byte[] Reserved;
    public POWER_ADAPTER_POWER_STATES PowerState;
    public uint PeakPower;
    public uint MaxOutputPower;
    public uint MaxInputPower;
    public ulong RecStartTime;
    public ulong RecEndTime;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure POWER_ADAPTER_POWER_STATES
    Public States As _States_e__Struct
    Public AsUlong As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure POWER_ADAPTER_STATUS
    Public Version As Byte
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> Public Reserved() As Byte
    Public PowerState As POWER_ADAPTER_POWER_STATES
    Public PeakPower As UInteger
    Public MaxOutputPower As UInteger
    Public MaxInputPower As UInteger
    Public RecStartTime As ULong
    Public RecEndTime As ULong
End Structure
import ctypes
from ctypes import wintypes

class POWER_ADAPTER_POWER_STATES(ctypes.Structure):
    _fields_ = [
        ("States", _States_e__Struct),
        ("AsUlong", wintypes.DWORD),
    ]

class POWER_ADAPTER_STATUS(ctypes.Structure):
    _fields_ = [
        ("Version", ctypes.c_ubyte),
        ("Reserved", ctypes.c_ubyte * 3),
        ("PowerState", POWER_ADAPTER_POWER_STATES),
        ("PeakPower", wintypes.DWORD),
        ("MaxOutputPower", wintypes.DWORD),
        ("MaxInputPower", wintypes.DWORD),
        ("RecStartTime", ctypes.c_ulonglong),
        ("RecEndTime", ctypes.c_ulonglong),
    ]
#[repr(C)]
pub struct POWER_ADAPTER_POWER_STATES {
    pub States: _States_e__Struct,
    pub AsUlong: u32,
}

#[repr(C)]
pub struct POWER_ADAPTER_STATUS {
    pub Version: u8,
    pub Reserved: [u8; 3],
    pub PowerState: POWER_ADAPTER_POWER_STATES,
    pub PeakPower: u32,
    pub MaxOutputPower: u32,
    pub MaxInputPower: u32,
    pub RecStartTime: u64,
    pub RecEndTime: u64,
}
import "golang.org/x/sys/windows"

type POWER_ADAPTER_POWER_STATES struct {
	States _States_e__Struct
	AsUlong uint32
}

type POWER_ADAPTER_STATUS struct {
	Version byte
	Reserved [3]byte
	PowerState POWER_ADAPTER_POWER_STATES
	PeakPower uint32
	MaxOutputPower uint32
	MaxInputPower uint32
	RecStartTime uint64
	RecEndTime uint64
}
type
  POWER_ADAPTER_POWER_STATES = record
    States: _States_e__Struct;
    AsUlong: DWORD;
  end;

  POWER_ADAPTER_STATUS = record
    Version: Byte;
    Reserved: array[0..2] of Byte;
    PowerState: POWER_ADAPTER_POWER_STATES;
    PeakPower: DWORD;
    MaxOutputPower: DWORD;
    MaxInputPower: DWORD;
    RecStartTime: UInt64;
    RecEndTime: UInt64;
  end;
const POWER_ADAPTER_POWER_STATES = extern struct {
    States: _States_e__Struct,
    AsUlong: u32,
};

const POWER_ADAPTER_STATUS = extern struct {
    Version: u8,
    Reserved: [3]u8,
    PowerState: POWER_ADAPTER_POWER_STATES,
    PeakPower: u32,
    MaxOutputPower: u32,
    MaxInputPower: u32,
    RecStartTime: u64,
    RecEndTime: u64,
};
type
  POWER_ADAPTER_POWER_STATES {.bycopy.} = object
    States: _States_e__Struct
    AsUlong: uint32

  POWER_ADAPTER_STATUS {.bycopy.} = object
    Version: uint8
    Reserved: array[3, uint8]
    PowerState: POWER_ADAPTER_POWER_STATES
    PeakPower: uint32
    MaxOutputPower: uint32
    MaxInputPower: uint32
    RecStartTime: uint64
    RecEndTime: uint64
struct POWER_ADAPTER_POWER_STATES
{
    _States_e__Struct States;
    uint AsUlong;
}

struct POWER_ADAPTER_STATUS
{
    ubyte Version;
    ubyte[3] Reserved;
    POWER_ADAPTER_POWER_STATES PowerState;
    uint PeakPower;
    uint MaxOutputPower;
    uint MaxInputPower;
    ulong RecStartTime;
    ulong RecEndTime;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; POWER_ADAPTER_STATUS サイズ: 40 バイト(x64)
dim st, 10    ; 4byte整数×10(構造体サイズ 40 / 4 切り上げ)
; Version : BYTE (+0, 1byte)  poke st,0,値  /  値 = peek(st,0)
; Reserved : BYTE (+1, 3byte)  varptr(st)+1 を基点に操作(3byte:入れ子/配列)
; PowerState : POWER_ADAPTER_POWER_STATES (+4, 4byte)  varptr(st)+4 を基点に操作(4byte:入れ子/配列)
; PeakPower : DWORD (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; MaxOutputPower : DWORD (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; MaxInputPower : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; RecStartTime : ULONGLONG (+24, 8byte)  qpoke st,24,値 / qpeek(st,24)  ※IronHSPのみ。3.7/3.8は lpoke st,24,下位 : lpoke st,28,上位
; RecEndTime : ULONGLONG (+32, 8byte)  qpoke st,32,値 / qpeek(st,32)  ※IronHSPのみ。3.7/3.8は lpoke st,32,下位 : lpoke st,36,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global POWER_ADAPTER_STATUS
    #field byte Version
    #field byte Reserved 3
    #field byte PowerState 4
    #field int PeakPower
    #field int MaxOutputPower
    #field int MaxInputPower
    #field int64 RecStartTime
    #field int64 RecEndTime
#endstruct

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