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このパラメーターは将来の使用のために予約されており、NULL に設定する必要があります。
SchemeGuidGUID*inoptional電源スキームの識別子です。
SubGroupOfPowerSettingsGuidGUID*inoptional

電源設定のサブグループです。このパラメーターには、WinNT.h で定義されている次の値のいずれかを指定できます。既定の電源スキームを参照するには NO_SUBGROUP_GUID を使用します。

意味
NO_SUBGROUP_GUID
fea3413e-7e05-4911-9a71-700331f1c294
このサブグループ内の設定は、既定の電源スキームの一部です。
GUID_DISK_SUBGROUP
0012ee47-9041-4b5d-9b77-535fba8b1442
このサブグループ内の設定は、システムのハードディスクドライブの電源管理構成を制御します。
GUID_SYSTEM_BUTTON_SUBGROUP
4f971e89-eebd-4455-a8de-9e59040e7347
このサブグループ内の設定は、システムの電源ボタンの構成を制御します。
GUID_PROCESSOR_SETTINGS_SUBGROUP
54533251-82be-4824-96c1-47b60b740d00
このサブグループ内の設定は、プロセッサの電源管理機能の構成を制御します。
GUID_VIDEO_SUBGROUP
7516b95f-f776-4464-8c53-06167f40cc99
このサブグループ内の設定は、ビデオの電源管理機能の構成を制御します。
GUID_BATTERY_SUBGROUP
e73a048d-bf27-4f12-9731-8b2076e8891f
このサブグループ内の設定は、バッテリアラームのトリップポイントとアクションを制御します。
GUID_SLEEP_SUBGROUP
238C9FA8-0AAD-41ED-83F4-97BE242C8F20
このサブグループ内の設定は、システムのスリープ設定を制御します。
GUID_PCIEXPRESS_SETTINGS_SUBGROUP
501a4d13-42af-4429-9fd1-a8218c268e20
このサブグループ内の設定は、PCI Express の設定を制御します。
PowerSettingGuidGUID*inoptional電源設定の識別子です。
AcValueIndexDWORD*outAC 値のインデックスを受け取る変数へのポインターです。

戻り値の型: WIN32_ERROR

公式ドキュメント

指定された電源設定の AC インデックスを取得します。

戻り値

呼び出しが成功した場合は ERROR_SUCCESS(ゼロ)を返し、呼び出しが失敗した場合は 0 以外の値を返します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

// 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)。
const std = @import("std");

extern "powrprof" fn PowerReadACValueIndex(
    RootPowerKey: ?*anyopaque, // HKEY optional
    SchemeGuid: [*c]GUID, // GUID* optional
    SubGroupOfPowerSettingsGuid: [*c]GUID, // GUID* optional
    PowerSettingGuid: [*c]GUID, // GUID* optional
    AcValueIndex: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) u32;
proc PowerReadACValueIndex(
    RootPowerKey: pointer,  # HKEY optional
    SchemeGuid: ptr GUID,  # GUID* optional
    SubGroupOfPowerSettingsGuid: ptr GUID,  # GUID* optional
    PowerSettingGuid: ptr GUID,  # GUID* optional
    AcValueIndex: ptr uint32  # DWORD* out
): uint32 {.importc: "PowerReadACValueIndex", stdcall, dynlib: "POWRPROF.dll".}
pragma(lib, "powrprof");
extern(Windows)
uint PowerReadACValueIndex(
    void* RootPowerKey,   // HKEY optional
    GUID* SchemeGuid,   // GUID* optional
    GUID* SubGroupOfPowerSettingsGuid,   // GUID* optional
    GUID* PowerSettingGuid,   // GUID* optional
    uint* AcValueIndex   // DWORD* out
);
ccall((:PowerReadACValueIndex, "POWRPROF.dll"), stdcall, UInt32,
      (Ptr{Cvoid}, Ptr{GUID}, Ptr{GUID}, Ptr{GUID}, Ptr{UInt32}),
      RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, AcValueIndex)
