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

PowerWritePossibleValue

関数
電源設定の指定インデックスの選択可能な値を書き込む。
DLLPOWRPROF.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

// POWRPROF.dll
#include <windows.h>

WIN32_ERROR PowerWritePossibleValue(
    HKEY RootPowerKey,   // optional
    const GUID* SubGroupOfPowerSettingsGuid,   // optional
    const GUID* PowerSettingGuid,   // optional
    DWORD Type,
    DWORD PossibleSettingIndex,
    BYTE* Buffer,
    DWORD BufferSize
);

パラメーター

名前方向
RootPowerKeyHKEYinoptional
SubGroupOfPowerSettingsGuidGUID*inoptional
PowerSettingGuidGUID*inoptional
TypeDWORDin
PossibleSettingIndexDWORDin
BufferBYTE*in
BufferSizeDWORDin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

// POWRPROF.dll
#include <windows.h>

WIN32_ERROR PowerWritePossibleValue(
    HKEY RootPowerKey,   // optional
    const GUID* SubGroupOfPowerSettingsGuid,   // optional
    const GUID* PowerSettingGuid,   // optional
    DWORD Type,
    DWORD PossibleSettingIndex,
    BYTE* Buffer,
    DWORD BufferSize
);
[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern uint PowerWritePossibleValue(
    IntPtr RootPowerKey,   // HKEY optional
    IntPtr SubGroupOfPowerSettingsGuid,   // GUID* optional
    IntPtr PowerSettingGuid,   // GUID* optional
    uint Type,   // DWORD
    uint PossibleSettingIndex,   // DWORD
    IntPtr Buffer,   // BYTE*
    uint BufferSize   // DWORD
);
<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerWritePossibleValue(
    RootPowerKey As IntPtr,   ' HKEY optional
    SubGroupOfPowerSettingsGuid As IntPtr,   ' GUID* optional
    PowerSettingGuid As IntPtr,   ' GUID* optional
    Type As UInteger,   ' DWORD
    PossibleSettingIndex As UInteger,   ' DWORD
    Buffer As IntPtr,   ' BYTE*
    BufferSize As UInteger   ' DWORD
) As UInteger
End Function
' RootPowerKey : HKEY optional
' SubGroupOfPowerSettingsGuid : GUID* optional
' PowerSettingGuid : GUID* optional
' Type : DWORD
' PossibleSettingIndex : DWORD
' Buffer : BYTE*
' BufferSize : DWORD
Declare PtrSafe Function PowerWritePossibleValue Lib "powrprof" ( _
    ByVal RootPowerKey As LongPtr, _
    ByVal SubGroupOfPowerSettingsGuid As LongPtr, _
    ByVal PowerSettingGuid As LongPtr, _
    ByVal Type As Long, _
    ByVal PossibleSettingIndex As Long, _
    ByVal Buffer As LongPtr, _
    ByVal BufferSize As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

PowerWritePossibleValue = ctypes.windll.powrprof.PowerWritePossibleValue
PowerWritePossibleValue.restype = wintypes.DWORD
PowerWritePossibleValue.argtypes = [
    wintypes.HANDLE,  # RootPowerKey : HKEY optional
    ctypes.c_void_p,  # SubGroupOfPowerSettingsGuid : GUID* optional
    ctypes.c_void_p,  # PowerSettingGuid : GUID* optional
    wintypes.DWORD,  # Type : DWORD
    wintypes.DWORD,  # PossibleSettingIndex : DWORD
    ctypes.POINTER(ctypes.c_ubyte),  # Buffer : BYTE*
    wintypes.DWORD,  # BufferSize : DWORD
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('POWRPROF.dll')
PowerWritePossibleValue = Fiddle::Function.new(
  lib['PowerWritePossibleValue'],
  [
    Fiddle::TYPE_VOIDP,  # RootPowerKey : HKEY optional
    Fiddle::TYPE_VOIDP,  # SubGroupOfPowerSettingsGuid : GUID* optional
    Fiddle::TYPE_VOIDP,  # PowerSettingGuid : GUID* optional
    -Fiddle::TYPE_INT,  # Type : DWORD
    -Fiddle::TYPE_INT,  # PossibleSettingIndex : DWORD
    Fiddle::TYPE_VOIDP,  # Buffer : BYTE*
    -Fiddle::TYPE_INT,  # BufferSize : DWORD
  ],
  -Fiddle::TYPE_INT)
#[link(name = "powrprof")]
extern "system" {
    fn PowerWritePossibleValue(
        RootPowerKey: *mut core::ffi::c_void,  // HKEY optional
        SubGroupOfPowerSettingsGuid: *const GUID,  // GUID* optional
        PowerSettingGuid: *const GUID,  // GUID* optional
        Type: u32,  // DWORD
        PossibleSettingIndex: u32,  // DWORD
        Buffer: *mut u8,  // BYTE*
        BufferSize: u32  // DWORD
    ) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("POWRPROF.dll")]
public static extern uint PowerWritePossibleValue(IntPtr RootPowerKey, IntPtr SubGroupOfPowerSettingsGuid, IntPtr PowerSettingGuid, uint Type, uint PossibleSettingIndex, IntPtr Buffer, uint BufferSize);
"@
$api = Add-Type -MemberDefinition $sig -Name 'POWRPROF_PowerWritePossibleValue' -Namespace Win32 -PassThru
# $api::PowerWritePossibleValue(RootPowerKey, SubGroupOfPowerSettingsGuid, PowerSettingGuid, Type, PossibleSettingIndex, Buffer, BufferSize)
#uselib "POWRPROF.dll"
#func global PowerWritePossibleValue "PowerWritePossibleValue" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; PowerWritePossibleValue RootPowerKey, varptr(SubGroupOfPowerSettingsGuid), varptr(PowerSettingGuid), Type, PossibleSettingIndex, varptr(Buffer), BufferSize   ; 戻り値は stat
; RootPowerKey : HKEY optional -> "sptr"
; SubGroupOfPowerSettingsGuid : GUID* optional -> "sptr"
; PowerSettingGuid : GUID* optional -> "sptr"
; Type : DWORD -> "sptr"
; PossibleSettingIndex : DWORD -> "sptr"
; Buffer : BYTE* -> "sptr"
; BufferSize : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "POWRPROF.dll"
#cfunc global PowerWritePossibleValue "PowerWritePossibleValue" sptr, var, var, int, int, var, int
; res = PowerWritePossibleValue(RootPowerKey, SubGroupOfPowerSettingsGuid, PowerSettingGuid, Type, PossibleSettingIndex, Buffer, BufferSize)
; RootPowerKey : HKEY optional -> "sptr"
; SubGroupOfPowerSettingsGuid : GUID* optional -> "var"
; PowerSettingGuid : GUID* optional -> "var"
; Type : DWORD -> "int"
; PossibleSettingIndex : DWORD -> "int"
; Buffer : BYTE* -> "var"
; BufferSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; WIN32_ERROR PowerWritePossibleValue(HKEY RootPowerKey, GUID* SubGroupOfPowerSettingsGuid, GUID* PowerSettingGuid, DWORD Type, DWORD PossibleSettingIndex, BYTE* Buffer, DWORD BufferSize)
#uselib "POWRPROF.dll"
#cfunc global PowerWritePossibleValue "PowerWritePossibleValue" intptr, var, var, int, int, var, int
; res = PowerWritePossibleValue(RootPowerKey, SubGroupOfPowerSettingsGuid, PowerSettingGuid, Type, PossibleSettingIndex, Buffer, BufferSize)
; RootPowerKey : HKEY optional -> "intptr"
; SubGroupOfPowerSettingsGuid : GUID* optional -> "var"
; PowerSettingGuid : GUID* optional -> "var"
; Type : DWORD -> "int"
; PossibleSettingIndex : DWORD -> "int"
; Buffer : BYTE* -> "var"
; BufferSize : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procPowerWritePossibleValue = powrprof.NewProc("PowerWritePossibleValue")
)

// RootPowerKey (HKEY optional), SubGroupOfPowerSettingsGuid (GUID* optional), PowerSettingGuid (GUID* optional), Type (DWORD), PossibleSettingIndex (DWORD), Buffer (BYTE*), BufferSize (DWORD)
r1, _, err := procPowerWritePossibleValue.Call(
	uintptr(RootPowerKey),
	uintptr(SubGroupOfPowerSettingsGuid),
	uintptr(PowerSettingGuid),
	uintptr(Type),
	uintptr(PossibleSettingIndex),
	uintptr(Buffer),
	uintptr(BufferSize),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // WIN32_ERROR
function PowerWritePossibleValue(
  RootPowerKey: THandle;   // HKEY optional
  SubGroupOfPowerSettingsGuid: PGUID;   // GUID* optional
  PowerSettingGuid: PGUID;   // GUID* optional
  Type: DWORD;   // DWORD
  PossibleSettingIndex: DWORD;   // DWORD
  Buffer: Pointer;   // BYTE*
  BufferSize: DWORD   // DWORD
): DWORD; stdcall;
  external 'POWRPROF.dll' name 'PowerWritePossibleValue';
result := DllCall("POWRPROF\PowerWritePossibleValue"
    , "Ptr", RootPowerKey   ; HKEY optional
    , "Ptr", SubGroupOfPowerSettingsGuid   ; GUID* optional
    , "Ptr", PowerSettingGuid   ; GUID* optional
    , "UInt", Type   ; DWORD
    , "UInt", PossibleSettingIndex   ; DWORD
    , "Ptr", Buffer   ; BYTE*
    , "UInt", BufferSize   ; DWORD
    , "UInt")   ; return: WIN32_ERROR
●PowerWritePossibleValue(RootPowerKey, SubGroupOfPowerSettingsGuid, PowerSettingGuid, Type, PossibleSettingIndex, Buffer, BufferSize) = DLL("POWRPROF.dll", "dword PowerWritePossibleValue(void*, void*, void*, dword, dword, void*, dword)")
# 呼び出し: PowerWritePossibleValue(RootPowerKey, SubGroupOfPowerSettingsGuid, PowerSettingGuid, Type, PossibleSettingIndex, Buffer, BufferSize)
# RootPowerKey : HKEY optional -> "void*"
# SubGroupOfPowerSettingsGuid : GUID* optional -> "void*"
# PowerSettingGuid : GUID* optional -> "void*"
# Type : DWORD -> "dword"
# PossibleSettingIndex : DWORD -> "dword"
# Buffer : BYTE* -> "void*"
# BufferSize : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。