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

SYSTEM_POWER_SOURCE_STATE

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

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

フィールド

フィールドサイズx64x86説明
BatteryStateSYSTEM_BATTERY_STATE32+0+0バッテリの現在の状態を示す。
InstantaneousPeakPowerDWORD4+32+32瞬間ピーク電力(ミリワット単位)。
InstantaneousPeakPeriodDWORD4+36+36瞬間ピーク電力を維持できる期間。
SustainablePeakPowerDWORD4+40+40持続可能なピーク電力。
SustainablePeakPeriodDWORD4+44+44持続可能なピーク電力を維持できる期間。
PeakPowerDWORD4+48+48ピーク電力値。
MaxOutputPowerDWORD4+52+52最大出力電力(ミリワット単位)。
MaxInputPowerDWORD4+56+56最大入力電力(ミリワット単位)。
BatteryRateInCurrentINT4+60+60バッテリの電流(充放電レート)。符号付きで充放電方向を示す。
BatteryVoltageDWORD4+64+64バッテリ電圧(ミリボルト単位)。

各言語での定義

#include <windows.h>

// SYSTEM_BATTERY_STATE  (x64 32 / x86 32 バイト)
typedef struct SYSTEM_BATTERY_STATE {
    BOOLEAN AcOnLine;
    BOOLEAN BatteryPresent;
    BOOLEAN Charging;
    BOOLEAN Discharging;
    BOOLEAN Spare1[3];
    BYTE Tag;
    DWORD MaxCapacity;
    DWORD RemainingCapacity;
    DWORD Rate;
    DWORD EstimatedTime;
    DWORD DefaultAlert1;
    DWORD DefaultAlert2;
} SYSTEM_BATTERY_STATE;

