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

PowerWriteDCValueIndex

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

シグネチャ

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

DWORD PowerWriteDCValueIndex(
    HKEY RootPowerKey,   // optional
    const GUID* SchemeGuid,
    const GUID* SubGroupOfPowerSettingsGuid,   // optional
    const GUID* PowerSettingGuid,   // optional
    DWORD DcValueIndex
);

パラメーター

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

戻り値の型: DWORD

各言語での呼び出し定義

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

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

PowerWriteDCValueIndex = ctypes.windll.powrprof.PowerWriteDCValueIndex
PowerWriteDCValueIndex.restype = wintypes.DWORD
PowerWriteDCValueIndex.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,  # DcValueIndex : DWORD
]
require 'fiddle'
require 'fiddle/import'

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

var (
	powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
	procPowerWriteDCValueIndex = powrprof.NewProc("PowerWriteDCValueIndex")
)

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