ホーム › System.Power › PowerReadDCValueIndex
PowerReadDCValueIndex
関数指定電源設定のDC電源時の値インデックスを読み取る。
シグネチャ
// POWRPROF.dll
#include <windows.h>
DWORD PowerReadDCValueIndex(
HKEY RootPowerKey, // optional
const GUID* SchemeGuid, // optional
const GUID* SubGroupOfPowerSettingsGuid, // optional
const GUID* PowerSettingGuid, // optional
DWORD* DcValueIndex
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| RootPowerKey | HKEY | inoptional | このパラメーターは将来の使用のために予約されており、NULL に設定する必要があります。 | ||||||||||||||||||
| SchemeGuid | GUID* | inoptional | 電源スキームの識別子です。 | ||||||||||||||||||
| SubGroupOfPowerSettingsGuid | GUID* | inoptional | 電源設定のサブグループの識別子です。既定の電源スキームを参照するには NO_SUBGROUP_GUID を使用します。 これらの値は Windows に含まれるサブグループの値です。
| ||||||||||||||||||
| PowerSettingGuid | GUID* | inoptional | 電源設定の識別子です。 | ||||||||||||||||||
| DcValueIndex | DWORD* | out | DC 値インデックスを受け取る変数へのポインターです。 |
戻り値の型: DWORD
公式ドキュメント
指定された電源設定の DC 値インデックスを取得します。
戻り値
呼び出しが成功した場合は ERROR_SUCCESS(ゼロ)を返し、失敗した場合は 0 以外の値を返します。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// POWRPROF.dll
#include <windows.h>
DWORD PowerReadDCValueIndex(
HKEY RootPowerKey, // optional
const GUID* SchemeGuid, // optional
const GUID* SubGroupOfPowerSettingsGuid, // optional
const GUID* PowerSettingGuid, // optional
DWORD* DcValueIndex
);[DllImport("POWRPROF.dll", ExactSpelling = true)]
static extern uint PowerReadDCValueIndex(
IntPtr RootPowerKey, // HKEY optional
IntPtr SchemeGuid, // GUID* optional
IntPtr SubGroupOfPowerSettingsGuid, // GUID* optional
IntPtr PowerSettingGuid, // GUID* optional
out uint DcValueIndex // DWORD* out
);<DllImport("POWRPROF.dll", ExactSpelling:=True)>
Public Shared Function PowerReadDCValueIndex(
RootPowerKey As IntPtr, ' HKEY optional
SchemeGuid As IntPtr, ' GUID* optional
SubGroupOfPowerSettingsGuid As IntPtr, ' GUID* optional
PowerSettingGuid As IntPtr, ' GUID* optional
<Out> ByRef DcValueIndex As UInteger ' DWORD* out
) As UInteger
End Function' RootPowerKey : HKEY optional
' SchemeGuid : GUID* optional
' SubGroupOfPowerSettingsGuid : GUID* optional
' PowerSettingGuid : GUID* optional
' DcValueIndex : DWORD* out
Declare PtrSafe Function PowerReadDCValueIndex Lib "powrprof" ( _
ByVal RootPowerKey As LongPtr, _
ByVal SchemeGuid As LongPtr, _
ByVal SubGroupOfPowerSettingsGuid As LongPtr, _
ByVal PowerSettingGuid As LongPtr, _
ByRef DcValueIndex As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
PowerReadDCValueIndex = ctypes.windll.powrprof.PowerReadDCValueIndex
PowerReadDCValueIndex.restype = wintypes.DWORD
PowerReadDCValueIndex.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), # DcValueIndex : DWORD* out
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('POWRPROF.dll')
PowerReadDCValueIndex = Fiddle::Function.new(
lib['PowerReadDCValueIndex'],
[
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, # DcValueIndex : DWORD* out
],
-Fiddle::TYPE_INT)#[link(name = "powrprof")]
extern "system" {
fn PowerReadDCValueIndex(
RootPowerKey: *mut core::ffi::c_void, // HKEY optional
SchemeGuid: *const GUID, // GUID* optional
SubGroupOfPowerSettingsGuid: *const GUID, // GUID* optional
PowerSettingGuid: *const GUID, // GUID* optional
DcValueIndex: *mut u32 // DWORD* out
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("POWRPROF.dll")]
public static extern uint PowerReadDCValueIndex(IntPtr RootPowerKey, IntPtr SchemeGuid, IntPtr SubGroupOfPowerSettingsGuid, IntPtr PowerSettingGuid, out uint DcValueIndex);
"@
$api = Add-Type -MemberDefinition $sig -Name 'POWRPROF_PowerReadDCValueIndex' -Namespace Win32 -PassThru
# $api::PowerReadDCValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex)#uselib "POWRPROF.dll"
#func global PowerReadDCValueIndex "PowerReadDCValueIndex" sptr, sptr, sptr, sptr, sptr
; PowerReadDCValueIndex RootPowerKey, varptr(SchemeGuid), varptr(SubGroupOfPowerSettingsGuid), varptr(PowerSettingGuid), varptr(DcValueIndex) ; 戻り値は stat
; RootPowerKey : HKEY optional -> "sptr"
; SchemeGuid : GUID* optional -> "sptr"
; SubGroupOfPowerSettingsGuid : GUID* optional -> "sptr"
; PowerSettingGuid : GUID* optional -> "sptr"
; DcValueIndex : DWORD* out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "POWRPROF.dll" #cfunc global PowerReadDCValueIndex "PowerReadDCValueIndex" sptr, var, var, var, var ; res = PowerReadDCValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex) ; RootPowerKey : HKEY optional -> "sptr" ; SchemeGuid : GUID* optional -> "var" ; SubGroupOfPowerSettingsGuid : GUID* optional -> "var" ; PowerSettingGuid : GUID* optional -> "var" ; DcValueIndex : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "POWRPROF.dll" #cfunc global PowerReadDCValueIndex "PowerReadDCValueIndex" sptr, sptr, sptr, sptr, sptr ; res = PowerReadDCValueIndex(RootPowerKey, varptr(SchemeGuid), varptr(SubGroupOfPowerSettingsGuid), varptr(PowerSettingGuid), varptr(DcValueIndex)) ; RootPowerKey : HKEY optional -> "sptr" ; SchemeGuid : GUID* optional -> "sptr" ; SubGroupOfPowerSettingsGuid : GUID* optional -> "sptr" ; PowerSettingGuid : GUID* optional -> "sptr" ; DcValueIndex : DWORD* out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD PowerReadDCValueIndex(HKEY RootPowerKey, GUID* SchemeGuid, GUID* SubGroupOfPowerSettingsGuid, GUID* PowerSettingGuid, DWORD* DcValueIndex) #uselib "POWRPROF.dll" #cfunc global PowerReadDCValueIndex "PowerReadDCValueIndex" intptr, var, var, var, var ; res = PowerReadDCValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex) ; RootPowerKey : HKEY optional -> "intptr" ; SchemeGuid : GUID* optional -> "var" ; SubGroupOfPowerSettingsGuid : GUID* optional -> "var" ; PowerSettingGuid : GUID* optional -> "var" ; DcValueIndex : DWORD* out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD PowerReadDCValueIndex(HKEY RootPowerKey, GUID* SchemeGuid, GUID* SubGroupOfPowerSettingsGuid, GUID* PowerSettingGuid, DWORD* DcValueIndex) #uselib "POWRPROF.dll" #cfunc global PowerReadDCValueIndex "PowerReadDCValueIndex" intptr, intptr, intptr, intptr, intptr ; res = PowerReadDCValueIndex(RootPowerKey, varptr(SchemeGuid), varptr(SubGroupOfPowerSettingsGuid), varptr(PowerSettingGuid), varptr(DcValueIndex)) ; RootPowerKey : HKEY optional -> "intptr" ; SchemeGuid : GUID* optional -> "intptr" ; SubGroupOfPowerSettingsGuid : GUID* optional -> "intptr" ; PowerSettingGuid : GUID* optional -> "intptr" ; DcValueIndex : DWORD* out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
powrprof = windows.NewLazySystemDLL("POWRPROF.dll")
procPowerReadDCValueIndex = powrprof.NewProc("PowerReadDCValueIndex")
)
// RootPowerKey (HKEY optional), SchemeGuid (GUID* optional), SubGroupOfPowerSettingsGuid (GUID* optional), PowerSettingGuid (GUID* optional), DcValueIndex (DWORD* out)
r1, _, err := procPowerReadDCValueIndex.Call(
uintptr(RootPowerKey),
uintptr(SchemeGuid),
uintptr(SubGroupOfPowerSettingsGuid),
uintptr(PowerSettingGuid),
uintptr(DcValueIndex),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction PowerReadDCValueIndex(
RootPowerKey: THandle; // HKEY optional
SchemeGuid: PGUID; // GUID* optional
SubGroupOfPowerSettingsGuid: PGUID; // GUID* optional
PowerSettingGuid: PGUID; // GUID* optional
DcValueIndex: Pointer // DWORD* out
): DWORD; stdcall;
external 'POWRPROF.dll' name 'PowerReadDCValueIndex';result := DllCall("POWRPROF\PowerReadDCValueIndex"
, "Ptr", RootPowerKey ; HKEY optional
, "Ptr", SchemeGuid ; GUID* optional
, "Ptr", SubGroupOfPowerSettingsGuid ; GUID* optional
, "Ptr", PowerSettingGuid ; GUID* optional
, "Ptr", DcValueIndex ; DWORD* out
, "UInt") ; return: DWORD●PowerReadDCValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex) = DLL("POWRPROF.dll", "dword PowerReadDCValueIndex(void*, void*, void*, void*, void*)")
# 呼び出し: PowerReadDCValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex)
# RootPowerKey : HKEY optional -> "void*"
# SchemeGuid : GUID* optional -> "void*"
# SubGroupOfPowerSettingsGuid : GUID* optional -> "void*"
# PowerSettingGuid : GUID* optional -> "void*"
# DcValueIndex : DWORD* out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "powrprof" fn PowerReadDCValueIndex(
RootPowerKey: ?*anyopaque, // HKEY optional
SchemeGuid: [*c]GUID, // GUID* optional
SubGroupOfPowerSettingsGuid: [*c]GUID, // GUID* optional
PowerSettingGuid: [*c]GUID, // GUID* optional
DcValueIndex: [*c]u32 // DWORD* out
) callconv(std.os.windows.WINAPI) u32;proc PowerReadDCValueIndex(
RootPowerKey: pointer, # HKEY optional
SchemeGuid: ptr GUID, # GUID* optional
SubGroupOfPowerSettingsGuid: ptr GUID, # GUID* optional
PowerSettingGuid: ptr GUID, # GUID* optional
DcValueIndex: ptr uint32 # DWORD* out
): uint32 {.importc: "PowerReadDCValueIndex", stdcall, dynlib: "POWRPROF.dll".}pragma(lib, "powrprof");
extern(Windows)
uint PowerReadDCValueIndex(
void* RootPowerKey, // HKEY optional
GUID* SchemeGuid, // GUID* optional
GUID* SubGroupOfPowerSettingsGuid, // GUID* optional
GUID* PowerSettingGuid, // GUID* optional
uint* DcValueIndex // DWORD* out
);ccall((:PowerReadDCValueIndex, "POWRPROF.dll"), stdcall, UInt32,
(Ptr{Cvoid}, Ptr{GUID}, Ptr{GUID}, Ptr{GUID}, Ptr{UInt32}),
RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex)
# RootPowerKey : HKEY optional -> Ptr{Cvoid}
# SchemeGuid : GUID* optional -> Ptr{GUID}
# SubGroupOfPowerSettingsGuid : GUID* optional -> Ptr{GUID}
# PowerSettingGuid : GUID* optional -> Ptr{GUID}
# DcValueIndex : DWORD* out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t PowerReadDCValueIndex(
void* RootPowerKey,
void* SchemeGuid,
void* SubGroupOfPowerSettingsGuid,
void* PowerSettingGuid,
uint32_t* DcValueIndex);
]]
local powrprof = ffi.load("powrprof")
-- powrprof.PowerReadDCValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex)
-- RootPowerKey : HKEY optional
-- SchemeGuid : GUID* optional
-- SubGroupOfPowerSettingsGuid : GUID* optional
-- PowerSettingGuid : GUID* optional
-- DcValueIndex : DWORD* out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('POWRPROF.dll');
const PowerReadDCValueIndex = lib.func('__stdcall', 'PowerReadDCValueIndex', 'uint32_t', ['void *', 'void *', 'void *', 'void *', 'uint32_t *']);
// PowerReadDCValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex)
// RootPowerKey : HKEY optional -> 'void *'
// SchemeGuid : GUID* optional -> 'void *'
// SubGroupOfPowerSettingsGuid : GUID* optional -> 'void *'
// PowerSettingGuid : GUID* optional -> 'void *'
// DcValueIndex : DWORD* out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("POWRPROF.dll", {
PowerReadDCValueIndex: { parameters: ["pointer", "pointer", "pointer", "pointer", "pointer"], result: "u32" },
});
// lib.symbols.PowerReadDCValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex)
// RootPowerKey : HKEY optional -> "pointer"
// SchemeGuid : GUID* optional -> "pointer"
// SubGroupOfPowerSettingsGuid : GUID* optional -> "pointer"
// PowerSettingGuid : GUID* optional -> "pointer"
// DcValueIndex : DWORD* out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t PowerReadDCValueIndex(
void* RootPowerKey,
void* SchemeGuid,
void* SubGroupOfPowerSettingsGuid,
void* PowerSettingGuid,
uint32_t* DcValueIndex);
C, "POWRPROF.dll");
// $ffi->PowerReadDCValueIndex(RootPowerKey, SchemeGuid, SubGroupOfPowerSettingsGuid, PowerSettingGuid, DcValueIndex);
// RootPowerKey : HKEY optional
// SchemeGuid : GUID* optional
// SubGroupOfPowerSettingsGuid : GUID* optional
// PowerSettingGuid : GUID* optional
// DcValueIndex : 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 PowerReadDCValueIndex(
Pointer RootPowerKey, // HKEY optional
Pointer SchemeGuid, // GUID* optional
Pointer SubGroupOfPowerSettingsGuid, // GUID* optional
Pointer PowerSettingGuid, // GUID* optional
IntByReference DcValueIndex // DWORD* out
);
}@[Link("powrprof")]
lib LibPOWRPROF
fun PowerReadDCValueIndex = PowerReadDCValueIndex(
RootPowerKey : Void*, # HKEY optional
SchemeGuid : GUID*, # GUID* optional
SubGroupOfPowerSettingsGuid : GUID*, # GUID* optional
PowerSettingGuid : GUID*, # GUID* optional
DcValueIndex : 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 PowerReadDCValueIndexNative = Uint32 Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
typedef PowerReadDCValueIndexDart = int Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Uint32>);
final PowerReadDCValueIndex = DynamicLibrary.open('POWRPROF.dll')
.lookupFunction<PowerReadDCValueIndexNative, PowerReadDCValueIndexDart>('PowerReadDCValueIndex');
// RootPowerKey : HKEY optional -> Pointer<Void>
// SchemeGuid : GUID* optional -> Pointer<Void>
// SubGroupOfPowerSettingsGuid : GUID* optional -> Pointer<Void>
// PowerSettingGuid : GUID* optional -> Pointer<Void>
// DcValueIndex : DWORD* out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function PowerReadDCValueIndex(
RootPowerKey: THandle; // HKEY optional
SchemeGuid: PGUID; // GUID* optional
SubGroupOfPowerSettingsGuid: PGUID; // GUID* optional
PowerSettingGuid: PGUID; // GUID* optional
DcValueIndex: Pointer // DWORD* out
): DWORD; stdcall;
external 'POWRPROF.dll' name 'PowerReadDCValueIndex';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "PowerReadDCValueIndex"
c_PowerReadDCValueIndex :: Ptr () -> Ptr () -> Ptr () -> Ptr () -> Ptr Word32 -> IO Word32
-- RootPowerKey : HKEY optional -> Ptr ()
-- SchemeGuid : GUID* optional -> Ptr ()
-- SubGroupOfPowerSettingsGuid : GUID* optional -> Ptr ()
-- PowerSettingGuid : GUID* optional -> Ptr ()
-- DcValueIndex : DWORD* out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let powerreaddcvalueindex =
foreign "PowerReadDCValueIndex"
((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) *)
(* DcValueIndex : 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 ("PowerReadDCValueIndex" power-read-dcvalue-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
(dc-value-index :pointer)) ; DWORD* out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $PowerReadDCValueIndex = Win32::API::More->new('POWRPROF',
'DWORD PowerReadDCValueIndex(HANDLE RootPowerKey, LPVOID SchemeGuid, LPVOID SubGroupOfPowerSettingsGuid, LPVOID PowerSettingGuid, LPVOID DcValueIndex)');
# my $ret = $PowerReadDCValueIndex->Call($RootPowerKey, $SchemeGuid, $SubGroupOfPowerSettingsGuid, $PowerSettingGuid, $DcValueIndex);
# RootPowerKey : HKEY optional -> HANDLE
# SchemeGuid : GUID* optional -> LPVOID
# SubGroupOfPowerSettingsGuid : GUID* optional -> LPVOID
# PowerSettingGuid : GUID* optional -> LPVOID
# DcValueIndex : DWORD* out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。