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

戻り値の型: WIN32_ERROR

公式ドキュメント

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

戻り値

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

解説(Remarks)

アクティブな電源スキームの設定への変更は、PowerSetActiveScheme 関数を呼び出すまで反映されません。

出典・ライセンス: 上記「公式ドキュメント」の内容は 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 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)。
const std = @import("std");

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

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

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

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

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

関連項目

使用する型