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

PowerReadACValueIndex

関数
指定電源設定のAC電源時の値インデックスを読み取る。
DLLPOWRPROF.dll呼出規約winapi対応OSWindows Vista 以降

シグネチャ

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

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

パラメーター

名前方向
RootPowerKeyHKEYinoptional
SchemeGuidGUID*inoptional
SubGroupOfPowerSettingsGuidGUID*inoptional
PowerSettingGuidGUID*inoptional
AcValueIndexDWORD*out

戻り値の型: WIN32_ERROR

各言語での呼び出し定義

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

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

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

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

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procPowerReadACValueIndex = powrprof.NewProc("PowerReadACValueIndex")
)

// RootPowerKey (HKEY optional), SchemeGuid (GUID* optional), SubGroupOfPowerSettingsGuid (GUID* optional), PowerSettingGuid (GUID* optional), AcValueIndex (DWORD* out)
r1, _, err := procPowerReadACValueIndex.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 PowerReadACValueIndex(
  RootPowerKey: THandle;   // HKEY optional
  SchemeGuid: PGUID;   // GUID* optional
  SubGroupOfPowerSettingsGuid: PGUID;   // GUID* optional
  PowerSettingGuid: PGUID;   // GUID* optional
  AcValueIndex: Pointer   // DWORD* out
): DWORD; stdcall;
  external 'POWRPROF.dll' name 'PowerReadACValueIndex';
result := DllCall("POWRPROF\PowerReadACValueIndex"
    , "Ptr", RootPowerKey   ; HKEY optional
    , "Ptr", SchemeGuid   ; GUID* optional
    , "Ptr", SubGroupOfPowerSettingsGuid   ; GUID* optional
    , "Ptr", PowerSettingGuid   ; GUID* optional
    , "Ptr", AcValueIndex   ; DWORD* out
    , "UInt")   ; return: WIN32_ERROR
●PowerReadACValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, AcValueIndex) = DLL("POWRPROF.dll", "dword PowerReadACValueIndex(void*, void*, void*, void*, void*)")
# 呼び出し: PowerReadACValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, AcValueIndex)
# RootPowerKey : HKEY optional -> "void*"
# SchemeGuid : GUID* optional -> "void*"
# SubGroupOfPowerSettingsGuid : GUID* optional -> "void*"
# PowerSettingGuid : GUID* optional -> "void*"
# AcValueIndex : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。