// SYSTEM_POWER_SOURCE_STATE  (x64 68 / x86 68 バイト)
typedef struct SYSTEM_POWER_SOURCE_STATE {
    SYSTEM_BATTERY_STATE BatteryState;
    DWORD InstantaneousPeakPower;
    DWORD InstantaneousPeakPeriod;
    DWORD SustainablePeakPower;
    DWORD SustainablePeakPeriod;
    DWORD PeakPower;
    DWORD MaxOutputPower;
    DWORD MaxInputPower;
    INT BatteryRateInCurrent;
    DWORD BatteryVoltage;
} SYSTEM_POWER_SOURCE_STATE;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SYSTEM_BATTERY_STATE
{
    [MarshalAs(UnmanagedType.U1)] public bool AcOnLine;
    [MarshalAs(UnmanagedType.U1)] public bool BatteryPresent;
    [MarshalAs(UnmanagedType.U1)] public bool Charging;
    [MarshalAs(UnmanagedType.U1)] public bool Discharging;
    [MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.U1, SizeConst = 3)] public bool[] Spare1;
    public byte Tag;
    public uint MaxCapacity;
    public uint RemainingCapacity;
    public uint Rate;
    public uint EstimatedTime;
    public uint DefaultAlert1;
    public uint DefaultAlert2;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SYSTEM_POWER_SOURCE_STATE
{
    public SYSTEM_BATTERY_STATE BatteryState;
    public uint InstantaneousPeakPower;
    public uint InstantaneousPeakPeriod;
    public uint SustainablePeakPower;
    public uint SustainablePeakPeriod;
    public uint PeakPower;
    public uint MaxOutputPower;
    public uint MaxInputPower;
    public int BatteryRateInCurrent;
    public uint BatteryVoltage;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SYSTEM_BATTERY_STATE
    <MarshalAs(UnmanagedType.U1)> Public AcOnLine As Boolean
    <MarshalAs(UnmanagedType.U1)> Public BatteryPresent As Boolean
    <MarshalAs(UnmanagedType.U1)> Public Charging As Boolean
    <MarshalAs(UnmanagedType.U1)> Public Discharging As Boolean
    <MarshalAs(UnmanagedType.ByValArray, ArraySubType:=UnmanagedType.U1, SizeConst:=3)> Public Spare1() As Boolean
    Public Tag As Byte
    Public MaxCapacity As UInteger
    Public RemainingCapacity As UInteger
    Public Rate As UInteger
    Public EstimatedTime As UInteger
    Public DefaultAlert1 As UInteger
    Public DefaultAlert2 As UInteger
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SYSTEM_POWER_SOURCE_STATE
    Public BatteryState As SYSTEM_BATTERY_STATE
    Public InstantaneousPeakPower As UInteger
    Public InstantaneousPeakPeriod As UInteger
    Public SustainablePeakPower As UInteger
    Public SustainablePeakPeriod As UInteger
    Public PeakPower As UInteger
    Public MaxOutputPower As UInteger
    Public MaxInputPower As UInteger
    Public BatteryRateInCurrent As Integer
    Public BatteryVoltage As UInteger
End Structure
import ctypes
from ctypes import wintypes

class SYSTEM_BATTERY_STATE(ctypes.Structure):
    _fields_ = [
        ("AcOnLine", ctypes.c_byte),
        ("BatteryPresent", ctypes.c_byte),
        ("Charging", ctypes.c_byte),
        ("Discharging", ctypes.c_byte),
        ("Spare1", ctypes.c_byte * 3),
        ("Tag", ctypes.c_ubyte),
        ("MaxCapacity", wintypes.DWORD),
        ("RemainingCapacity", wintypes.DWORD),
        ("Rate", wintypes.DWORD),
        ("EstimatedTime", wintypes.DWORD),
        ("DefaultAlert1", wintypes.DWORD),
        ("DefaultAlert2", wintypes.DWORD),
    ]

class SYSTEM_POWER_SOURCE_STATE(ctypes.Structure):
    _fields_ = [
        ("BatteryState", SYSTEM_BATTERY_STATE),
        ("InstantaneousPeakPower", wintypes.DWORD),
        ("InstantaneousPeakPeriod", wintypes.DWORD),
        ("SustainablePeakPower", wintypes.DWORD),
        ("SustainablePeakPeriod", wintypes.DWORD),
        ("PeakPower", wintypes.DWORD),
        ("MaxOutputPower", wintypes.DWORD),
        ("MaxInputPower", wintypes.DWORD),
        ("BatteryRateInCurrent", ctypes.c_int),
        ("BatteryVoltage", wintypes.DWORD),
    ]
#[repr(C)]
pub struct SYSTEM_BATTERY_STATE {
    pub AcOnLine: u8,
    pub BatteryPresent: u8,
    pub Charging: u8,
    pub Discharging: u8,
    pub Spare1: [u8; 3],
    pub Tag: u8,
    pub MaxCapacity: u32,
    pub RemainingCapacity: u32,
    pub Rate: u32,
    pub EstimatedTime: u32,
    pub DefaultAlert1: u32,
    pub DefaultAlert2: u32,
}

#[repr(C)]
pub struct SYSTEM_POWER_SOURCE_STATE {
    pub BatteryState: SYSTEM_BATTERY_STATE,
    pub InstantaneousPeakPower: u32,
    pub InstantaneousPeakPeriod: u32,
    pub SustainablePeakPower: u32,
    pub SustainablePeakPeriod: u32,
    pub PeakPower: u32,
    pub MaxOutputPower: u32,
    pub MaxInputPower: u32,
    pub BatteryRateInCurrent: i32,
    pub BatteryVoltage: u32,
}
import "golang.org/x/sys/windows"

type SYSTEM_BATTERY_STATE struct {
	AcOnLine byte
	BatteryPresent byte
	Charging byte
	Discharging byte
	Spare1 [3]byte
	Tag byte
	MaxCapacity uint32
	RemainingCapacity uint32
	Rate uint32
	EstimatedTime uint32
	DefaultAlert1 uint32
	DefaultAlert2 uint32
}

type SYSTEM_POWER_SOURCE_STATE struct {
	BatteryState SYSTEM_BATTERY_STATE
	InstantaneousPeakPower uint32
	InstantaneousPeakPeriod uint32
	SustainablePeakPower uint32
	SustainablePeakPeriod uint32
	PeakPower uint32
	MaxOutputPower uint32
	MaxInputPower uint32
	BatteryRateInCurrent int32
	BatteryVoltage uint32
}
type
  SYSTEM_BATTERY_STATE = record
    AcOnLine: ByteBool;
    BatteryPresent: ByteBool;
    Charging: ByteBool;
    Discharging: ByteBool;
    Spare1: array[0..2] of ByteBool;
    Tag: Byte;
    MaxCapacity: DWORD;
    RemainingCapacity: DWORD;
    Rate: DWORD;
    EstimatedTime: DWORD;
    DefaultAlert1: DWORD;
    DefaultAlert2: DWORD;
  end;

  SYSTEM_POWER_SOURCE_STATE = record
    BatteryState: SYSTEM_BATTERY_STATE;
    InstantaneousPeakPower: DWORD;
    InstantaneousPeakPeriod: DWORD;
    SustainablePeakPower: DWORD;
    SustainablePeakPeriod: DWORD;
    PeakPower: DWORD;
    MaxOutputPower: DWORD;
    MaxInputPower: DWORD;
    BatteryRateInCurrent: Integer;
    BatteryVoltage: DWORD;
  end;
const SYSTEM_BATTERY_STATE = extern struct {
    AcOnLine: u8,
    BatteryPresent: u8,
    Charging: u8,
    Discharging: u8,
    Spare1: [3]u8,
    Tag: u8,
    MaxCapacity: u32,
    RemainingCapacity: u32,
    Rate: u32,
    EstimatedTime: u32,
    DefaultAlert1: u32,
    DefaultAlert2: u32,
};

const SYSTEM_POWER_SOURCE_STATE = extern struct {
    BatteryState: SYSTEM_BATTERY_STATE,
    InstantaneousPeakPower: u32,
    InstantaneousPeakPeriod: u32,
    SustainablePeakPower: u32,
    SustainablePeakPeriod: u32,
    PeakPower: u32,
    MaxOutputPower: u32,
    MaxInputPower: u32,
    BatteryRateInCurrent: i32,
    BatteryVoltage: u32,
};
type
  SYSTEM_BATTERY_STATE {.bycopy.} = object
    AcOnLine: uint8
    BatteryPresent: uint8
    Charging: uint8
    Discharging: uint8
    Spare1: array[3, uint8]
    Tag: uint8
    MaxCapacity: uint32
    RemainingCapacity: uint32
    Rate: uint32
    EstimatedTime: uint32
    DefaultAlert1: uint32
    DefaultAlert2: uint32

  SYSTEM_POWER_SOURCE_STATE {.bycopy.} = object
    BatteryState: SYSTEM_BATTERY_STATE
    InstantaneousPeakPower: uint32
    InstantaneousPeakPeriod: uint32
    SustainablePeakPower: uint32
    SustainablePeakPeriod: uint32
    PeakPower: uint32
    MaxOutputPower: uint32
    MaxInputPower: uint32
    BatteryRateInCurrent: int32
    BatteryVoltage: uint32
struct SYSTEM_BATTERY_STATE
{
    ubyte AcOnLine;
    ubyte BatteryPresent;
    ubyte Charging;
    ubyte Discharging;
    ubyte[3] Spare1;
    ubyte Tag;
    uint MaxCapacity;
    uint RemainingCapacity;
    uint Rate;
    uint EstimatedTime;
    uint DefaultAlert1;
    uint DefaultAlert2;
}

struct SYSTEM_POWER_SOURCE_STATE
{
    SYSTEM_BATTERY_STATE BatteryState;
    uint InstantaneousPeakPower;
    uint InstantaneousPeakPeriod;
    uint SustainablePeakPower;
    uint SustainablePeakPeriod;
    uint PeakPower;
    uint MaxOutputPower;
    uint MaxInputPower;
    int BatteryRateInCurrent;
    uint BatteryVoltage;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; SYSTEM_POWER_SOURCE_STATE サイズ: 68 バイト(x64)
dim st, 17    ; 4byte整数×17(構造体サイズ 68 / 4 切り上げ)
; BatteryState : SYSTEM_BATTERY_STATE (+0, 32byte)  varptr(st)+0 を基点に操作(32byte:入れ子/配列)
; InstantaneousPeakPower : DWORD (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; InstantaneousPeakPeriod : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; SustainablePeakPower : DWORD (+40, 4byte)  st.10 = 値  /  値 = st.10   (lpoke/lpeek も可)
; SustainablePeakPeriod : DWORD (+44, 4byte)  st.11 = 値  /  値 = st.11   (lpoke/lpeek も可)
; PeakPower : DWORD (+48, 4byte)  st.12 = 値  /  値 = st.12   (lpoke/lpeek も可)
; MaxOutputPower : DWORD (+52, 4byte)  st.13 = 値  /  値 = st.13   (lpoke/lpeek も可)
; MaxInputPower : DWORD (+56, 4byte)  st.14 = 値  /  値 = st.14   (lpoke/lpeek も可)
; BatteryRateInCurrent : INT (+60, 4byte)  st.15 = 値  /  値 = st.15   (lpoke/lpeek も可)
; BatteryVoltage : DWORD (+64, 4byte)  st.16 = 値  /  値 = st.16   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global SYSTEM_BATTERY_STATE
    #field bool1 AcOnLine
    #field bool1 BatteryPresent
    #field bool1 Charging
    #field bool1 Discharging
    #field bool1 Spare1 3
    #field byte Tag
    #field int MaxCapacity
    #field int RemainingCapacity
    #field int Rate
    #field int EstimatedTime
    #field int DefaultAlert1
    #field int DefaultAlert2
#endstruct

#defstruct global SYSTEM_POWER_SOURCE_STATE
    #field SYSTEM_BATTERY_STATE BatteryState
    #field int InstantaneousPeakPower
    #field int InstantaneousPeakPeriod
    #field int SustainablePeakPower
    #field int SustainablePeakPeriod
    #field int PeakPower
    #field int MaxOutputPower
    #field int MaxInputPower
    #field int BatteryRateInCurrent
    #field int BatteryVoltage
#endstruct

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