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

SET_POWER_SETTING_VALUE

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

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

フィールド

フィールドサイズx64x86説明
VersionDWORD4+0+0この構造体のバージョン番号。
GuidGUID16+4+4設定対象の電源設定を識別するGUID。
PowerConditionSYSTEM_POWER_CONDITION4+20+20適用対象の電源状態条件(AC/DCなど)を示す列挙値。
DataLengthDWORD4+24+24Dataフィールドの長さ。バイト数で表す。
DataBYTE1+28+28設定する値の本体。可変長のバイト配列。

各言語での定義

#include <windows.h>

// SET_POWER_SETTING_VALUE  (x64 32 / x86 32 バイト)
typedef struct SET_POWER_SETTING_VALUE {
    DWORD Version;
    GUID Guid;
    SYSTEM_POWER_CONDITION PowerCondition;
    DWORD DataLength;
    BYTE Data[1];
} SET_POWER_SETTING_VALUE;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SET_POWER_SETTING_VALUE
{
    public uint Version;
    public Guid Guid;
    public int PowerCondition;
    public uint DataLength;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public byte[] Data;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure SET_POWER_SETTING_VALUE
    Public Version As UInteger
    Public Guid As Guid
    Public PowerCondition As Integer
    Public DataLength As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public Data() As Byte
End Structure
import ctypes
from ctypes import wintypes

class SET_POWER_SETTING_VALUE(ctypes.Structure):
    _fields_ = [
        ("Version", wintypes.DWORD),
        ("Guid", GUID),
        ("PowerCondition", ctypes.c_int),
        ("DataLength", wintypes.DWORD),
        ("Data", ctypes.c_ubyte * 1),
    ]
#[repr(C)]
pub struct SET_POWER_SETTING_VALUE {
    pub Version: u32,
    pub Guid: GUID,
    pub PowerCondition: i32,
    pub DataLength: u32,
    pub Data: [u8; 1],
}
import "golang.org/x/sys/windows"

type SET_POWER_SETTING_VALUE struct {
	Version uint32
	Guid windows.GUID
	PowerCondition int32
	DataLength uint32
	Data [1]byte
}
type
  SET_POWER_SETTING_VALUE = record
    Version: DWORD;
    Guid: TGUID;
    PowerCondition: Integer;
    DataLength: DWORD;
    Data: array[0..0] of Byte;
  end;
const SET_POWER_SETTING_VALUE = extern struct {
    Version: u32,
    Guid: GUID,
    PowerCondition: i32,
    DataLength: u32,
    Data: [1]u8,
};
type
  SET_POWER_SETTING_VALUE {.bycopy.} = object
    Version: uint32
    Guid: GUID
    PowerCondition: int32
    DataLength: uint32
    Data: array[1, uint8]
struct SET_POWER_SETTING_VALUE
{
    uint Version;
    GUID Guid;
    int PowerCondition;
    uint DataLength;
    ubyte[1] Data;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; SET_POWER_SETTING_VALUE サイズ: 32 バイト(x64)
dim st, 8    ; 4byte整数×8(構造体サイズ 32 / 4 切り上げ)
; Version : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; Guid : GUID (+4, 16byte)  varptr(st)+4 を基点に操作(16byte:入れ子/配列)
; PowerCondition : SYSTEM_POWER_CONDITION (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; DataLength : DWORD (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; Data : BYTE (+28, 1byte)  varptr(st)+28 を基点に操作(1byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global GUID, pack=1
    #field int Data1
    #field short Data2
    #field short Data3
    #field byte Data4 8
#endstruct

#defstruct global SET_POWER_SETTING_VALUE
    #field int Version
    #field GUID Guid
    #field int PowerCondition
    #field int DataLength
    #field byte Data 1
#endstruct

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