# RootPowerKey : HKEY optional -> Ptr{Cvoid}
# SchemeGuid : GUID* optional -> Ptr{GUID}
# SubGroupOfPowerSettingsGuid : GUID* optional -> Ptr{GUID}
# PowerSettingGuid : GUID* optional -> Ptr{GUID}
# AcValueIndex : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
uint32_t PowerReadACValueIndex(
    void* RootPowerKey,
    void* SchemeGuid,
    void* SubGroupOfPowerSettingsGuid,
    void* PowerSettingGuid,
    uint32_t* AcValueIndex);
]]
local powrprof = ffi.load("powrprof")
-- powrprof.PowerReadACValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, AcValueIndex)
-- RootPowerKey : HKEY optional
-- SchemeGuid : GUID* optional
-- SubGroupOfPowerSettingsGuid : GUID* optional
-- PowerSettingGuid : GUID* optional
-- AcValueIndex : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('POWRPROF.dll');
const PowerReadACValueIndex = lib.func('__stdcall', 'PowerReadACValueIndex', 'uint32_t', ['void *', 'void *', 'void *', 'void *', 'uint32_t *']);
// 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 -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("POWRPROF.dll", {
  PowerReadACValueIndex: { parameters: ["pointer", "pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.PowerReadACValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, AcValueIndex)
// RootPowerKey : HKEY optional -> "pointer"
// SchemeGuid : GUID* optional -> "pointer"
// SubGroupOfPowerSettingsGuid : GUID* optional -> "pointer"
// PowerSettingGuid : GUID* optional -> "pointer"
// AcValueIndex : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
uint32_t PowerReadACValueIndex(
    void* RootPowerKey,
    void* SchemeGuid,
    void* SubGroupOfPowerSettingsGuid,
    void* PowerSettingGuid,
    uint32_t* AcValueIndex);
C, "POWRPROF.dll");
// $ffi->PowerReadACValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, AcValueIndex);
// RootPowerKey : HKEY optional
// SchemeGuid : GUID* optional
// SubGroupOfPowerSettingsGuid : GUID* optional
// PowerSettingGuid : GUID* optional
// AcValueIndex : DWORD* out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Powrprof extends StdCallLibrary {
    Powrprof INSTANCE = Native.load("powrprof", Powrprof.class);
    int PowerReadACValueIndex(
        Pointer RootPowerKey,   // HKEY optional
        Pointer SchemeGuid,   // GUID* optional
        Pointer SubGroupOfPowerSettingsGuid,   // GUID* optional
        Pointer PowerSettingGuid,   // GUID* optional
        IntByReference AcValueIndex   // DWORD* out
    );
}
@[Link("powrprof")]
lib LibPOWRPROF
  fun PowerReadACValueIndex = PowerReadACValueIndex(
    RootPowerKey : Void*,   # HKEY optional
    SchemeGuid : GUID*,   # GUID* optional
    SubGroupOfPowerSettingsGuid : GUID*,   # GUID* optional
    PowerSettingGuid : GUID*,   # GUID* optional
    AcValueIndex : UInt32*   # DWORD* out
  ) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef PowerReadACValueIndexNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
typedef PowerReadACValueIndexDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
final PowerReadACValueIndex = DynamicLibrary.open('POWRPROF.dll')
    .lookupFunction<PowerReadACValueIndexNative, PowerReadACValueIndexDart>('PowerReadACValueIndex');
// RootPowerKey : HKEY optional -> Pointer<Void>
// SchemeGuid : GUID* optional -> Pointer<Void>
// SubGroupOfPowerSettingsGuid : GUID* optional -> Pointer<Void>
// PowerSettingGuid : GUID* optional -> Pointer<Void>
// AcValueIndex : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
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';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "PowerReadACValueIndex"
  c_PowerReadACValueIndex :: Ptr () -> Ptr () -> Ptr () -> Ptr () -> Ptr Word32 -> IO Word32
-- RootPowerKey : HKEY optional -> Ptr ()
-- SchemeGuid : GUID* optional -> Ptr ()
-- SubGroupOfPowerSettingsGuid : GUID* optional -> Ptr ()
-- PowerSettingGuid : GUID* optional -> Ptr ()
-- AcValueIndex : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let powerreadacvalueindex =
  foreign "PowerReadACValueIndex"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr uint32_t) @-> returning uint32_t)
(* RootPowerKey : HKEY optional -> (ptr void) *)
(* SchemeGuid : GUID* optional -> (ptr void) *)
(* SubGroupOfPowerSettingsGuid : GUID* optional -> (ptr void) *)
(* PowerSettingGuid : GUID* optional -> (ptr void) *)
(* AcValueIndex : DWORD* out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library powrprof (t "POWRPROF.dll"))
(cffi:use-foreign-library powrprof)

(cffi:defcfun ("PowerReadACValueIndex" power-read-acvalue-index :convention :stdcall) :uint32
  (root-power-key :pointer)   ; HKEY optional
  (scheme-guid :pointer)   ; GUID* optional
  (sub-group-of-power-settings-guid :pointer)   ; GUID* optional
  (power-setting-guid :pointer)   ; GUID* optional
  (ac-value-index :pointer))   ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $PowerReadACValueIndex = Win32::API::More->new('POWRPROF',
    'DWORD PowerReadACValueIndex(HANDLE RootPowerKey, LPVOID SchemeGuid, LPVOID SubGroupOfPowerSettingsGuid, LPVOID PowerSettingGuid, LPVOID AcValueIndex)');
# my $ret = $PowerReadACValueIndex->Call($RootPowerKey, $SchemeGuid, $SubGroupOfPowerSettingsGuid, $PowerSettingGuid, $AcValueIndex);
# RootPowerKey : HKEY optional -> HANDLE
# SchemeGuid : GUID* optional -> LPVOID
# SubGroupOfPowerSettingsGuid : GUID* optional -> LPVOID
# PowerSettingGuid : GUID* optional -> LPVOID
# AcValueIndex : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型