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

PowerWriteACValueIndex

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

シグネチャ

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

WIN32_ERROR PowerWriteACValueIndex(
    HKEY RootPowerKey,   // optional
    const GUID* SchemeGuid,
    const GUID* SubGroupOfPowerSettingsGuid,   // optional
    const GUID* PowerSettingGuid,   // optional
    DWORD AcValueIndex
);

パラメーター

名前方向
RootPowerKeyHKEYinoptional
SchemeGuidGUID*in
SubGroupOfPowerSettingsGuidGUID*inoptional
PowerSettingGuidGUID*inoptional
AcValueIndexDWORDin

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

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

PowerWriteACValueIndex = ctypes.windll.powrprof.PowerWriteACValueIndex
PowerWriteACValueIndex.restype = wintypes.DWORD
PowerWriteACValueIndex.argtypes = [
    wintypes.HANDLE,  # RootPowerKey : HKEY optional
    ctypes.c_void_p,  # SchemeGuid : GUID*
    ctypes.c_void_p,  # SubGroupOfPowerSettingsGuid : GUID* optional
    ctypes.c_void_p,  # PowerSettingGuid : GUID* optional
    wintypes.DWORD,  # AcValueIndex : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procPowerWriteACValueIndex = powrprof.NewProc("PowerWriteACValueIndex")
)

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